24 BEGIN_IGRAPHICS_NAMESPACE
36 , mMouseOversEnabled(mouseOversEnabled)
54 int c =
GetUI()->GetMouseControlIdx(x, y,
true);
59 mMouseDownRECT = pControl->
GetRECT();
63 mSelectedControls.Empty();
65 mSelectedControls.Add(pControl);
71 mMouseClickedOnResizeHandle =
false;
75 mClickedOnControl = c;
80 mClickedOnControl = c;
82 if(GetHandleRect(mMouseDownRECT).Contains(x, y))
84 mMouseClickedOnResizeHandle =
true;
94 mSelectedControls.Empty();
95 mDragRegion.
L = mDragRegion.
R = x;
96 mDragRegion.
T = mDragRegion.
B = y;
102 if(mMouseClickedOnResizeHandle)
109 if(w < 0.f || h < 0.f)
111 pControl->
SetRECT(mMouseDownRECT);
115 mClickedOnControl = -1;
116 mMouseClickedOnResizeHandle =
false;
119 mDragRegion =
IRECT();
128 int c =
GetUI()->GetMouseControlIdx(x, y,
true);
132 IRECT h = GetHandleRect(cr);
148 float mouseDownX, mouseDownY;
151 if(mClickedOnControl > 0)
155 if(mMouseClickedOnResizeHandle)
158 r.
R = SnapToGrid(mMouseDownRECT.
R + (x - mouseDownX));
159 r.
B = SnapToGrid(mMouseDownRECT.
B + (y - mouseDownY));
161 if(r.
R < mMouseDownRECT.
L +mGridSize) r.
R = mMouseDownRECT.
L+mGridSize;
162 if(r.
B < mMouseDownRECT.
T +mGridSize) r.
B = mMouseDownRECT.
T+mGridSize;
168 const float x1 = SnapToGrid(mMouseDownRECT.
L + (x - mouseDownX));
169 const float y1 = SnapToGrid(mMouseDownRECT.
T + (y - mouseDownY));
176 float mouseDownX, mouseDownY;
178 mDragRegion.
L = x < mouseDownX ? x : mouseDownX;
179 mDragRegion.
R = x < mouseDownX ? mouseDownX : x;
180 mDragRegion.
T = y < mouseDownY ? y : mouseDownY;
181 mDragRegion.
B = y < mouseDownY ? mouseDownY : y;
185 if(mSelectedControls.FindR(pControl) == -1)
186 mSelectedControls.Add(pControl);
189 int idx = mSelectedControls.FindR(pControl);
191 mSelectedControls.Delete(idx);
201 if(key.VK == kVK_BACK || key.VK == kVK_DELETE)
203 if(mSelectedControls.GetSize())
205 for(
int i = 0; i < mSelectedControls.GetSize(); i++)
207 IControl* pControl = mSelectedControls.Get(i);
211 mSelectedControls.Empty();
223 if(pSelectedMenu && pSelectedMenu == &mRightClickOutsideControlMenu)
225 auto idx = pSelectedMenu->GetChosenItemIdx();
240 if (pSelectedMenu && pSelectedMenu == &mRightClickOnControlMenu)
242 auto idx = pSelectedMenu->GetChosenItemIdx();
247 mSelectedControls.Empty();
249 mClickedOnControl = -1;
260 IBlend b {EBlend::Add, 0.25f};
275 IRECT h = GetHandleRect(cr);
280 for(
int i = 0; i< mSelectedControls.GetSize(); i++)
282 g.
DrawDottedRect(COLOR_WHITE, mSelectedControls.Get(i)->GetRECT());
285 if(!mDragRegion.
Empty())
293 mSelectedControls.Empty();
302 return IRECT(r.
R - RESIZE_HANDLE_SIZE, r.
B - RESIZE_HANDLE_SIZE, r.
R, r.
B);
305 inline float SnapToGrid(
float input)
308 return (
float) std::round(input / (
float) mGridSize) * mGridSize;
314 IPopupMenu mRightClickOutsideControlMenu {
"Outside Control", {
"Add Place Holder"}};
315 IPopupMenu mRightClickOnControlMenu{
"On Control", {
"Delete Control"} };
317 bool mMouseOversEnabled =
false;
318 bool mMouseClickedOnResizeHandle =
false;
319 bool mMouseIsDragging =
false;
320 WDL_String mErrorMessage;
321 WDL_PtrList<IControl> mSelectedControls;
323 IColor mGridColor = COLOR_WHITE;
324 IColor mRectColor = COLOR_WHITE;
325 static const int RESIZE_HANDLE_SIZE = 10;
327 IRECT mMouseDownRECT;
328 IRECT mMouseDownTargetRECT;
331 float mGridSize = 10;
332 int mClickedOnControl = -1;
335 END_IGRAPHICS_NAMESPACE
void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod &mod) override
Implement this method to respond to a mouse drag event on this control.
bool Contains(const IRECT &rhs) const
Returns true if this IRECT completely contains rhs.
The lowest level base class of an IGraphics control.
Used to manage a rectangular area, independent of draw class/platform.
virtual void DrawGrid(const IColor &color, const IRECT &bounds, float gridSizeH, float gridSizeV, const IBlend *pBlend=0, float thickness=1.f)
Draw a grid to the graphics context.
void SetControlSize(int idx, float w, float h)
Resize a control, redrawing the interface correctly.
Used to manage composite/blend operations, independent of draw class/platform.
virtual ECursor SetMouseCursor(ECursor cursorType=ECursor::ARROW)
Sets the mouse cursor to one of ECursor (implementations should return the result of the base impleme...
void ReleaseMouseCapture()
Used to tell the graphics context to stop tracking mouse interaction with a control.
const IRECT & GetTargetRECT() const
Get the rectangular mouse tracking target area, within the graphics context for this control...
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
Used to manage mouse modifiers i.e.
void OnMouseDblClick(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse double click event on this control.
A control to use as a placeholder during development.
IControl * GetControl(int idx)
void SetControlPosition(int idx, float x, float y)
Reposition a control, redrawing the interface correctly.
Used to manage color data, independent of draw class/platform.
void OnInit() override
Called just prior to when the control is attached, after its delegate and graphics member variable se...
This file contains the base IControl implementation, along with some base classes for specific types ...
void OnMouseOver(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouseover event on this control.
void SetAllControlsDirty()
Calls SetDirty() on every control.
float R
Right side of the rectangle (X + W)
void OnPopupMenuSelection(IPopupMenu *pSelectedMenu, int valIdx) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControl::Promp...
void RemoveControl(int idx)
Remove a control at a particular index, (frees memory).
void SetRECT(const IRECT &bounds)
Set the rectangular draw area for this control, within the graphics context.
const IRECT & GetRECT() const
Get the rectangular draw area for this control, within the graphics context.
void CreatePopupMenu(IControl &control, IPopupMenu &menu, const IRECT &bounds, int valIdx=0)
Shows a pop up/contextual menu in relation to a rectangular region of the graphics context...
void ForStandardControlsFunc(std::function< void(IControl *pControl)> func)
For all standard controls in the main control stack perform a function.
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
void GetMouseDownPoint(float &x, float &y) const
Get the x, y position of the last mouse down message.
The lowest level base class of an IGraphics context.
void OnResize() override
Called when IControl is constructed or resized using SetRect().
IRECT GetBounds() const
Returns an IRECT that represents the entire UI bounds This is useful for programatically arranging UI...
bool IsDirty() override
Called at each display refresh by the IGraphics draw loop, after IControl::Animate(), to determine if the control is marked as dirty.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
A control to enable live modification of control layout in an IGraphics context in debug builds This ...
virtual void DrawTriangle(const IColor &color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend *pBlend=0, float thickness=1.f)
Draw a triangle to the graphics context.
void SetTargetRECT(const IRECT &bounds)
Set the rectangular mouse tracking target area, within the graphics context for this control...
bool OnKeyDown(float x, float y, const IKeyPress &key) override
Implement this method to respond to a key down event on this control.
float L
Left side of the rectangle (X)
void EnableMouseOver(bool enable)
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
IControl * AttachControl(IControl *pControl, int ctrlTag=kNoTag, const char *group="")
Attach an IControl to the graphics context and add it to the top of the control stack.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
float T
Top of the rectangle (Y)
virtual void FillTriangle(const IColor &color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend *pBlend=0)
Fill a triangle with a color.
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
float B
Bottom of the rectangle (Y + H)