2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
27 void ui_draw_scrollbar( UI_GADGET_SCROLLBAR * scrollbar )
31 if (scrollbar->status==0)
34 scrollbar->status = 0;
37 gr_set_current_canvas( scrollbar->canvas );
39 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)scrollbar)
44 gr_rect( 0, 0, scrollbar->width-1, scrollbar->fake_position-1 );
45 gr_rect( 0, scrollbar->fake_position+scrollbar->fake_size, scrollbar->width-1, scrollbar->height-1);
47 ui_draw_box_out(0, scrollbar->fake_position, scrollbar->width-1, scrollbar->fake_position+scrollbar->fake_size-1 );
53 UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_WINDOW * wnd, short x, short y, short w, short h, int start, int stop, int position, int window_size )
57 UI_GADGET_SCROLLBAR * scrollbar;
60 up[0] = 30; up[1] = 0;
61 down[0] = 31; down[1] = 0;
63 gr_get_string_size( up, &tw, &th, &taw );
67 if (stop < start ) stop = start;
69 scrollbar = (UI_GADGET_SCROLLBAR *)ui_gadget_add( wnd, 3, x, y+w, x+w-1, y+h-w-1 );
71 scrollbar->up_button = ui_add_gadget_button( wnd, x, y, w, w, up, NULL );
72 scrollbar->up_button->parent = (UI_GADGET *)scrollbar;
74 scrollbar->down_button =ui_add_gadget_button( wnd, x, y+h-w, w, w, down, NULL );
75 scrollbar->down_button->parent = (UI_GADGET *)scrollbar;
78 scrollbar->width = scrollbar->x2-scrollbar->x1+1;
79 scrollbar->height = scrollbar->y2-scrollbar->y1+1;
80 scrollbar->start = start;
81 scrollbar->stop = stop;
82 scrollbar->position = position;
83 scrollbar->window_size = window_size;
84 scrollbar->fake_length = scrollbar->height;
85 scrollbar->fake_position = 0;
87 scrollbar->fake_size = (window_size * scrollbar->height)/(stop-start+1+window_size);
89 scrollbar->fake_size = scrollbar->height;
91 if (scrollbar->fake_size < 7) scrollbar->fake_size = 7;
92 scrollbar->dragging = 0;
94 scrollbar->last_scrolled = 0;
99 void ui_scrollbar_do( UI_GADGET_SCROLLBAR * scrollbar, int keypress )
101 int OnMe, OnSlider, keyfocus;
107 if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)scrollbar)
110 if (scrollbar->start==scrollbar->stop)
112 scrollbar->position = 0;
113 scrollbar->fake_position = 0;
114 ui_draw_scrollbar( scrollbar );
118 op = scrollbar->position;
120 oldpos = scrollbar->fake_position;
122 scrollbar->moved = 0;
125 if ( (scrollbar->up_button->position!=0) || (keyfocus && keyd_pressed[KEY_UP]) )
127 if (timer_get_fixed_seconds() > scrollbar->last_scrolled + 1)
129 scrollbar->last_scrolled = timer_get_fixed_seconds();
130 scrollbar->position--;
131 if (scrollbar->position < scrollbar->start )
132 scrollbar->position = scrollbar->start;
133 scrollbar->fake_position = scrollbar->position-scrollbar->start;
134 scrollbar->fake_position *= scrollbar->height-scrollbar->fake_size;
135 scrollbar->fake_position /= (scrollbar->stop-scrollbar->start);
139 if ( (scrollbar->down_button->position!=0) || (keyfocus && keyd_pressed[KEY_DOWN]) )
141 if (timer_get_fixed_seconds() > scrollbar->last_scrolled + 1)
143 scrollbar->last_scrolled = timer_get_fixed_seconds();
144 scrollbar->position++;
145 if (scrollbar->position > scrollbar->stop )
146 scrollbar->position = scrollbar->stop;
147 scrollbar->fake_position = scrollbar->position-scrollbar->start;
148 scrollbar->fake_position *= scrollbar->height-scrollbar->fake_size;
149 scrollbar->fake_position /= (scrollbar->stop-scrollbar->start);
153 OnMe = ui_mouse_on_gadget( (UI_GADGET *)scrollbar );
155 //gr_ubox(0, scrollbar->fake_position, scrollbar->width-1, scrollbar->fake_position+scrollbar->fake_size-1 );
158 scrollbar->dragging = 0;
160 //if (B1_PRESSED && OnMe )
161 // listbox->dragging = 1;
165 if ((Mouse.y >= scrollbar->fake_position+scrollbar->y1) && \
166 (Mouse.y < scrollbar->fake_position+scrollbar->y1+scrollbar->fake_size) && OnMe )
169 if (B1_JUST_PRESSED && OnSlider )
171 scrollbar->dragging = 1;
172 scrollbar->drag_x = Mouse.x;
173 scrollbar->drag_y = Mouse.y;
174 scrollbar->drag_starting = scrollbar->fake_position;
177 if (B1_PRESSED && OnMe && !OnSlider && (timer_get_fixed_seconds() > scrollbar->last_scrolled + 4))
179 scrollbar->last_scrolled = timer_get_fixed_seconds();
181 if ( Mouse.y < scrollbar->fake_position+scrollbar->y1 )
184 scrollbar->position -= scrollbar->window_size;
185 if (scrollbar->position < scrollbar->start )
186 scrollbar->position = scrollbar->start;
190 scrollbar->position += scrollbar->window_size;
191 if (scrollbar->position > scrollbar->stop )
192 scrollbar->position = scrollbar->stop;
194 scrollbar->fake_position = scrollbar->position-scrollbar->start;
195 scrollbar->fake_position *= scrollbar->height-scrollbar->fake_size;
196 scrollbar->fake_position /= (scrollbar->stop-scrollbar->start);
199 if ((selected_gadget==(UI_GADGET *)scrollbar) && B1_PRESSED && scrollbar->dragging )
201 //Mouse.x = scrollbar->drag_x;
202 scrollbar->fake_position = scrollbar->drag_starting + (Mouse.y - scrollbar->drag_y );
203 if (scrollbar->fake_position<0)
205 scrollbar->fake_position = 0;
206 //Mouse.y = scrollbar->fake_position + scrollbar->drag_y - scrollbar->drag_starting;
208 if (scrollbar->fake_position > (scrollbar->height-scrollbar->fake_size))
210 scrollbar->fake_position = (scrollbar->height-scrollbar->fake_size);
211 //Mouse.y = scrollbar->fake_position + scrollbar->drag_y - scrollbar->drag_starting;
214 //mouse_set_pos( Mouse.x, Mouse.y );
216 scrollbar->position = scrollbar->fake_position;
217 scrollbar->position *= (scrollbar->stop-scrollbar->start);
218 scrollbar->position /= ( scrollbar->height-scrollbar->fake_size ) ;
219 scrollbar->position += scrollbar->start;
221 if (scrollbar->position > scrollbar->stop )
222 scrollbar->position = scrollbar->stop;
224 if (scrollbar->position < scrollbar->start )
225 scrollbar->position = scrollbar->start;
227 //scrollbar->fake_position = scrollbar->position-scrollbar->start;
228 //scrollbar->fake_position *= scrollbar->height-scrollbar->fake_size;
229 //scrollbar->fake_position /= (scrollbar->stop-scrollbar->start);
233 if (op != scrollbar->position )
234 scrollbar->moved = 1;
236 if (oldpos != scrollbar->fake_position)
237 scrollbar->status = 1;
238 ui_draw_scrollbar( scrollbar );