Home2L - C/C++ API v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
ui_widgets.H
Go to the documentation of this file.
1/*
2 * This file is part of the Home2L project.
3 *
4 * (C) 2015-2024 Gundolf Kiefer
5 *
6 * Home2L is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Home2L is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Home2L. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21
22#ifndef _UI_WIDGETS_
23#define _UI_WIDGETS_
24
25
51#include "ui_screen.H"
52
53
54
55
56
57// *****************************************************************************
58// * *
59// * Useful widget extensions *
60// * *
61// *****************************************************************************
62
63
67
68
69
70
71
72// *************************** CModalWidget ************************************
73
74
77class CModalWidget: public virtual CWidget {
78 public:
79
82 int Run (CScreen *_screen);
83
84 virtual void Start (CScreen *_screen);
85 bool IsRunning ();
86 virtual void Stop ();
88
91 int GetStatus () { return status; }
92 void SetStatus (int _status) { status = _status; }
94
97 void SetNoCancelArea (SDL_Rect _rNoCancel) { rNoCancel = _rNoCancel; }
103 void RemoveNoCancelArea () { SetNoCancelArea (RectScreen ()); }
105
108 virtual bool HandleEvent (SDL_Event *ev);
110
111 protected:
112 SDL_Rect rNoCancel;
113 int status;
114};
115
116
117
118
119
120// *************************** CCursorWidget ***********************************
121
122
125class CCursorWidget: public virtual CWidget {
126 public:
127 CCursorWidget () { ClearCursor (); cbHandleEvent = NULL; }
128
129 void SetCursorFormat (TColor _cursorColor = ToColor (0xff, 0xff, 0xff, 0x20), SDL_BlendMode _blendMode = SDL_BLENDMODE_BLEND) { cursorColor = _cursorColor; blendMode = _blendMode; }
130
131 void SetCursor (SDL_Rect _cursorArea) { cursorArea = _cursorArea; }
132 void ClearCursor () { cursorArea.w = cursorArea.h = 0; }
133
134 void SetCbHandleEvent (bool (*_cbHandleEvent) (SDL_Event *, void *), void *_data = NULL) { cbHandleEvent = _cbHandleEvent; cbHandleEventData = _data; }
135
136 virtual void Render (SDL_Renderer *ren);
137 virtual bool HandleEvent (SDL_Event *ev);
138
139 protected:
140 SDL_Rect cursorArea;
141 TColor cursorColor;
142 SDL_BlendMode blendMode;
143 bool (*cbHandleEvent) (SDL_Event *, void *);
144 void *cbHandleEventData;
145};
146
147
148
150
151
152
153
154
155// *****************************************************************************
156// * *
157// * The widgets *
158// * *
159// *****************************************************************************
160
161
162
163
164
165// *************************** CButton *****************************************
166
167
171
172
173#define BUTTON_DEFAULT_FONT FontGet (fntNormal, 24)
174#define BUTTON_LABEL_BORDER 8
175
176
177typedef void FCbButtonPushed (class CButton *button, bool longPush, void *data);
179
180
181#define BUTTON_TRAMPOLINE(CB_NAME, CLASS_NAME, METHOD_NAME) \
182 void CB_NAME (class CButton *button, bool longPush, void *data) { \
183 ((CLASS_NAME *) data)->METHOD_NAME (button, longPush); \
184 }
199
200
201void CbActivateScreen (class CButton *, bool, void *screen);
204
210class CButton: public CWidget {
211 public:
212 CButton () { Init (); }
213 virtual ~CButton () { Done (); }
214 void Init ();
215 void Done ();
216
219 void Set (SDL_Rect _area, TColor _color = GREY);
220 void Set (SDL_Rect _area, TColor _color, SDL_Surface *_icon);
221 void Set (SDL_Rect _area, TColor _color, const char *text, TColor textColor = WHITE, TTF_Font *font = NULL);
222 void Set (SDL_Rect _area, TColor _color, SDL_Surface *_icon, const char *text, TColor textColor = WHITE, TTF_Font *font = NULL);
224
227
228 void SetArea (SDL_Rect _area);
229
230 void SetColor (TColor _colNorm) { SetColor (_colNorm, _colNorm); }
231 void SetColor (TColor _colNorm, TColor _colDown);
232
233 void SetLabel (SDL_Surface *_icon, SDL_Rect *srcRect = NULL, bool takeOwnership = false);
246 void SetLabel (const char *text, TColor textColor = WHITE, TTF_Font *font = NULL);
248 void SetLabel (SDL_Surface *_icon, const char *text, TColor textColor = WHITE, TTF_Font *font = NULL);
250 void SetLabel (TColor color, const char *iconName, const char *text = NULL, TTF_Font *font = NULL)
251 { SetLabel (iconName ? IconGet (iconName, color) : NULL, text, color, font); }
253 void ClearLabel () { SetLabel ((SDL_Surface *) NULL); }
255 void SetLabelAlignment (int _hAlign = 0, int _vAlign = 0) { hAlign = _hAlign; vAlign = _vAlign; ChangedSurface (); }
258 void SetHotkey (SDL_Keycode _hotkey) { hotkey = _hotkey; }
260
265 virtual void OnPushed (bool longPush);
266 void SetCbPushed (FCbButtonPushed *cb, void *_data = NULL) { cbPushed = cb; cbPushedData = _data; }
267 void *GetCbPushedData () { return cbPushedData; }
269
272 virtual SDL_Surface *GetSurface ();
273 virtual bool HandleEvent (SDL_Event *ev);
275
276 protected:
277 SDL_Surface *surfLabel;
278 bool surfLabelIsOwned;
279 TColor colNorm, colDown;
280 int hAlign, vAlign;
281 bool isDown, changed;
282
283 FCbButtonPushed *cbPushed;
284 void *cbPushedData;
285
286 SDL_Keycode hotkey;
287
290 void ChangedSurface () { changed = true; CWidget::ChangedSurface (); }
292};
293
294
295
296#define FLATBUTTON_COL_UP BLACK
297#define FLATBUTTON_COL_DOWN ToColor (0x60, 0x00, 0x00)
298//~ #define FLATBUTTON_COL_DOWN LIGHT_BROWN // DARK_YELLOW
299
300
306class CFlatButton: public CButton {
307 public:
308 CFlatButton () { SetColor (FLATBUTTON_COL_UP, FLATBUTTON_COL_DOWN); }
309
310 virtual SDL_Surface *GetSurface ();
311};
312
313
315
316
317// ***** Creating main button bars *****
318
319
321typedef struct {
322 int layoutWidth;
323 TColor color;
324 const char *iconName;
325 const char *text;
326 FCbButtonPushed *cbPushed;
327 SDL_Keycode hotkey;
331CButton *CreateMainButtonBar (int buttons, TButtonDescriptor *descTable, CScreen *screen);
336
338
339
340
341
342
343// *************************** CListbox ****************************************
344
345
349
350
351#define LISTBOX_ITEM_BORDER 4
352
353
356 lmReadOnly,
357 lmActivate,
363typedef void FCbListboxPushed (class CListbox *, int idx, bool longPush, void *data);
365
366
367#define LISTBOX_TRAMPOLINE(CB_NAME, CLASS_NAME, METHOD_NAME) \
368 void CB_NAME (class CListbox *listbox, int idx, bool longPush, void *data) { \
369 ((CLASS_NAME *) data)->METHOD_NAME (listbox, idx, longPush); \
370 }
385
386
389class CListboxItem {
390 public:
391 CListboxItem () { text = NULL; iconName = NULL; iconSurf = NULL; isSelected = isSpecial = false; data = NULL; changed = true; }
393 bool IsSelected () { return isSelected; }
394
395 void SetLabel (const char *_text, const char *_iconName = NULL) { text = _text; iconName = _iconName; iconSurf = NULL; }
398 void SetLabel (const char *_text, SDL_Surface *_iconSurf) { text = _text; iconName = NULL; iconSurf = _iconSurf; }
401
402 bool isSpecial;
403 void *data;
404
405 protected:
406 friend class CListbox;
407
408 const char *text;
409 const char *iconName;
410 SDL_Surface *iconSurf;
412 bool isSelected;
413 bool changed;
414};
415
416
419class CListbox: public CCanvas {
420 public:
422 ~CListbox ();
423
426 void SetMode (EListboxMode _mode, int _itemHeight, int _itemGap = 1);
429 void SetFormat (TTF_Font *_font, int _hAlign = -1, TColor colGrid = BLACK,
430 TColor _colLabel = WHITE, TColor _colBack = DARK_DARK_GREY,
431 TColor _colLabelSelected = WHITE, TColor _colBackSelected = GREY,
432 TColor _colLabelSpecial = WHITE, TColor _colBackSpecial = DARK_GREY);
435 void SetArea (SDL_Rect _area) { CCanvas::SetArea (_area); ChangedSetup (); }
440 void Clear () { SetItems (0); }
441 void SetItems (int _items);
442 int GetItems () { return items; }
443
444 void SetItem (int idx, const char *_text, const char *_iconName = NULL, bool _isSpecial = false, void *data = NULL);
445 void SetItem (int idx, const char *_text, SDL_Surface *_iconSurf, bool _isSpecial = false, void *data = NULL);
446 CListboxItem *GetItem (int idx) { return &itemArr[idx]; }
447
448 int GetItemHeight () { return itemHeight; }
449 int GetItemLabelWidth (int idx);
451 SDL_Rect GetItemRect (int idx);
453
454 void ScrollTo (int idx, int vAlign = -1) { CCanvas::ScrollTo (GetItemRect (idx), 0, vAlign); Changed (); }
455 void ScrollIn (int idx) { CCanvas::ScrollIn (GetItemRect (idx)); Changed (); }
460 void SelectItem (int idx, bool _isSelected = true);
461 void SelectAll (bool _isSelected = true);
462 void SelectNone () { SelectAll (false); }
463
464 bool MouseDown () { return downIdx >= 0; }
471 bool ItemIsSelected (int idx) { return itemArr[idx].isSelected; }
472 int GetSelectedItem () { return selectedItem; } // 'lmSelectSingle' only
473
474 virtual void OnPushed (int idx, bool longPush) { if (cbPushed) cbPushed (this, idx, longPush, cbPushedData); }
475 void SetCbPushed (FCbListboxPushed *_cbPushed, void *_data = NULL) { cbPushed = _cbPushed; cbPushedData = _data; }
477
480 void ChangedItems (int idx, int num = 1);
482
485 virtual void Render (SDL_Renderer *ren);
486 virtual bool HandleEvent (SDL_Event *ev);
489 protected:
490 CListboxItem *itemArr;
491 int items;
492 CWidget **pool;
493 int poolSize, *poolIdx;
494 int selectedItem, downIdx, downSelectedItem;
495 bool noLongPush;
496 bool changed;
497
498 // Configuration options...
499 EListboxMode mode;
500 int itemGap, itemHeight;
501 FCbListboxPushed *cbPushed;
502 void *cbPushedData;
503
504 // Infos for 'RenderItem' only...
505 TTF_Font *font;
506 int hAlign;
507 TColor colLabel, colBack, colLabelSelected, colBackSelected, colLabelSpecial, colBackSpecial;
508
511 virtual SDL_Surface *RenderItem (CListboxItem *item, int idx, SDL_Surface *surf);
522
525 void ChangedSetup () { InvalidatePool (); Changed (); }
526 void Changed () { changed = true; CCanvas::Changed (); }
528
529 private:
530
531 // Helpers...
532 void InvalidatePool (); // called if something general changed (e.g. colors, area)
533 void UpdatePool (); // update pool before rendering
534};
535
536
538
539
540
541
542
543// *************************** CMenu *******************************************
544
545
549
550
551#define MENU_DEFAULT_FONT FontGet (fntNormal, 20)
552#define MENU_DEFAULT_COLOR DARK_GREY
553
554
557class CMenu: public CListbox, public CModalWidget {
558 public:
559 CMenu () { texFrame = NULL; }
560 ~CMenu () { TextureFree (&texFrame); }
561
564 void Setup (SDL_Rect _rContainer, int _hAlign = -1, int _vAlign = -1, // The exact geometry is determined in 'Start'
565 TColor color = MENU_DEFAULT_COLOR, TTF_Font *_font = NULL);
567
570 void SetItems (const char *_itemStr);
571 void SetItems (int _items) { CListbox::SetItems (_items); }
572 void SetItem (int idx, const char *_text, SDL_Surface *_surfIcon = NULL, bool _isSpecial = false, void *data = NULL) { CListbox::SetItem (idx, _text, _surfIcon, _isSpecial, data); }
574
577 int Run (CScreen *_screen, const char *_itemStr) { SetItems (_itemStr); return Run (_screen); }
578 int Run (CScreen *_screen) { return CModalWidget::Run (_screen); }
579 virtual void Start (CScreen *_screen);
581
587 bool GetStatusLongPush () { return hadLongPush; }
590
593 SDL_Rect *GetArea () { return &rFrame; } // Note: Is different from 'CWidget::area', which here only contains the canvas part of the menu
598 virtual void Render (SDL_Renderer *ren);
599 virtual bool HandleEvent (SDL_Event *ev);
600 virtual void OnPushed (int idx, bool longPush);
602
603 protected:
604 SDL_Rect rContainer, rFrame;
605 int hAlign, vAlign;
606 CString itemStr;
607 SDL_Texture *texFrame;
608 bool hadLongPush;
609};
610
611
612// Easy-to-use function(s)...
613int RunMenu (const char *_itemStr, SDL_Rect _rContainer, int _hAlign = -1, int _vAlign = -1,
614 TColor color = MENU_DEFAULT_COLOR, TTF_Font *_font = NULL,
615 bool *retLongPush = NULL);
624
625
627
628
629
630
631
632// *************************** Message Box *************************************
633
634
638
639
640#define MSGBOX_DEFAULT_FONT FontGet (fntNormal, 24)
641#define MSGBOX_TITLE_FONT FontGet (fntBold, 32)
642
643#define MSGBOX_COLOR DARK_GREY
644
645#define MSGBOX_SPACE_X 32
646#define MSGBOX_SPACE_Y 32
647#define MSGBOX_BUTTON_MINWIDTH 160
650
652enum EMessageButtonId {
653 mbiCancel = 0,
654 mbiOk,
655 mbiNo,
656 mbiYes,
657 mbiEND
658};
659
661#define mbmCancel ((int) (1 << mbiCancel))
662#define mbmOk ((int) (1 << mbiOk))
663#define mbmNo ((int) (1 << mbiNo))
664#define mbmYes ((int) (1 << mbiYes))
665
666#define mbmOkCancel (mbmOk | mbmCancel)
667#define mbmYesNoCancel (mbmYes | mbmNo | mbmCancel)
668#define mbmNone ((int) 0)
676 public:
677 CMessageBox () { buttons = 0; buttonArr = NULL; screenHasKeyboard = false; }
678 ~CMessageBox () { Stop (); SurfaceFree (&surface); }
679
682 void Setup (const char *title, int contentW, int contentH, int _buttons, CButton **_buttonArr, TColor color = MSGBOX_COLOR, int titleHAlign = 0);
689 // TBD: FIX this: replace int "int contentW, int contentH" by "SDL_Surface *content"!!!
692
693 void Setup (const char *title, int contentW, int contentH, int buttonMask, TColor color = MSGBOX_COLOR);
696 // TBD: FIX this: replace int "int contentW, int contentH" by "SDL_Surface *content"!!!
697
698 void Setup (const char *title, const char *text, SDL_Surface *icon = NULL, int buttonMask = mbmOk, int hAlign = 0, TTF_Font *font = NULL);
704 SDL_Rect *ContentArea () { return &rContent; }
709 int GetChoice () { return GetStatus (); }
713
716 virtual void Start (CScreen *_screen);
717 virtual void Stop ();
718 virtual void OnButtonPushed (CButton *button, bool);
720
721 protected:
722 CButton stdButtons[mbiEND], **buttonArr, *stdButtonArr[mbiEND];
723 SDL_Rect rContent;
724 int buttons;
725 bool screenHasKeyboard;
726};
727
728
731int RunMessageBox (const char *title, const char *text, int buttonMask = mbmOk, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
733
734int RunInfoBox (const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
735int RunInfoBox (const char *title, const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
737int RunWarnBox (const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
738int RunWarnBox (const char *title, const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
740int RunErrorBox (const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
741int RunErrorBox (const char *title, const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
744int RunSureBox (const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
745int RunSureBox (const char *title, const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
747int RunQueryBox (const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
748int RunQueryBox (const char *title, const char *text, SDL_Surface *icon = NULL, int hAlign = 0, TTF_Font *font = NULL);
751
752
756CMessageBox *StartMessageBox (const char *title, const char *text, SDL_Surface *icon = NULL, int buttonMask = mbmOk, int hAlign = 0, TTF_Font *font = NULL);
757static inline void IterateMessageBox () { UiIterate (); }
758static inline int GetMessageBoxStatus (CMessageBox *msgBox) { return msgBox->GetStatus (); }
759void StopMessageBox (CMessageBox *msgBox);
761
762
764
765
766
767
768
769// *************************** CInputLine **************************************
770
771
775
776
777#define INPUTLINE_FONTSIZE 24
778#define INPUTLINE_UNDOS 32
779#define INPUTLINE_MAXLEN 512
780 // The maximum length must be selected such that the rendered string does not exceed the
781 // maximum texture width of currently 16384 pixels [2022-11-04].
782
785class CInputLine: public CCanvas {
786 public:
787 CInputLine () { font = NULL; inputLen = 0; mark0 = markD = 0; suggPos = -1; cbSuggCheck = NULL; suggData = NULL; undoFirst = redoFirst = NULL; surfMain = NULL; changedContent = changedMark = false; }
788 ~CInputLine () { SurfaceFree (&surfMain); ClearHistory (); }
789
792 void Setup (int fontSize = INPUTLINE_FONTSIZE);
793 void SetInput (const char *_inputStr = NULL, int _mark0 = 0, int _markD = 0);
795 void ClearHistory ();
797
800 void GetInput (CString *ret) { ret->SetFromIso8859 (input.Get ()); }
802 bool InputModified ();
804
807 int GetMark0 () { return mark0; }
808 int GetMarkD () { return markD; }
809 void SetMark (int _mark0, int _markD = 0);
810 void MoveMark (int _mark0);
811
812 void InsChar (char c);
813 void InsText (const char *txt, int chars = -1);
814 void DelMarked ();
815 void DelChar (int pos);
816
817 CString *GetInput () { return &input; }
819 void ChangedInput ();
821
824 void ClipboardCopy ();
825 void ClipboardCut () { ClipboardCopy (); DelMarked (); }
826 void ClipboardPaste ();
828
831 void Undo ();
832 void Redo ();
834
837 void SetSuggestion (int _suggPos, const char *_suggText, int _suggMark0 = -1, int _suggMarkD = 0); // '_suggText' must be in ISO 8859
838 void ClearSuggestion () { SetSuggestion (-1, NULL); }
839 void ApplySuggestion ();
840 virtual void CheckSuggestion () { if (cbSuggCheck) cbSuggCheck (this, suggData); } // called when
841 void SetCbCheckSuggestion (void (*_cbSuggCheck) (CInputLine *, void *), void *_suggData) { cbSuggCheck = _cbSuggCheck; suggData = _suggData; }
843
846 virtual void Render (SDL_Renderer *ren);
847 virtual bool HandleEvent (SDL_Event *ev);
849
850 protected:
851 TTF_Font *font;
852 int charWidth;
853 CString input; // ISO 8859
854 int inputLen;
855 int mark0, markD; // 'markD' may also be negative; 'mark0' is always the cursor position
856 class CUndoState *undoFirst, *redoFirst;
857
858 int suggPos, suggMark0, suggMarkD; // 'suggPos < 0' => no suggestion
859 CString suggText; // ISO 8859
860 void (*cbSuggCheck) (CInputLine *, void *);
861 void *suggData;
862
863 CCursorWidget wdgMain;
864 SDL_Surface *surfMain;
865
866 bool changedContent, changedMark;
867
868 // Undoing/Redoing...
869 void ClearStateList (class CUndoState **pList);
870 void PushInput ();
871 void PushMark ();
872 void SetState (class CUndoState *s);
873
874 // Change management...
875 // ChangedInput (): see above
876 void ChangedContent () { changedContent = true; Changed (); } // input or suggestion
877 void ChangedMark ();
878
879 // Helpers...
880 int GetCharOfMouseEvent (SDL_Event *ev);
881};
882
883
891class CInputScreen: public CScreen {
892 public:
893 CInputScreen () {}
894 ~CInputScreen ();
895
898 void Setup (const char *label, const char *inputPreset, TColor color = GREY, int userBtns = 0, CButton **userBtnList = NULL, const int *userBtnWidth = NULL);
909
912 CInputLine *InputLine () { return &wdgInput; }
913 void SetInput (const char *_inputStr=NULL, int _mark0=0, int _markD=0) { wdgInput.SetInput (_inputStr, _mark0, _markD); }
915 void GetInput (CString *ret) { wdgInput.GetInput (ret); }
917 bool InputModified () { return wdgInput.InputModified (); }
920
921 protected:
922 CWidget wdgLabel;
923 CInputLine wdgInput;
924 CButton btnBack, btnUndo, btnRedo, btnCut, btnCopy, btnPaste, btnOk;
928 virtual void Commit () { Return (); }
930 virtual void Cancel () { Return (); }
933 virtual void OnUserButtonPushed (CButton *btn, bool longPush) {}
937 private:
938 friend void CbInputScreenOnButtonPushed (CButton *, bool, void *);
939
940 void OnButtonPushed (CButton *btn, bool longPush);
942
943
945
946
947
948
949
950// *************************** CSlider *****************************************
951
952
956
957
958#define SLIDER_WIDTH 48
959#define SLIDER_BAR_HEIGHT 16
960
961
962#define SLIDER_TRAMPOLINE(CB_NAME, CLASS_NAME, METHOD_NAME) \
963 void CB_NAME (class CSlider *slider, int val, int lastVal, void *data) { \
964 ((CLASS_NAME *) data)->METHOD_NAME (slider, val, lastVal); \
965 }
980
981
984class CSlider: public CWidget {
985 public:
986 CSlider ();
987 virtual ~CSlider ();
988
991 void SetFormat (TColor _colSlider, TColor _colBarLower, TColor _colBarUpper, TColor _colBack = TRANSPARENT, int _sliderW = SLIDER_WIDTH, int _barH = SLIDER_BAR_HEIGHT);
992 void SetArea (SDL_Rect _area);
993 void SetInterval (int _val0, int _val1, bool _continuousUpdate = true);
999
1002 int GetValue () { return val; }
1003 void SetValue (int _val, bool callOnValueChanged = false);
1006
1009 virtual void OnValueChanged (int val, int lastVal);
1010 void SetCbValueChanged (void (*_cbValueChanged) (class CSlider *, int, int, void *), void *_data = NULL) { cbValueChanged = _cbValueChanged; cbValueChangedData = _data; }
1012
1015 virtual SDL_Surface *GetSurface ();
1016 virtual bool HandleEvent (SDL_Event *ev);
1018
1019 protected:
1020 int sliderW, barH;
1021 TColor colSlider, colBarLower, colBarUpper, colBack;
1022 bool continuousUpdate, isDown, redraw;
1023
1024 int val0, val1, val;
1025 int slider0, downX; // X position of slider and of last "touch down" event
1026
1027 void (*cbValueChanged) (class CSlider *, int, int, void *);
1028 void *cbValueChangedData;
1029
1032 void ChangedSurface () { redraw = true; CWidget::ChangedSurface (); }
1033 void Changed () { redraw = true; CWidget::Changed (); }
1035
1036 // Helpers...
1037 void SetSlider0 (int _slider0, bool updateVal);
1038};
1039
1040
1042
1043
1044
1045
1051#endif
Push-button widget.
Definition: ui_widgets.H:214
void SetLabel(SDL_Surface *_icon, SDL_Rect *srcRect=NULL, bool takeOwnership=false)
Set '_icon' as the button label.
void SetLabel(const char *text, TColor textColor=WHITE, TTF_Font *font=NULL)
Set a text-only label.
void SetLabelAlignment(int _hAlign=0, int _vAlign=0)
Set/change label alignment.
Definition: ui_widgets.H:259
virtual bool HandleEvent(SDL_Event *ev)
Handle an event and return 'true' if the event was consumed and is to be ignored by later widgets.
void ClearLabel()
Remove label.
Definition: ui_widgets.H:257
virtual SDL_Surface * GetSurface()
Get an up-to-date surface or 'NULL' if none is available.
void SetHotkey(SDL_Keycode _hotkey)
Set hotkey which activates the button callback.
Definition: ui_widgets.H:262
Canvas widget.
Definition: ui_screen.H:213
void ScrollTo(SDL_Rect r, int hAlign=0, int vAlign=-1)
Scroll such that 'r' is aligned according to '[vh]Align' (-1 = left/up, 0 = center,...
void ScrollIn(SDL_Rect r)
Scroll just enough to get 'r' fully visible.
Widget with an additional rectangular cursor.
Definition: ui_widgets.H:125
virtual void Render(SDL_Renderer *ren)
Render this widget.
virtual bool HandleEvent(SDL_Event *ev)
Handle an event and return 'true' if the event was consumed and is to be ignored by later widgets.
Flat Push-button widget.
Definition: ui_widgets.H:310
virtual SDL_Surface * GetSurface()
Get an up-to-date surface or 'NULL' if none is available.
Input line widget.
Definition: ui_widgets.H:793
bool InputModified()
Return if anything may have changed.
int GetMark0()
Return the cursor position.
Definition: ui_widgets.H:815
CString * GetInput()
Return string (ISO 8859!) that may be modified arbitrarily, followed by a call to ChangedInput().
Definition: ui_widgets.H:825
void ClearHistory()
Clear the undo & redo history.
virtual void Render(SDL_Renderer *ren)
Render this widget.
void ChangedInput()
To be called if the imput string was changed.
void SetInput(const char *_inputStr=NULL, int _mark0=0, int _markD=0)
Set the input contents; implicitly calls 'ClearHistory' afterwards.
void MoveMark(int _mark0)
Set 'mark0' while leaving 'mark0 + markD' constant.
void GetInput(CString *ret)
Retrieve the current string.
Definition: ui_widgets.H:808
virtual bool HandleEvent(SDL_Event *ev)
Handle wiping/scrolling events, if virtual area is wider (higher) than physical area.
Screen with an input line widget.
Definition: ui_widgets.H:899
virtual void Cancel()
Definition: ui_widgets.H:938
virtual void OnUserButtonPushed(CButton *btn, bool longPush)
Called on push of any user button.
Definition: ui_widgets.H:941
void Setup(const char *label, const char *inputPreset, TColor color=GREY, int userBtns=0, CButton **userBtnList=NULL, const int *userBtnWidth=NULL)
virtual void Commit()
Called on push of the "OK" button. May call Return() on success or not to continue editing.
Definition: ui_widgets.H:936
void SetInput(const char *_inputStr=NULL, int _mark0=0, int _markD=0)
see CInputLine::SetInput ().
Definition: ui_widgets.H:921
bool InputModified()
see CInputLine::InputModified ().
Definition: ui_widgets.H:925
void GetInput(CString *ret)
see CInputLine::GetInput ().
Definition: ui_widgets.H:923
Listbox item.
Definition: ui_widgets.H:397
bool changed
If set, item will be re-rendered at next occasion.
Definition: ui_widgets.H:421
void SetLabel(const char *_text, const char *_iconName=NULL)
Set label with a text and icon, both are optional. The icon is recolored as the text.
Definition: ui_widgets.H:403
void * data
Reference to optional user data.
Definition: ui_widgets.H:411
bool isSpecial
Item is special, e.g. a head line.
Definition: ui_widgets.H:410
Listbox widget.
Definition: ui_widgets.H:427
SDL_Rect GetItemRect(int idx)
Get the area of an item.
bool MouseDown()
Determine whether the listbox is currently dragged by the mouse. In this case, calling a Select....
Definition: ui_widgets.H:472
void SelectItem(int idx, bool _isSelected=true)
(De-)Select item (for 'lmSelectSingle', 'lmSelectAny')
void ChangedItems(int idx, int num=1)
Must be called if items changed and SetItem() was not called.
virtual void Render(SDL_Renderer *ren)
Render this widget.
void SelectAll(bool _isSelected=true)
Select all items (for 'lmSelectAny')
void SetFormat(TTF_Font *_font, int _hAlign=-1, TColor colGrid=BLACK, TColor _colLabel=WHITE, TColor _colBack=DARK_DARK_GREY, TColor _colLabelSelected=WHITE, TColor _colBackSelected=GREY, TColor _colLabelSpecial=WHITE, TColor _colBackSpecial=DARK_GREY)
Except 'colGrid', all parameters set here are only read in 'RenderItem' & can be ommited (or re-inter...
virtual SDL_Surface * RenderItem(CListboxItem *item, int idx, SDL_Surface *surf)
Render a list box item to an SDL surface and return it.
void SetMode(EListboxMode _mode, int _itemHeight, int _itemGap=1)
'itemHeight' == 0 indicates variable-height items (Note: presently much worse performance than fixed-...
void SelectNone()
Deselect all items (for 'lmSelectSingle', 'lmSelectAny')
Definition: ui_widgets.H:470
virtual bool HandleEvent(SDL_Event *ev)
Handle wiping/scrolling events, if virtual area is wider (higher) than physical area.
int GetItemLabelWidth(int idx)
Retrieve the label (net) width of an item (e.g. to optimize geometry).
Menu widget.
Definition: ui_widgets.H:565
void SetItems(const char *_itemStr)
Set a list of items separated by '|'.
virtual void Start(CScreen *_screen)
Just start the modal widget.
virtual void Render(SDL_Renderer *ren)
Render this widget.
bool GetStatusLongPush()
Return whether the push was a long push.
Definition: ui_widgets.H:595
virtual bool HandleEvent(SDL_Event *ev)
Handle event: must always be called last.
Message box widget.
Definition: ui_widgets.H:683
int GetChoice()
Return the number of the button pushed, numbered from right to left; the rightmost button (typically ...
Definition: ui_widgets.H:717
CButton * GetStdButton(EMessageButtonId buttonId)
Initialize and return a standard button to be used by the previous method.
void Setup(const char *title, int contentW, int contentH, int _buttons, CButton **_buttonArr, TColor color=MSGBOX_COLOR, int titleHAlign=0)
The most flexible way.
virtual void Stop()
Remove widget from screen (e.g. useful for inactivity timeout).
virtual void Start(CScreen *_screen)
Just start the modal widget.
Widget that can pop up on a screen, such as a menu or a message box.
Definition: ui_widgets.H:77
void SetStatus(int _status)
Set a status code.
Definition: ui_widgets.H:92
bool IsRunning()
Must be invoked regularly (in each UI iteration), if Run() is not used.
virtual void Stop()
Remove widget from screen (e.g. useful for inactivity timeout).
virtual void Start(CScreen *_screen)
Just start the modal widget.
void SetNoCancelArea(SDL_Rect _rNoCancel)
Set the no-cancel area.
Definition: ui_widgets.H:97
int GetStatus()
Get status: -2: running, -1: cancelled (e.g. by touching outside), >= 0: success, user-defined code s...
Definition: ui_widgets.H:91
virtual bool HandleEvent(SDL_Event *ev)
Handle event: must always be called last.
int Run(CScreen *_screen)
Run the widget until it is cancelled or a status >= 0 is set; return status.
Screen object.
Definition: ui_screen.H:293
void Return()
Let Run() return at next occasion.
Definition: ui_screen.H:338
Slider widget.
Definition: ui_widgets.H:996
void SetValue(int _val, bool callOnValueChanged=false)
Set the current value; The passed value will be clipped to the allowed range.
void SetInterval(int _val0, int _val1, bool _continuousUpdate=true)
Set the logical range of values; Possible values for 'val' are then '_val0 <= val <= _val1'.
virtual bool HandleEvent(SDL_Event *ev)
Handle an event and return 'true' if the event was consumed and is to be ignored by later widgets.
virtual SDL_Surface * GetSurface()
Get an up-to-date surface or 'NULL' if none is available.
Dynamically allocated string.
Definition: base.H:635
void SetFromIso8859(const char *iso8859str)
'this' will be a (normal) UTF-8 string, the source is expected to be ISO-8859
char * Get() const
Get the C string. Unless explicitely set by 'SetC', this will never return NULL or an invalid pointer...
Definition: base.H:687
Base class for all widgets.
Definition: ui_screen.H:94
void ChangedSurface()
Mark (only) the surface as changed to trigger a redrawing at next occasion.
Definition: ui_screen.H:185
void Changed()
Anything may have changed: Trigger a redrawing at next occasion.
static SDL_Rect RectScreen()
Rectangle representing the whole UI screen.
Definition: ui_base.H:355
void UiIterate(bool noWait=false)
SDL_Surface * IconGet(const char *name, TColor color=WHITE, TColor bgColor=TRANSPARENT, int scaleDown=1, int orient=0, bool preserveThinLines=false)
Get a reference to an icon from the application's 'etc/icons/' or 'share/icons/' folder.
void CbActivateScreen(class CButton *, bool, void *screen)
Convenience callback for all sort of "Jump-to-screen" buttons (including home). 'data' must point to ...
CButton * CreateMainButtonBar(int buttons, TButtonDescriptor *descTable, CScreen *screen)
Create a dynamic array of CButton objects for a main button bar. 'screen' is passed as the user data ...
void FCbButtonPushed(class CButton *button, bool longPush, void *data)
Function prototype for CButton callbacks.
Definition: ui_widgets.H:177
void FCbListboxPushed(class CListbox *, int idx, bool longPush, void *data)
Callback prototype for CListbox push events.
Definition: ui_widgets.H:367
EListboxMode
List box mode.
Definition: ui_widgets.H:359
@ lmSelectAny
Items are arbitrarily selectable (activation callback can be defined, too).
Definition: ui_widgets.H:363
@ lmActivate
Items act like push-buttons, activation callback can be defined.
Definition: ui_widgets.H:361
@ lmReadOnly
Listbox is read-only, no selection & interaction.
Definition: ui_widgets.H:360
@ lmSelectSingle
Items are exclusivly selectable (activation callback can be defined, too).
Definition: ui_widgets.H:362
int RunMenu(const char *_itemStr, SDL_Rect _rContainer, int _hAlign=-1, int _vAlign=-1, TColor color=MENU_DEFAULT_COLOR, TTF_Font *_font=NULL, bool *retLongPush=NULL)
Run a menu with a single function call.
#define MENU_DEFAULT_COLOR
Default color for menus.
Definition: ui_widgets.H:560
int RunSureBox(const char *title, const char *text, SDL_Surface *icon=NULL, int hAlign=0, TTF_Font *font=NULL)
Run an "Are you sure?" box. Returns 1 if sure and <= 0 otherwise.
int RunQueryBox(const char *title, const char *text, SDL_Surface *icon=NULL, int hAlign=0, TTF_Font *font=NULL)
Run a "Yes/No/Cancel" query box. Returns 2 on "yes", 1 on "no" and 0 otherwise.
int RunMessageBox(const char *title, const char *text, int buttonMask=mbmOk, SDL_Surface *icon=NULL, int hAlign=0, TTF_Font *font=NULL)
Run an arbitray message box.
int RunWarnBox(const char *title, const char *text, SDL_Surface *icon=NULL, int hAlign=0, TTF_Font *font=NULL)
Run an warning box with an "OK" button.
#define MSGBOX_COLOR
Default color for message boxes.
Definition: ui_widgets.H:651
#define mbmOk
Bit mask to select an "OK" button.
Definition: ui_widgets.H:670
EMessageButtonId
IDs for standard buttons.
Definition: ui_widgets.H:660
int RunErrorBox(const char *title, const char *text, SDL_Surface *icon=NULL, int hAlign=0, TTF_Font *font=NULL)
Run an error box with an "OK" button.
int RunInfoBox(const char *title, const char *text, SDL_Surface *icon=NULL, int hAlign=0, TTF_Font *font=NULL)
Run an info box with an "OK" button.
#define SLIDER_WIDTH
Default width of a slider.
Definition: ui_widgets.H:966
#define SLIDER_BAR_HEIGHT
Default height of a slider bar.
Definition: ui_widgets.H:967
Descriptor for a button on the main button bar.
Definition: ui_widgets.H:325