UIpane.c
2.48 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <ultratypes.h>
#include "gfx.h"
#include "UI.h"
#include "UIpane.h"
#include "cursor.h"
void DefPaneDrawProc (UIPane *pPane, Gfx **ppGfx);
void DefItemDrawProc (UIItem *pPane, Gfx **ppGfx);
char DefHandleEventProc (UIPane *pPane, UIEvent *pEvent);
void
Pane_Init (UIPane *pPane)
{
/* Initialize the pane's fields. */
pPane->numItems = 0;
pPane->pData = NULL;
/* Setup the pane with default procs. */
pPane->DrawProc = DefPaneDrawProc;
pPane->HandleEventProc = DefHandleEventProc;
}
char
Pane_ItemClicked (UIPane *pPane, Point *pPt, UIItem **ppItem)
{
UIItem * pItem;
Rect globalRect;
int i;
for (i=0; i<pPane->numItems; i++)
{
pItem = &pPane->itemList[i];
globalRect = pItem->bounds;
OffsetRect (&globalRect, pItem->pPane->bounds.left, pItem->pPane->bounds.top);
if (PointInRect (&globalRect, pPt))
{
*ppItem = pItem;
return TRUE;
}
}
*ppItem = NULL;
return FALSE;
}
char
Pane_GetSelectedItem (UIPane *pPane, UIItem **ppItem)
{
int i;
char foundSelectedItem = FALSE;
*ppItem = NULL; /* safety's sake */
for (i=0; i<pPane->numItems; i++)
{
if (pPane->itemList[i].fIsSelected)
{
*ppItem = &pPane->itemList[i];
foundSelectedItem = TRUE;
break;
}
}
return foundSelectedItem;
}
void
Pane_DeselectAllItems (UIPane *pPane)
{
int i;
for (i=0; i<pPane->numItems; i++)
pPane->itemList[i].fIsSelected = FALSE;
}
/*
*
* UI Item routines
*
*/
void
Item_Init (UIItem *pItem, int id)
{
pItem->id = id;
pItem->pPane = NULL;
pItem->fIsClicked = FALSE;
pItem->fIsSelected = FALSE;
pItem->pSpriteIcon = NULL;
pItem->DrawProc = DefItemDrawProc;
}
void
Item_GetScreenBounds (UIItem *pItem, Rect *pRect)
{
*pRect = pItem->bounds;
OffsetRect (pRect, pItem->pPane->bounds.left, pItem->pPane->bounds.top);
}
void
Item_SetSelected (UIItem *pItem, char isSelected)
{
pItem->fIsSelected = isSelected;
}
char
Item_IsSelected (UIItem *pItem)
{
return pItem->fIsSelected;
}
/*
DEFAULT UI PROCS
*/
void
DefPaneDrawProc (UIPane *pPane, Gfx **ppGfx)
{
DrawBeveledRect (&pPane->bounds, FALSE, FALSE, ppGfx);
}
void
DefItemDrawProc (UIItem *pItem, Gfx **ppGfx)
{
Rect boundsRect;
Item_GetScreenBounds (pItem, &boundsRect);
DrawBeveledRect (&boundsRect, FALSE, FALSE, ppGfx);
}
char
DefHandleEventProc (UIPane *pPane, UIEvent *pEvent)
{}