iPlug2 - C++ Audio Plug-in Framework
TestGFXLabel.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 
22 class GFXLabelControl : public IControl
23 {
24 public:
25  GFXLabelControl(const IRECT& rect)
26  : IControl(rect)
27  {
28  mIgnoreMouse = true;
29  }
30 
31  void Draw(IGraphics& g) override
32  {
33  if (!g.CheckLayer(mLayer))
34  {
35  g.StartLayer(this, mRECT);
36 //#ifdef IGRAPHICS_NANOVG
37 // static IText text {14, COLOR_WHITE, "Roboto-Regular", EAlign::Center, EVAlign::Middle, 0};
38 //#else
39  static IText text {34, COLOR_WHITE, "Roboto-Regular", EAlign::Center, EVAlign::Top, 0};
40 //#endif
41  IRECT r = mRECT;
42  g.MeasureText(text, g.GetDrawingAPIStr(), r);
43  r.Pad(20, 0, 20, 0);
44 
45  g.FillRect(COLOR_BLACK, r);
46 
47  g.DrawText(text, g.GetDrawingAPIStr(), mRECT);
48  mLayer = g.EndLayer();
49  IShadow shadow(COLOR_BLACK_DROP_SHADOW, 10.0, 3.0, 6.0, 0.7f, true);
50  g.ApplyLayerDropShadow(mLayer, shadow);
51  }
52 
53  g.DrawLayer(mLayer);
54 // g.DrawRotatedLayer(mLayer, 45);
55  }
56 
57 private:
58  ILayerPtr mLayer;
59 };
void StartLayer(IControl *pOwner, const IRECT &r, bool cacheable=false)
Create an IGraphics layer.
Definition: IGraphics.cpp:1954
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
void ApplyLayerDropShadow(ILayerPtr &layer, const IShadow &shadow)
Applies a drop shadow directly onto a layer.
Definition: IGraphics.cpp:2052
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
Definition: IGraphics.cpp:631
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Definition: TestGFXLabel.h:31
This file contains the base IControl implementation, along with some base classes for specific types ...
IText is used to manage font and text/text entry style for a piece of text on the UI...
bool CheckLayer(const ILayerPtr &layer)
Test to see if a layer needs drawing, for instance if the control's bounds were changed.
Definition: IGraphics.cpp:2009
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Definition: IControl.cpp:81
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
Used to specify properties of a drop-shadow to a layer.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2547
void DrawLayer(const ILayerPtr &layer, const IBlend *pBlend=nullptr)
Draw a layer to the main IGraphics context.
Definition: IGraphics.cpp:2022
void Pad(float padding)
Pad this IRECT N.B.
ILayerPtr EndLayer()
End an IGraphics layer.
Definition: IGraphics.cpp:1977
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
Control to display the graphics backend.
Definition: TestGFXLabel.h:22
virtual float MeasureText(const IText &text, const char *str, IRECT &bounds) const
Measure the rectangular region that some text will occupy.
Definition: IGraphics.cpp:639
virtual const char * GetDrawingAPIStr()=0