2 * $Logfile: /Freespace2/code/UI/SCROLL.cpp $
7 * Code for vertical scrollbars.
10 * Revision 1.1 2002/05/03 03:28:11 root
14 * 4 12/02/98 5:47p Dave
15 * Put in interface xstr code. Converted barracks screen to new format.
17 * 3 10/13/98 9:29a Dave
18 * Started neatening up freespace.h. Many variables renamed and
19 * reorganized. Added AlphaColors.[h,cpp]
21 * 2 10/07/98 10:54a Dave
24 * 1 10/07/98 10:51a Dave
26 * 15 3/23/98 5:48p Hoffoss
27 * Improved listbox handling. Most notibly the scrollbar arrows work now.
29 * 14 2/03/98 4:21p Hoffoss
30 * Made UI controls draw white text when disabled.
32 * 13 1/14/98 6:44p Hoffoss
33 * Massive changes to UI code. A lot cleaner and better now. Did all
34 * this to get the new UI_DOT_SLIDER to work properly, which the old code
35 * wasn't flexible enough to handle.
37 * 12 8/24/97 5:24p Lawrance
38 * improve drawing of buttons
40 * 11 6/12/97 12:39p John
41 * made ui use freespace colors
43 * 10 6/11/97 1:13p John
44 * Started fixing all the text colors in the game.
46 * 9 5/26/97 10:26a Lawrance
47 * get slider control working 100%
49 * 8 5/22/97 5:36p Lawrance
50 * allowing custom art for scrollbars
52 * 7 1/28/97 4:58p Lawrance
53 * allowing hidden UI components
55 * 6 12/04/96 3:00p John
56 * Added code to allow adjusting of HUD colors and saved it to the player
59 * 5 12/03/96 11:29a John
60 * Made scroll buttons on listbox scroll once, then delay, then repeat
61 * when the buttons are held down.
63 * 4 12/02/96 2:50p John
64 * Made list box not scroll instantly.
66 * 3 12/02/96 2:17p John
67 * Made right button drag UI gadgets around and
68 * Ctrl+Shift+Alt+F12 dumps out where they are.
70 * 2 11/15/96 11:43a John
72 * 1 11/14/96 6:55p John
80 #include "alphacolors.h"
83 // --------------------------------------------------------------------
84 // UI_SCROLLBAR::link_hotspot
87 void UI_SCROLLBAR::link_hotspot(int up_button_num, int down_button_num)
89 up_button.link_hotspot(up_button_num);
90 down_button.link_hotspot(down_button_num);
93 // --------------------------------------------------------------------
94 // UI_SCROLLBAR::set_bmaps
96 // Call the UI_GADGET::set_bmaps() function for the child components
97 // of a scroll bar (the up and down button). Set up the bmaps for the
100 // We also need to get the dimensions of the bitmap button so we can update
101 // the dimensions of the scrollbar.
103 // returns: -1 ==> error
106 int UI_SCROLLBAR::set_bmaps(char *up_button_fname, char *down_button_fname, char *line_fname)
110 up_button.set_bmaps(up_button_fname);
111 down_button.set_bmaps(down_button_fname);
112 up_button.get_dimensions(&bx, &by, &bw, &bh);
114 // set the bitmaps for the rectangle that is the scrollbar itself
115 ((UI_GADGET*)this)->set_bmaps(line_fname);
118 update_dimensions(x,y+bw,bw,h-bw*2);
123 void UI_SCROLLBAR::hide()
130 void UI_SCROLLBAR::unhide()
134 down_button.unhide();
137 int UI_SCROLLBAR::get_hidden()
142 void UI_SCROLLBAR::create(UI_WINDOW *wnd, int _x, int _y, int _h, int _start, int _stop, int _position, int _window_size)
148 base_create( wnd, UI_KIND_SCROLLBAR, _x, _y + bw, bw, _h - bw * 2 );
150 up_button.create( wnd, up, _x, _y, bw, bw, 1 );
151 up_button.set_parent(this);
152 up_button.set_hotkey_if_focus(KEY_UP);
154 down_button.create( wnd, down, _x, _y + _h - bw, bw, bw, 1 );
155 down_button.set_parent(this);
156 down_button.set_hotkey_if_focus(KEY_DOWN);
161 position = _position;
162 window_size = _window_size;
169 bar_size = (window_size * h) / (stop - start + window_size + 1);
176 bar_position = position - start;
177 bar_position *= h - bar_size;
178 bar_position /= stop - start;
185 void UI_SCROLLBAR::draw()
192 if ( bmap_ids[SB_DISABLED] != -1 ) {
193 gr_set_bitmap(bmap_ids[SB_DISABLED]);
198 if ( bmap_ids[SB_NORMAL] != -1 ) {
199 gr_set_bitmap(bmap_ids[SB_NORMAL]);
204 gr_set_clip( x, y, w, h );
205 ui_draw_box_out( 0, bar_position, w - 1, bar_position + bar_size - 1 );
208 gr_set_font(my_wnd->f_id);
209 gr_set_clip( x, y, w, h );
211 if (my_wnd->selected_gadget == this)
212 gr_set_color_fast(&CBRIGHT_GREEN);
214 gr_set_color_fast(&CGRAY);
217 ui_rect( 0, 0, w-1, bar_position-1 );
218 ui_rect( 0, bar_position+bar_size, w-1, h-1);
220 ui_rect( 0, 0, w-1, h-1 );
221 ui_draw_box_out( 0, bar_position, w - 1, bar_position + bar_size - 1 );
225 void UI_SCROLLBAR::process(int focus)
235 if (my_wnd->selected_gadget == this)
238 up_button.process(focus);
239 down_button.process(focus);
248 oldpos = bar_position;
250 if (up_button.pressed()) {
252 if (position < start)
255 bar_position = position - start;
256 bar_position *= h - bar_size;
257 bar_position /= stop - start;
261 if ( (up_button.position != 0) || (focus && keyd_pressed[KEY_UP]) ) {
262 if ( (timer_get_milliseconds() > last_scrolled + 50) || up_button.just_pressed() ) {
263 if ( up_button.just_pressed() ) {
264 last_scrolled = timer_get_milliseconds() + 300;
266 last_scrolled = timer_get_milliseconds();
269 if (position < start)
272 bar_position = position - start;
273 bar_position *= h - bar_size;
274 bar_position /= stop - start;
278 if (down_button.pressed()) {
283 bar_position = position - start;
284 bar_position *= h - bar_size;
285 bar_position /= stop - start;
289 /* if ( down_button.position || (keyfocus && keyd_pressed[KEY_DOWN]) ) {
290 if ( (timer_get_milliseconds() > last_scrolled + 50) || down_button.just_pressed() ) {
291 if ( down_button.just_pressed() )
292 last_scrolled = timer_get_milliseconds() + 300;
294 last_scrolled = timer_get_milliseconds();
297 if (position > stop )
300 bar_position = position-start;
301 bar_position *= h-bar_size;
302 bar_position /= (stop-start);
306 OnMe = is_mouse_on();
312 if ( (ui_mouse.y >= bar_position + y) && (ui_mouse.y < bar_position + y + bar_size) && OnMe )
315 if (B1_JUST_PRESSED && OnSlider) {
319 drag_starting = bar_position;
323 if ( B1_PRESSED && OnMe && !OnSlider && (timer_get_milliseconds() > last_scrolled + 1000 / (18*4)) ) {
324 last_scrolled = timer_get_milliseconds();
326 if ( ui_mouse.y < bar_position+y ) {
328 position -= window_size;
329 if (position < start)
334 position += window_size;
339 bar_position = position - start;
340 bar_position *= h - bar_size;
341 bar_position /= stop - start;
345 if (B1_PRESSED && dragging) {
346 bar_position = drag_starting + ui_mouse.y - drag_y;
348 if (bar_position < 0) {
352 if (bar_position > h - bar_size) {
353 bar_position = h - bar_size;
356 position = bar_position;
357 position *= stop - start;
358 position /= h - bar_size;
364 if (position < start)
376 int UI_SCROLLBAR::getpos()
381 int UI_SCROLLBAR::changed()