iPlug2 - C++ Audio Plug-in Framework
TestBlendControl.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 
23 {
24 public:
25  TestBlendControl(const IRECT& bounds, const IBitmap& srcBitmap, const IBitmap& dstBitmap, int paramIdx)
26  : IKnobControlBase(bounds, paramIdx)
27  , mSrc(srcBitmap)
28  , mDst(dstBitmap)
29  {
30  SetTooltip("TestBlendControl");
31  mText.mSize = 12;
32  }
33 
34  void Draw(IGraphics& g) override
35  {
36  g.FillRect(COLOR_WHITE, mRECT);
37  const float alpha = (float) GetValue();
38 
39  int cell = 0;
40  auto nextCell = [&]() {
41  return mRECT.GetGridCell(cell++, 4, 4).GetPadded(-5.f);
42  };
43 
44  auto drawBlendPic = [this](IGraphics& g, IRECT r, EBlend blend, const char* name, float alpha)
45  {
46  IBlend blendMode { blend, alpha };
47  g.DrawFittedBitmap(mDst, r.GetPadded(-2.f));
48  g.DrawFittedBitmap(mSrc, r.GetPadded(-2.f), &blendMode);
49  g.DrawRect(COLOR_BLACK, r, nullptr, 1.f);
50  g.DrawText(mText, name, r.GetFromTop(10.f));
51  };
52 
53  g.StartLayer(this, mRECT);
54  nextCell();
55  nextCell();
56  drawBlendPic(g, nextCell(), EBlend::SrcOver, "Src Over", alpha);
57  drawBlendPic(g, nextCell(), EBlend::DstOver, "Dst Over", alpha);
58  drawBlendPic(g, nextCell(), EBlend::SrcIn, "Src In", alpha);
59  drawBlendPic(g, nextCell(), EBlend::DstIn, "Dst In", alpha);
60  drawBlendPic(g, nextCell(), EBlend::SrcOut, "Src Out", alpha);
61  drawBlendPic(g, nextCell(), EBlend::DstOut, "Dst Out", alpha);
62  drawBlendPic(g, nextCell(), EBlend::SrcAtop, "Src Atop", alpha);
63  drawBlendPic(g, nextCell(), EBlend::DstAtop, "Dst Atop", alpha);
64  drawBlendPic(g, nextCell(), EBlend::XOR, "XOR", alpha);
65  drawBlendPic(g, nextCell(), EBlend::Add, "Add", alpha);
66  mLayer = g.EndLayer();
67  g.DrawLayer(mLayer);
68  }
69 
70 private:
71  IBitmap mSrc;
72  IBitmap mDst;
73  ILayerPtr mLayer;
74 };
void StartLayer(IControl *pOwner, const IRECT &r, bool cacheable=false)
Create an IGraphics layer.
Definition: IGraphics.cpp:1954
Used to manage a rectangular area, independent of draw class/platform.
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Definition: IGraphics.cpp:2475
Used to manage composite/blend operations, independent of draw class/platform.
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
Control to test blend methods.
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
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
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1191
virtual void DrawFittedBitmap(const IBitmap &bitmap, const IRECT &bounds, const IBlend *pBlend=0)
Draw a bitmap (raster) image to the graphics context, scaling the image to fit the bounds...
Definition: IGraphics.cpp:2752
void DrawLayer(const ILayerPtr &layer, const IBlend *pBlend=nullptr)
Draw a layer to the main IGraphics context.
Definition: IGraphics.cpp:2022
IRECT GetGridCell(int row, int col, int nRows, int nColumns) const
Get a subrect (by row, column) of this IRECT which is a cell in a grid of size (nRows * nColumns) ...
double GetValue(int valIdx=0) const
Get the control's value.
Definition: IControl.cpp:151
ILayerPtr EndLayer()
End an IGraphics layer.
Definition: IGraphics.cpp:1977
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.