iPlug2 - C++ Audio Plug-in Framework
TestImageControl.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 TestImageControl : public IControl
23 {
24 public:
25  TestImageControl(const IRECT& bounds, const IBitmap& bmp)
26  : IControl(bounds)
27  , mBitmap(bmp)
28  {
29  SetTooltip("TestImageControl - Click or Drag 'n drop here to load a new bitmap");
30  }
31 
32  void Draw(IGraphics& g) override
33  {
34  g.DrawDottedRect(COLOR_BLACK, mRECT);
35  g.FillRect(mMouseIsOver ? COLOR_TRANSLUCENT : COLOR_TRANSPARENT, mRECT);
36 
37  if(mBitmap.IsValid())
38  g.DrawFittedBitmap(mBitmap, mRECT);
39  else
40  g.DrawText(DEFAULT_TEXT, "Invalid Bitmap", mRECT);
41  }
42 
43  void OnMouseDown(float x, float y, const IMouseMod& mod) override
44  {
45  WDL_String file;
46  WDL_String path;
47 
48  GetUI()->PromptForFile(file, path, EFileAction::Open, "");
49 
50  if(file.GetLength())
51  SetBitmap(file.Get());
52  }
53 
54  void OnDrop(const char* str) override
55  {
56  SetBitmap(str);
57  }
58 
59  void SetBitmap(const char* str)
60  {
61  mBitmap = GetUI()->LoadBitmap(str);
62  SetDirty(false);
63  }
64 
65 private:
66  IBitmap mBitmap;
67 };
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
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.
Definition: IGraphics.cpp:2517
Used to manage mouse modifiers i.e.
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:545
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 ...
virtual IBitmap LoadBitmap(const char *fileNameOrResID, int nStates=1, bool framesAreHorizontal=false, int targetScale=0)
Load a bitmap image from disk or from windows resource.
Definition: IGraphics.cpp:1694
virtual void PromptForFile(WDL_String &fileName, WDL_String &path, EFileAction action=EFileAction::Open, const char *extensions=0)=0
Create a platform file prompt dialog to choose a file/directory path for opening/saving a file/direct...
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
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
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
bool IsValid() const
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
IGraphics * GetUI()
Definition: IControl.h:452
Control to test drawing bitmaps.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnDrop(const char *str) override
Implement to do something when something was drag 'n dropped onto this control.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196