iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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
20BEGIN_IPLUG_NAMESPACE
21BEGIN_IGRAPHICS_NAMESPACE
22
27{
28public:
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 }
78private:
79 float mSize;
80 bool mMouseOver = false;
81 ECursor mPrevCursorType = ECursor::ARROW;
82 IRECT mInitialGraphicsBounds;
83 IColor mColor, mMouseOverColor, mDragColor;
84};
85
86END_IGRAPHICS_NAMESPACE
87END_IPLUG_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.
Definition: IControl.h:49
bool GetMouseIsOver() const
This can be used in IControl::Draw() to check if the mouse is over the control, without implementing ...
Definition: IControl.h:474
IGraphics * GetUI()
Definition: IControl.h:467
virtual void OnMouseOut()
Implement this method to respond to a mouseout event on this control.
Definition: IControl.cpp:275
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:267
void SetTargetAndDrawRECTs(const IRECT &bounds)
Set BOTH the draw rect and the target area, within the graphics context for this control.
Definition: IControl.h:327
A control for resizing the plug-in window by clicking and dragging in the bottom right-hand corner Th...
void OnMouseOver(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouseover event on this control.
void OnMouseOut() override
Implement this method to respond to a mouseout 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.
void OnRescale() override
Implement to do something when graphics is scaled globally (e.g.
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
void Resize(int w, int h, float scale, bool needsPlatformResize=true)
Definition: IGraphics.cpp:90
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:828
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:2562
float GetDrawScale() const
Gets the graphics context scaling factor.
Definition: IGraphics.h:1101
IRECT GetBounds() const
Returns an IRECT that represents the entire UI bounds This is useful for programatically arranging UI...
Definition: IGraphics.h:1194
Used to manage color data, independent of draw class/platform.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
float W() const
float H() const
IRECT GetFromBRHC(float w, float h) const
Get a subrect of this IRECT expanding from the bottom-right corner.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.