5 using namespace Options
;
6 extern FocusStack optionstack
;
8 #define DLG_X ((SCREEN_WIDTH / 2) - 88)
9 #define DLG_Y ((SCREEN_HEIGHT / 2) - 90)
13 #define REPEAT_WAIT 30
25 fTextX
= (fCoords
.x
+ 48);
31 optionstack
.AddItem(this);
36 for(int i
=0;ODItem
*item
= ItemAt(i
);i
++)
39 optionstack
.RemoveItem(this);
42 void Dialog::SetSize(int w
, int h
)
46 fCoords
.x
= ((DLG_W
/ 2) - (w
/ 2)) + DLG_X
;
47 fCoords
.y
= ((DLG_H
/ 2) - (h
/ 2)) + DLG_Y
;
48 fTextX
= (fCoords
.x
+ 34);
51 void Dialog::offset(int xd
, int yd
)
59 void c------------------------------() {}
62 ODItem
*Dialog::AddItem(const char *text
, \
63 void (*activate
)(ODItem
*, int), \
64 void (*update
)(ODItem
*),\
67 ODItem
*item
= new ODItem
;
68 memset(item
, 0, sizeof(ODItem
));
70 strcpy(item
->text
, text
);
72 item
->activate
= activate
;
73 item
->update
= update
;
85 ODItem
*Dialog::AddSeparator()
87 return AddItem("", NULL
, NULL
, -1, OD_SEPARATOR
);
90 ODItem
*Dialog::AddDismissalItem(const char *text
)
92 if (!text
) text
= "Return";
93 return AddItem(text
, NULL
, NULL
, -1, OD_DISMISS
);
97 void c------------------------------() {}
102 TextBox::DrawFrame(fCoords
.x
, fCoords
.y
, fCoords
.w
, fCoords
.h
);
105 int y
= (fCoords
.y
+ 18);
108 ODItem
*item
= (ODItem
*)fItems
.ItemAt(i
);
112 DrawItem(x
, y
, item
);
115 draw_sprite(x
- 16, y
, SPR_WHIMSICAL_STAR
, 1);
117 y
+= GetFontHeight();
124 void Dialog::DrawItem(int x
, int y
, ODItem
*item
)
128 strcpy(text
, item
->text
);
129 strcat(text
, item
->suffix
);
132 // comes first because it can trim the text on the left side if needed
133 if (item
->raligntext
[0])
135 int rx
= (fCoords
.x
+ fCoords
.w
) - 10;
136 rx
-= GetFontWidth(item
->raligntext
, 5);
137 font_draw(rx
, y
, item
->raligntext
, 5);
139 // ... ellipses if too long
141 //FillRect(maxx, 0, maxx, SCREEN_HEIGHT, 0,255,0);
144 int wd
= GetFontWidth(text
, 0);
145 if (x
+wd
< maxx
) break;
147 int len
= strlen(text
);
148 if (len
<= 3) { *text
= 0; break; }
157 font_draw(x
, y
, text
, 0);
160 if (item
->righttext
[0])
162 font_draw((fCoords
.x
+ fCoords
.w
) - 62, y
, item
->righttext
, 0);
168 void c------------------------------() {}
171 void Dialog::RunInput()
173 if (inputs
[UPKEY
] || inputs
[DOWNKEY
])
175 int dir
= (inputs
[DOWNKEY
]) ? 1 : -1;
179 fRepeatTimer
= (lastinputs
[UPKEY
] || lastinputs
[DOWNKEY
]) ? REPEAT_RATE
: REPEAT_WAIT
;
180 sound(SND_MENU_MOVE
);
182 int nitems
= fItems
.CountItems();
186 if (fCurSel
< 0) fCurSel
= (nitems
- 1);
187 else fCurSel
%= nitems
;
189 ODItem
*item
= ItemAt(fCurSel
);
190 if (item
&& item
->type
!= OD_SEPARATOR
) break;
195 else fRepeatTimer
= 0;
198 if (buttonjustpushed() || justpushed(RIGHTKEY
) || justpushed(LEFTKEY
))
200 int dir
= (!inputs
[LEFTKEY
] || buttonjustpushed() || justpushed(RIGHTKEY
)) ? 1 : -1;
202 ODItem
*item
= ItemAt(fCurSel
);
205 if (item
->type
== OD_DISMISS
)
209 sound(SND_MENU_MOVE
);
210 if (ondismiss
) (*ondismiss
)();
214 else if (item
->activate
)
216 (*item
->activate
)(item
, dir
);
219 (*item
->update
)(item
);
224 /*if (justpushed(ESCKEY))
231 void Dialog::SetSelection(int sel
)
233 if (sel
< 0) sel
= fItems
.CountItems();
234 if (sel
>= fItems
.CountItems()) sel
= (fItems
.CountItems() - 1);
240 void Dialog::Dismiss()
245 void Dialog::Refresh()
247 for(int i
=0;ODItem
*item
= ItemAt(i
);i
++)
250 (*item
->update
)(item
);
259 for(int i
=0;ODItem
*item
= ItemAt(i
);i
++)