iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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
23{
24public:
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 fileName, path;
46
47 GetUI()->PromptForFile(fileName, path, EFileAction::Open, "bmp jpg png",
48 [this](const WDL_String& fileName, const WDL_String& path) {
49 if (fileName.GetLength())
50 SetBitmap(fileName.Get());
51 });
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
65private:
66 IBitmap mBitmap;
67};
This file contains the base IControl implementation, along with some base classes for specific types ...
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
bool IsValid() const
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
IGraphics * GetUI()
Definition: IControl.h:467
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:560
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2774
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:670
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:2539
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:2569
virtual void PromptForFile(WDL_String &fileName, WDL_String &path, EFileAction action=EFileAction::Open, const char *ext="", IFileDialogCompletionHandlerFunc completionHandler=nullptr)=0
Create a platform file prompt dialog to choose a path for opening/saving a single file.
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:1721
Control to test drawing bitmaps.
void OnDrop(const char *str) override
Implement to do something when something was drag 'n dropped onto this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.