1 /* Public domain */ 2 3 #ifndef _AGAR_WIDGET_LABEL_H_ 4 #define _AGAR_WIDGET_LABEL_H_ 5 6 #include <agar/gui/widget.h> 7 #include <agar/gui/text.h> 8 9 #include <agar/gui/begin.h> 10 11 #define AG_LABEL_MAX 1024 /* Max format string length */ 12 #define AG_LABEL_MAX_POLLPTRS 32 /* Max polled pointers */ 13 14 struct ag_label; 15 struct ag_text_cache; 16 17 /* Type of label */ 18 enum ag_label_type { 19 AG_LABEL_STATIC, /* Display static text */ 20 AG_LABEL_POLLED /* Display an AG_FmtString(3) */ 21 }; 22 23 typedef struct ag_label { 24 struct ag_widget wid; 25 enum ag_label_type type; 26 Uint flags; 27 #define AG_LABEL_HFILL 0x01 /* Fill horizontal space */ 28 #define AG_LABEL_VFILL 0x02 /* Fill vertical space */ 29 #define AG_LABEL_NOMINSIZE 0x04 /* No minimum enforced size */ 30 #define AG_LABEL_PARTIAL 0x10 /* Partial mode (RO) */ 31 #define AG_LABEL_REGEN 0x20 /* Regenerate surface at next draw */ 32 #define AG_LABEL_FRAME 0x80 /* Draw visible frame */ 33 #define AG_LABEL_EXPAND (AG_LABEL_HFILL|AG_LABEL_VFILL) 34 char *text; /* Text buffer (for static labels) */ 35 int surface; /* Label surface */ 36 int surfaceCont; /* [...] surface */ 37 int wPre, hPre; /* SizeHint dimensions */ 38 int lPad, rPad, tPad, bPad; /* Label padding */ 39 enum ag_text_justify justify; /* Justification mode */ 40 enum ag_text_valign valign; /* Vertical alignment */ 41 struct ag_text_cache *tCache; /* Cache for polled labels */ 42 AG_Rect rClip; /* Clipping rectangle */ 43 AG_FmtString *fmt; /* Polled label data */ 44 char *pollBuf; /* Buffer for polled labels */ 45 size_t pollBufSize; 46 } AG_Label; 47 48 __BEGIN_DECLS 49 extern AG_WidgetClass agLabelClass; 50 51 AG_Label *AG_LabelNew(void *, Uint, const char *, ...) 52 FORMAT_ATTRIBUTE(printf, 3, 4); 53 AG_Label *AG_LabelNewS(void *, Uint, const char *); 54 AG_Label *AG_LabelNewPolled(void *, Uint, const char *, ...); 55 AG_Label *AG_LabelNewPolledMT(void *, Uint, AG_Mutex *, const char *, ...); 56 57 void AG_LabelText(AG_Label *, const char *, ...) 58 FORMAT_ATTRIBUTE(printf, 2, 3) 59 NONNULL_ATTRIBUTE(2); 60 void AG_LabelTextS(AG_Label *, const char *); 61 62 void AG_LabelSetPadding(AG_Label *, int, int, int, int); 63 void AG_LabelJustify(AG_Label *, enum ag_text_justify); 64 void AG_LabelValign(AG_Label *, enum ag_text_valign); 65 #define AG_LabelSetPaddingLeft(lbl,v) AG_LabelSetPadding((lbl),(v),-1,-1,-1) 66 #define AG_LabelSetPaddingRight(lbl,v) AG_LabelSetPadding((lbl),-1,(v),-1,-1) 67 #define AG_LabelSetPaddingTop(lbl,v) AG_LabelSetPadding((lbl),-1,-1,(v),-1) 68 #define AG_LabelSetPaddingBottom(lbl,v) AG_LabelSetPadding((lbl),-1,-1,-1,(v)) 69 void AG_LabelSizeHint(AG_Label *, Uint, const char *); 70 71 #ifdef AG_LEGACY 72 # define AG_LabelNewStatic AG_LabelNew 73 # define AG_LabelNewString AG_LabelNewS 74 # define AG_LabelNewStaticS AG_LabelNewS 75 # define AG_LabelPrintf AG_LabelText 76 # define AG_LabelString(lbl,s) AG_LabelTextS((lbl),(s)) 77 # define AG_LabelPrescale AG_LabelSizeHint 78 # define AG_LABEL_POLLED_MT AG_LABEL_POLLED 79 # define AG_LabelSetFont AG_SetFont 80 #endif /* AG_LEGACY */ 81 __END_DECLS 82 83 #include <agar/gui/close.h> 84 #endif /* _AGAR_WIDGET_LABEL_H_ */ 85