1 /* Public domain */ 2 3 #ifndef _AGAR_WIDGET_BUTTON_H_ 4 #define _AGAR_WIDGET_BUTTON_H_ 5 6 #include <agar/gui/widget.h> 7 #include <agar/gui/label.h> 8 9 #include <agar/gui/begin.h> 10 11 typedef struct ag_button { 12 struct ag_widget wid; 13 int state; /* Default state binding */ 14 AG_Label *lbl; /* Text label */ 15 int surface; /* Icon surface handle */ 16 enum ag_text_justify justify; /* Label justification */ 17 enum ag_text_valign valign; /* Vertical alignment */ 18 Uint flags; 19 #define AG_BUTTON_STICKY 0x0002 /* Toggle state */ 20 #define AG_BUTTON_REPEAT 0x0008 /* Repeat button-pushed event */ 21 #define AG_BUTTON_HFILL 0x0010 /* Fill available width */ 22 #define AG_BUTTON_VFILL 0x0020 /* Fill available height */ 23 #define AG_BUTTON_INVSTATE 0x0400 /* Invert value of "state" binding */ 24 #define AG_BUTTON_KEYDOWN 0x0800 /* Got `key-down' before `key-up' */ 25 #define AG_BUTTON_EXCL 0x1000 26 #define AG_BUTTON_NOEXCL 0x2000 /* For AG_ButtonNewFn() */ 27 #define AG_BUTTON_EXPAND (AG_BUTTON_HFILL|AG_BUTTON_VFILL) 28 29 int lPad, rPad, tPad, bPad; /* Padding in pixels */ 30 AG_Timer delayTo, repeatTo; /* For AG_BUTTON_REPEAT */ 31 } AG_Button; 32 33 __BEGIN_DECLS 34 extern AG_WidgetClass agButtonClass; 35 36 AG_Button *AG_ButtonNew(void *, Uint, const char *, ...) 37 FORMAT_ATTRIBUTE(printf, 3, 4); 38 AG_Button *AG_ButtonNewS(void *, Uint, const char *); 39 AG_Button *AG_ButtonNewFn(void *, Uint, const char *, AG_EventFn, 40 const char *, ...); 41 AG_Button *AG_ButtonNewInt(void *, Uint, const char *, int *); 42 AG_Button *AG_ButtonNewUint8(void *, Uint, const char *, Uint8 *); 43 AG_Button *AG_ButtonNewUint16(void *, Uint, const char *, Uint16 *); 44 AG_Button *AG_ButtonNewUint32(void *, Uint, const char *, Uint32 *); 45 46 AG_Button *AG_ButtonNewFlag(void *, Uint, const char *, Uint *, Uint); 47 AG_Button *AG_ButtonNewFlag8(void *, Uint, const char *, Uint8 *, Uint8); 48 AG_Button *AG_ButtonNewFlag16(void *, Uint, const char *, Uint16 *, Uint16); 49 AG_Button *AG_ButtonNewFlag32(void *, Uint, const char *, Uint32 *, Uint32); 50 51 void AG_ButtonSetPadding(AG_Button *, int, int, int, int); 52 #define AG_ButtonSetPaddingLeft(b,v) AG_ButtonSetPadding((b),(v),-1,-1,-1) 53 #define AG_ButtonSetPaddingRight(b,v) AG_ButtonSetPadding((b),-1,(v),-1,-1) 54 #define AG_ButtonSetPaddingTop(b,v) AG_ButtonSetPadding((b),-1,-1,(v),-1) 55 #define AG_ButtonSetPaddingBottom(b,v) AG_ButtonSetPadding((b),-1,-1,-1,(v)) 56 void AG_ButtonSetFocusable(AG_Button *, int); 57 void AG_ButtonSetSticky(AG_Button *, int); 58 void AG_ButtonInvertState(AG_Button *, int); 59 void AG_ButtonJustify(AG_Button *, enum ag_text_justify); 60 void AG_ButtonValign(AG_Button *, enum ag_text_valign); 61 void AG_ButtonSurface(AG_Button *, const AG_Surface *); 62 void AG_ButtonSurfaceNODUP(AG_Button *, AG_Surface *); 63 void AG_ButtonSetRepeatMode(AG_Button *, int); 64 65 void AG_ButtonText(AG_Button *, const char *, ...) 66 FORMAT_ATTRIBUTE(printf, 2, 3) 67 NONNULL_ATTRIBUTE(2); 68 void AG_ButtonTextS(AG_Button *, const char *); 69 70 #ifdef AG_LEGACY 71 # define AG_ButtonAct AG_ButtonNewFn 72 # define AG_ButtonSetSurface(bu,su) AG_ButtonSurface((bu),(su)) 73 # define AG_ButtonPrintf AG_ButtonText 74 # define AG_ButtonEnable AG_WidgetEnable 75 # define AG_ButtonDisable AG_WidgetDisable 76 # define AG_ButtonSetJustification AG_ButtonJustify 77 #endif /* AG_LEGACY */ 78 79 __END_DECLS 80 81 #include <agar/gui/close.h> 82 #endif /* _AGAR_WIDGET_BUTTON_H_ */ 83