iPlug2 - C++ Audio Plug-in Framework
ICornerResizerControl.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5 
6  See LICENSE.txt for more info.
7 
8  ==============================================================================
9  */
10 
11 #pragma once
12 
18 #include "IControl.h"
19 
20 BEGIN_IPLUG_NAMESPACE
21 BEGIN_IGRAPHICS_NAMESPACE
22 
27 {
28 public:
29  ICornerResizerControl(const IRECT& graphicsBounds, float size, const IColor& color = COLOR_TRANSLUCENT, const IColor& mouseOverColour = COLOR_BLACK, const IColor& dragColor = COLOR_BLACK)
30  : IControl(graphicsBounds.GetFromBRHC(size, size).GetPadded(-1))
31  , mSize(size)
32  , mInitialGraphicsBounds(graphicsBounds)
33  , mColor(color)
34  , mMouseOverColor(mouseOverColour)
35  , mDragColor(dragColor)
36  {
37  }
38 
39  void Draw(IGraphics& g) override
40  {
41  const IColor &color = GetUI()->mResizingInProcess ? mDragColor : GetMouseIsOver()? mMouseOverColor : mColor;
42 
43  g.FillTriangle(color, mRECT.L, mRECT.B, mRECT.R, mRECT.T, mRECT.R, mRECT.B);
44  }
45 
46  void OnMouseDown(float x, float y, const IMouseMod& mod) override
47  {
48  GetUI()->StartDragResize();
49  }
50 
51  void OnMouseDblClick(float x, float y, const IMouseMod& mod) override
52  {
53  GetUI()->Resize(static_cast<int>(mInitialGraphicsBounds.W()), static_cast<int>(mInitialGraphicsBounds.H()), 1.f);
54  }
55 
56  void OnRescale() override
57  {
58  float size = mSize * (1.f/GetUI()->GetDrawScale());
59  IRECT r = GetUI()->GetBounds().GetFromBRHC(size, size);
61  }
62 
63  void OnMouseOver(float x, float y, const IMouseMod& mod) override
64  {
65  if (!mMouseOver)
66  mPrevCursorType = GetUI()->SetMouseCursor(ECursor::SIZENWSE);
67  mMouseOver = true;
68  IControl::OnMouseOver(x, y, mod);
69  }
70 
71  void OnMouseOut() override
72  {
73  if (mMouseOver)
74  GetUI()->SetMouseCursor(mPrevCursorType);
75  mMouseOver = false;
77  }
78 private:
79  float mSize;
80  bool mMouseOver = false;
81  ECursor mPrevCursorType = ECursor::ARROW;
82  IRECT mInitialGraphicsBounds;
83  IColor mColor, mMouseOverColor, mDragColor;
84 };
85 
86 END_IGRAPHICS_NAMESPACE
87 END_IPLUG_NAMESPACE
void OnRescale() override
Implement to do something when graphics is scaled globally (e.g.
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, 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...
Definition: IGraphics.h:805
Used to manage mouse modifiers i.e.
void OnMouseOver(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouseover event on this control.
Used to manage color data, independent of draw class/platform.
This file contains the base IControl implementation, along with some base classes for specific types ...
float R
Right side of the rectangle (X + W)
float H() const
void OnMouseOut() override
Implement this method to respond to a mouseout event on this control.
float W() const
float GetDrawScale() const
Gets the graphics context scaling factor.
Definition: IGraphics.h:1064
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Definition: IControl.cpp:81
bool GetMouseIsOver() const
This can be used in IControl::Draw() to check if the mouse is over the control, without implementing ...
Definition: IControl.h:459
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void OnMouseOver(float x, float y, const IMouseMod &mod)
Implement this method to respond to a mouseover event on this control.
Definition: IControl.cpp:265
IRECT GetBounds() const
Returns an IRECT that represents the entire UI bounds This is useful for programatically arranging UI...
Definition: IGraphics.h:1154
A control for resizing the plug-in window by clicking and dragging in the bottom right-hand corner Th...
void Resize(int w, int h, float scale, bool needsPlatformResize=true)
Definition: IGraphics.cpp:91
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void SetTargetAndDrawRECTs(const IRECT &bounds)
Set BOTH the draw rect and the target area, within the graphics context for this control.
Definition: IControl.h:321
IGraphics * GetUI()
Definition: IControl.h:452
float L
Left side of the rectangle (X)
void OnMouseDblClick(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse double click event on this control.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
IRECT GetFromBRHC(float w, float h) const
Get a subrect of this IRECT expanding from the bottom-right corner.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
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.
Definition: IGraphics.cpp:2540
float B
Bottom of the rectangle (Y + H)
virtual void OnMouseOut()
Implement this method to respond to a mouseout event on this control.
Definition: IControl.cpp:273