iPlug2 - C++ Audio Plug-in Framework
ITextEntryControl.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 
21 #define STB_TEXTEDIT_CHARTYPE char16_t
22 #define STB_TEXTEDIT_POSITIONTYPE int
23 #define STB_TEXTEDIT_STRING iplug::igraphics::ITextEntryControl
24 #define STB_TEXTEDIT_KEYTYPE uint32_t
25 
26 #include "stb_textedit.h"
27 
28 #include "IControl.h"
29 
30 BEGIN_IPLUG_NAMESPACE
31 BEGIN_IGRAPHICS_NAMESPACE
32 
39 {
40 public:
42 
43  //IControl
44  void Draw(IGraphics& g) override;
45  void OnMouseDown(float x, float y, const IMouseMod& mod) override;
46  bool OnKeyDown(float x, float y, const IKeyPress& key) override;
47  void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod& mod) override;
48  void OnMouseUp(float x, float y, const IMouseMod& mod) override;
49  void OnMouseDblClick(float x, float y, const IMouseMod& mod) override;
50  void OnEndAnimation() override;
51 
52  static int DeleteChars(ITextEntryControl* _this, size_t pos, size_t num);
53  static int InsertChars(ITextEntryControl* _this, size_t pos, const char16_t* text, size_t num);
54  static void Layout(StbTexteditRow* row, ITextEntryControl* _this, int start_i);
55  static float GetCharWidth(ITextEntryControl* _this, int n, int i);
56  static char16_t GetChar(ITextEntryControl* _this, int pos);
57  static int GetLength(ITextEntryControl* _this);
58 
59  bool EditInProgress() { return mEditing; }
60  void DismissEdit();
61  void CommitEdit();
62 
63  void CreateTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str);
64 
65 private:
66 
67  void SetStr(const char* str);
68 
69  template<typename Proc>
70  bool CallSTB(Proc proc);
71  void OnStateChanged();
72  void OnTextChange();
73  void FillCharWidthCache();
74  void CalcCursorSizes();
75  float MeasureCharWidth(char16_t c, char16_t nc);
76  void CopySelection();
77  void Paste();
78  void Cut();
79  void SelectAll();
80 
81  bool mDrawCursor = false;
82  bool mEditing = false;
83  bool mRecursiveKeyGuard = false;
84  bool mCursorIsSet = false;
85  bool mCursorSizesValid = false;
86  bool mNotifyTextChange = false;
87 
88  STB_TexteditState mEditState;
89  WDL_TypedBuf<float> mCharWidths;
90  std::u16string mEditString;
91 };
92 
93 END_IGRAPHICS_NAMESPACE
94 END_IPLUG_NAMESPACE
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
A Text entry widget drawn by IGraphics.
Used to manage a rectangular area, independent of draw class/platform.
Used to manage mouse modifiers i.e.
void OnMouseDrag(float x, float y, float dX, float dY, const IMouseMod &mod) override
Implement this method to respond to a mouse drag event on this control.
bool OnKeyDown(float x, float y, const IKeyPress &key) override
Implement this method to respond to a key down 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.
This file contains the base IControl implementation, along with some base classes for specific types ...
void Draw(IGraphics &g) override
Draw the control to the graphics context.
IText is used to manage font and text/text entry style for a piece of text on the UI...
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
void OnMouseDblClick(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse double click event on this control.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
Definition: IPlugStructs.h:612