24BEGIN_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};
277 IRECT h = GetHandleRect(cr);
278 g.
FillTriangle(mRectColor, h.L, h.B, h.R, h.B, h.R, h.T);
279 g.
DrawTriangle(COLOR_BLACK, h.L, h.B, h.R, h.B, h.R, h.T);
283 for (
int i = 0; i< mSelectedControls.GetSize(); i++)
285 g.
DrawDottedRect(COLOR_WHITE, mSelectedControls.Get(i)->GetRECT());
288 if (!mDragRegion.
Empty())
296 mSelectedControls.Empty();
305 return IRECT(r.R - RESIZE_HANDLE_SIZE, r.B - RESIZE_HANDLE_SIZE, r.R, r.B);
308 inline float SnapToGrid(
float input)
311 return (
float) std::round(input / (
float) mGridSize) * mGridSize;
317 IPopupMenu mRightClickOutsideControlMenu {
"Outside Control", {
"Add Place Holder"}};
318 IPopupMenu mRightClickOnControlMenu{
"On Control", {
"Delete Control"} };
320 bool mMouseOversEnabled =
false;
321 bool mMouseClickedOnResizeHandle =
false;
322 bool mMouseIsDragging =
false;
323 WDL_String mErrorMessage;
324 WDL_PtrList<IControl> mSelectedControls;
326 IColor mGridColor = COLOR_WHITE;
327 IColor mRectColor = COLOR_WHITE;
328 static const int RESIZE_HANDLE_SIZE = 10;
330 IRECT mMouseDownRECT;
331 IRECT mMouseDownTargetRECT;
334 float mGridSize = 10;
335 int mClickedOnControl = -1;
338END_IGRAPHICS_NAMESPACE
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
const IRECT & GetTargetRECT() const
Get the rectangular mouse tracking target area, within the graphics context for this control.
const IRECT & GetRECT() const
Get the rectangular draw area for this control, within the graphics context.
void SetTargetRECT(const IRECT &bounds)
Set the rectangular mouse tracking target area, within the graphics context for this control.
void SetRECT(const IRECT &bounds)
Set the rectangular draw area for this control, within the graphics context.
IContainerBase * GetParent() const
The lowest level base class of an IGraphics context.
void RemoveControl(int idx)
Remove a control at a particular index, (frees memory).
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.
virtual ECursor SetMouseCursor(ECursor cursorType=ECursor::ARROW)
Sets the mouse cursor to one of ECursor (implementations should return the result of the base impleme...
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.
void ReleaseMouseCapture()
Used to tell the graphics context to stop tracking mouse interaction with a control.
void GetMouseDownPoint(float &x, float &y) const
Get the x, y position of the last mouse down message.
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.
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 SetAllControlsDirty()
Calls SetDirty() on every control.
void SetControlSize(IControl *pControl, float w, float h)
Resize a control, redrawing the interface correctly.
IControl * GetControl(int idx)
Get the control at a certain index in the control stack.
void ForStandardControlsFunc(IControlFunction func)
For all standard controls in the main control stack perform a function.
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 SetControlPosition(IControl *pControl, float x, float y)
Reposition a control, redrawing the interface correctly.
void EnableMouseOver(bool enable)
IRECT GetBounds() const
Returns an IRECT that represents the entire UI bounds This is useful for programatically arranging UI...
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.
A control to enable live modification of control layout in an IGraphics context in debug builds This ...
void OnResize() override
Called when IControl is constructed or resized using SetRect().
bool OnKeyDown(float x, float y, const IKeyPress &key) override
Implement this method to respond to a key down event on this control.
void OnMouseOver(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouseover event on this control.
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.
void OnPopupMenuSelection(IPopupMenu *pSelectedMenu, int valIdx) override
Implement this method to handle popup menu selection after IGraphics::CreatePopupMenu/IControlPromptU...
void OnInit() override
Called just prior to when the control is attached, after its delegate and graphics member variable se...
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void OnMouseDblClick(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse double click event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
bool IsDirty() override
Called at each display refresh by the IGraphics draw loop, after IControl::Animate(),...
A control to use as a placeholder during development.
Used to manage composite/blend operations, independent of draw class/platform.
Used to manage color data, independent of draw class/platform.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
bool Contains(const IRECT &rhs) const
Returns true if this IRECT completely contains rhs.