129 void SetCursorFormat (TColor _cursorColor = ToColor (0xff, 0xff, 0xff, 0x20), SDL_BlendMode _blendMode = SDL_BLENDMODE_BLEND) { cursorColor = _cursorColor; blendMode = _blendMode; }
131 void SetCursor (SDL_Rect _cursorArea) { cursorArea = _cursorArea; }
132 void ClearCursor () { cursorArea.w = cursorArea.h = 0; }
134 void SetCbHandleEvent (
bool (*_cbHandleEvent) (SDL_Event *,
void *),
void *_data = NULL) { cbHandleEvent = _cbHandleEvent; cbHandleEventData = _data; }
142 SDL_BlendMode blendMode;
143 bool (*cbHandleEvent) (SDL_Event *,
void *);
144 void *cbHandleEventData;
173#define BUTTON_DEFAULT_FONT FontGet (fntNormal, 24)
174#define BUTTON_LABEL_BORDER 8
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); \
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);
228 void SetArea (SDL_Rect _area);
230 void SetColor (TColor _colNorm) { SetColor (_colNorm, _colNorm); }
231 void SetColor (TColor _colNorm, TColor _colDown);
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); }
255 void SetLabelAlignment (
int _hAlign = 0,
int _vAlign = 0) { hAlign = _hAlign; vAlign = _vAlign; ChangedSurface (); }
258 void SetHotkey (SDL_Keycode _hotkey) { hotkey = _hotkey; }
265 virtual void OnPushed (
bool longPush);
266 void SetCbPushed (
FCbButtonPushed *cb,
void *_data = NULL) { cbPushed = cb; cbPushedData = _data; }
267 void *GetCbPushedData () {
return cbPushedData; }
277 SDL_Surface *surfLabel;
278 bool surfLabelIsOwned;
279 TColor colNorm, colDown;
281 bool isDown, changed;
296#define FLATBUTTON_COL_UP BLACK
297#define FLATBUTTON_COL_DOWN ToColor (0x60, 0x00, 0x00)
308 CFlatButton () { SetColor (FLATBUTTON_COL_UP, FLATBUTTON_COL_DOWN); }
324 const char *iconName;
351#define LISTBOX_ITEM_BORDER 4
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); \
393 bool IsSelected () {
return isSelected; }
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; }
409 const char *iconName;
410 SDL_Surface *iconSurf;
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; }
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]; }
448 int GetItemHeight () {
return itemHeight; }
460 void SelectItem (
int idx,
bool _isSelected =
true);
461 void SelectAll (
bool _isSelected =
true);
464 bool MouseDown () {
return downIdx >= 0; }
471 bool ItemIsSelected (
int idx) {
return itemArr[idx].isSelected; }
472 int GetSelectedItem () {
return selectedItem; }
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; }
485 virtual void Render (SDL_Renderer *ren);
493 int poolSize, *poolIdx;
494 int selectedItem, downIdx, downSelectedItem;
500 int itemGap, itemHeight;
507 TColor colLabel, colBack, colLabelSelected, colBackSelected, colLabelSpecial, colBackSpecial;
525 void ChangedSetup () { InvalidatePool (); Changed (); }
532 void InvalidatePool ();
551#define MENU_DEFAULT_FONT FontGet (fntNormal, 20)
552#define MENU_DEFAULT_COLOR DARK_GREY
564 void Setup (SDL_Rect _rContainer,
int _hAlign = -1,
int _vAlign = -1,
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); }
577 int Run (
CScreen *_screen,
const char *_itemStr) {
SetItems (_itemStr);
return Run (_screen); }
593 SDL_Rect *GetArea () {
return &rFrame; }
598 virtual void Render (SDL_Renderer *ren);
600 virtual void OnPushed (
int idx,
bool longPush);
604 SDL_Rect rContainer, rFrame;
607 SDL_Texture *texFrame;
613int RunMenu (
const char *_itemStr, SDL_Rect _rContainer,
int _hAlign = -1,
int _vAlign = -1,
615 bool *retLongPush = NULL);
640#define MSGBOX_DEFAULT_FONT FontGet (fntNormal, 24)
641#define MSGBOX_TITLE_FONT FontGet (fntBold, 32)
643#define MSGBOX_COLOR DARK_GREY
645#define MSGBOX_SPACE_X 32
646#define MSGBOX_SPACE_Y 32
647#define MSGBOX_BUTTON_MINWIDTH 160
661#define mbmCancel ((int) (1 << mbiCancel))
662#define mbmOk ((int) (1 << mbiOk))
663#define mbmNo ((int) (1 << mbiNo))
664#define mbmYes ((int) (1 << mbiYes))
666#define mbmOkCancel (mbmOk | mbmCancel)
667#define mbmYesNoCancel (mbmYes | mbmNo | mbmCancel)
668#define mbmNone ((int) 0)
677 CMessageBox () { buttons = 0; buttonArr = NULL; screenHasKeyboard =
false; }
682 void Setup (
const char *title,
int contentW,
int contentH,
int _buttons,
CButton **_buttonArr, TColor color =
MSGBOX_COLOR,
int titleHAlign = 0);
693 void Setup (
const char *title,
int contentW,
int contentH,
int buttonMask, TColor color =
MSGBOX_COLOR);
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; }
718 virtual void OnButtonPushed (
CButton *button,
bool);
722 CButton stdButtons[mbiEND], **buttonArr, *stdButtonArr[mbiEND];
725 bool screenHasKeyboard;
731int RunMessageBox (
const char *title,
const char *text,
int buttonMask =
mbmOk, SDL_Surface *icon = NULL,
int hAlign = 0, TTF_Font *font = NULL);
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);
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 (); }
777#define INPUTLINE_FONTSIZE 24
778#define INPUTLINE_UNDOS 32
779#define INPUTLINE_MAXLEN 512
787 CInputLine () { font = NULL; inputLen = 0; mark0 = markD = 0; suggPos = -1; cbSuggCheck = NULL; suggData = NULL; undoFirst = redoFirst = NULL; surfMain = NULL; changedContent = changedMark =
false; }
792 void Setup (
int fontSize = INPUTLINE_FONTSIZE);
793 void SetInput (
const char *_inputStr = NULL,
int _mark0 = 0,
int _markD = 0);
808 int GetMarkD () {
return markD; }
809 void SetMark (
int _mark0,
int _markD = 0);
812 void InsChar (
char c);
813 void InsText (
const char *txt,
int chars = -1);
815 void DelChar (
int pos);
824 void ClipboardCopy ();
825 void ClipboardCut () { ClipboardCopy (); DelMarked (); }
826 void ClipboardPaste ();
837 void SetSuggestion (
int _suggPos,
const char *_suggText,
int _suggMark0 = -1,
int _suggMarkD = 0);
838 void ClearSuggestion () { SetSuggestion (-1, NULL); }
839 void ApplySuggestion ();
840 virtual void CheckSuggestion () {
if (cbSuggCheck) cbSuggCheck (
this, suggData); }
841 void SetCbCheckSuggestion (
void (*_cbSuggCheck) (
CInputLine *,
void *),
void *_suggData) { cbSuggCheck = _cbSuggCheck; suggData = _suggData; }
846 virtual void Render (SDL_Renderer *ren);
856 class CUndoState *undoFirst, *redoFirst;
858 int suggPos, suggMark0, suggMarkD;
864 SDL_Surface *surfMain;
866 bool changedContent, changedMark;
869 void ClearStateList (
class CUndoState **pList);
872 void SetState (
class CUndoState *s);
876 void ChangedContent () { changedContent =
true;
Changed (); }
880 int GetCharOfMouseEvent (SDL_Event *ev);
898 void Setup (
const char *label,
const char *inputPreset, TColor color = GREY,
int userBtns = 0,
CButton **userBtnList = NULL,
const int *userBtnWidth = NULL);
912 CInputLine *InputLine () {
return &wdgInput; }
913 void SetInput (
const char *_inputStr=NULL,
int _mark0=0,
int _markD=0) { wdgInput.
SetInput (_inputStr, _mark0, _markD); }
924 CButton btnBack, btnUndo, btnRedo, btnCut, btnCopy, btnPaste, btnOk;
938 friend void CbInputScreenOnButtonPushed (
CButton *,
bool,
void *);
940 void OnButtonPushed (
CButton *btn,
bool longPush);
958#define SLIDER_WIDTH 48
959#define SLIDER_BAR_HEIGHT 16
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); \
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);
1002 int GetValue () {
return val; }
1003 void SetValue (
int _val,
bool callOnValueChanged =
false);
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; }
1021 TColor colSlider, colBarLower, colBarUpper, colBack;
1022 bool continuousUpdate, isDown, redraw;
1024 int val0, val1, val;
1027 void (*cbValueChanged) (
class CSlider *, int, int,
void *);
1028 void *cbValueChangedData;
1037 void SetSlider0 (
int _slider0,
bool updateVal);
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.
bool changed
If set, item will be re-rendered at next occasion.
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.
void * data
Reference to optional user data.
bool isSpecial
Item is special, e.g. a head line.
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....
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')
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).
int GetChoice()
Return the number of the button pushed, numbered from right to left; the rightmost button (typically ...
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.
void Return()
Let Run() return at next occasion.
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.
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...
static SDL_Rect RectScreen()
Rectangle representing the whole UI screen.
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.