=== Overview ===
[xuni.git] / src / widget / textbox.c
blob2c1fcf5b04b66042614d59e141034792f5d938d7
1 /*! \file textbox.c
3 Implements textbox widgets. Some textbox-specific code is sprinkled
4 elsewhere at the moment too, such as in label.c and in functions in gui.c
5 like activate_widget() and revert_widget().
6 */
8 #include "SDL_gfxPrimitives.h" /* for vlineRGBA() */
10 #include "../graphics.h"
11 #include "../memory.h"
12 #include "font.h"
13 #include "widgets.h"
14 #include "textbox.h"
15 #include "box.h"
16 #include "label.h"
18 static void free_textbox(struct xuni_t *xuni, struct widget_t *widget);
19 static void reposition_textbox(struct xuni_t *xuni, struct widget_t *widget);
20 static void rescale_textbox(struct xuni_t *xuni, struct widget_t *widget);
21 static void paint_textbox(struct xuni_t *xuni, struct widget_t *widget);
23 void textbox_widget_event(struct xuni_t *xuni, struct widget_t *widget,
24 enum widget_event_t event) {
26 static void (*function[])(struct xuni_t *xuni, struct widget_t *widget)
27 = {
29 free_textbox,
31 paint_textbox,
32 reposition_textbox,
33 rescale_textbox
36 call_widget_event_func(xuni, widget, event, function,
37 sizeof(function) / sizeof(*function));
40 void init_textbox(struct widget_t *widget, struct xuni_t *xuni,
41 const char *text, size_t font) {
43 widget->type = WIDGET_TEXTBOX;
44 widget->p.textbox = xuni_memory_allocate(sizeof(*widget->p.textbox));
46 widget->p.textbox->leftpos = 0;
48 add_allocate_widget_compose(widget, "alwaysinbox");
50 init_widget_pos(last_compose_widget(widget), 0, 0, 100.0, 100.0,
51 POS_PACK_NONE);
52 init_box(last_compose_widget(widget), BOX_STYLE_ALWAYSIN, 0);
53 /*last_compose_widget(widget)->visibility &= ~WIDGET_VISIBILITY_SELABLE;*/
54 last_compose_widget(widget)->visibility &= ~WIDGET_VISIBILITY_INDEPENDENT;
56 add_allocate_widget_compose(widget, "text");
58 init_widget_pos(last_compose_widget(widget), 0, 0, 100.0, 100.0,
59 POS_PACK_NONE);
60 init_label(last_compose_widget(widget), font, text, LABEL_ALIGN_LEFT,
61 255, 255, 255);
62 /* !!! why does reposition_widget() not work? */
63 /* !!! why was this here? */
64 /*widget_event(xuni, widget, WIDGET_EVENT_RESCALE);*/
65 last_compose_widget(widget)->visibility &= ~WIDGET_VISIBILITY_INDEPENDENT;
67 widget->visibility &= ~WIDGET_VISIBILITY_NOT_COMPOSE;
70 static void free_textbox(struct xuni_t *xuni, struct widget_t *widget) {
71 xuni_memory_free(widget->p.textbox);
74 static void paint_textbox(struct xuni_t *xuni, struct widget_t *widget) {
75 set_box_type(xuni->gui, widget,
76 widget->compose->widget[WID_TEXTBOX_BOX]);
77 paint_box_previous_state(xuni,
78 widget->compose->widget[WID_TEXTBOX_BOX]);
80 /*widget_event(xuni, widget->compose->widget[WID_TEXTBOX_BOX],
81 WIDGET_EVENT_PAINT);*/
83 widget_event(xuni, widget->compose->widget[WID_TEXTBOX_LABEL],
84 WIDGET_EVENT_PAINT);
86 /*paint_textbox_text(xuni->smode->screen, xuni->font, xuni->gui,
87 widget->p.textbox->data.scroll.text,
88 &widget->pos->real,
89 xuni->gui->active.widget == widget->compose->widget[0]);*/
92 static void reposition_textbox(struct xuni_t *xuni, struct widget_t *widget) {
96 static void rescale_textbox(struct xuni_t *xuni, struct widget_t *widget) {
97 /*struct widget_t *label = widget->compose->widget[WID_TEXTBOX_LABEL];
99 if(label->p.label && label->p.label->label) {
100 if(label->p.label->label->w > widget->pos->real.w) {
101 int offset = label->p.label->label->w - widget->pos->real.w;
103 set_widget_clip(label, 0, 0, offset, 0,
104 label->p.label->label->w - offset, label->p.label->label->h);
109 const char *get_textbox_data(struct widget_t *widget) {
110 return widget->compose->widget[WID_TEXTBOX_LABEL]->p.label->text;