blob: 224d6915539af5081ebe8c7c33411d54a9864c58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include "widget.h"
static void
cherry_widget_draw(CherryWidget *widget)
{
if (cherry_widget_is_visible(*widget) == 0) return;
widget->drawn = 1;
}
CherryWidget
cherry_widget_new(void)
{
CherryWidget widget;
widget.x = 0;
widget.y = 0;
widget.widgets = clist_create();
widget.width = 0;
widget.height = 0;
widget.visible = 0;
widget.drawn = 0;
widget.draw = cherry_widget_draw;
return widget;
}
void
cherry_widget_get_dimension(CherryWidget *widget, int *width, int *height) {
*width = widget->width;
*height = widget->height;
}
void
cherry_widget_set_dimension(CherryWidget *widget, int width, int height)
{
widget->width = width;
widget->height = height;
}
void
cherry_widget_add_component(CherryWidget *parent, CherryWidget *child)
{
clist_add(&parent->widgets, child);
if (cherry_widget_is_visible(parent) && parent->drawn) {
child->draw(child);
}
}
int
cherry_widget_is_visible(CherryWidget *widget)
{
return widget->visible;
}
void
cherry_widget_set_visible(CherryWidget *widget, int visible)
{
widget->visible = visible;
if (visible && widget->drawn == 0)
widget->draw(widget);
}
void
cherry_widget_get_position(CherryWidget *widget, int *x, int *y)
{
*x = widget->x;
*y = widget->y;
}
void
cherry_widget_set_position(CherryWidget *widget, int x, int y)
{
widget->x = x;
widget->y = y;
}
|