44 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y) |
44 void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y) |
45 { |
45 { |
46 int mi, ma, pos; |
46 int mi, ma, pos; |
47 Scrollbar *sb; |
47 Scrollbar *sb; |
48 |
48 |
49 if (wi->type == WWT_SCROLLBAR) { |
49 switch (wi->type) { |
50 // vertical scroller |
50 case WWT_SCROLLBAR: { |
51 w->flags4 &= ~WF_HSCROLL; |
51 // vertical scroller |
52 mi = wi->top; |
52 w->flags4 &= ~WF_HSCROLL; |
53 ma = wi->bottom; |
53 w->flags4 &= ~WF_SCROLL2; |
54 pos = y; |
54 mi = wi->top; |
55 sb = &w->vscroll; |
55 ma = wi->bottom; |
56 } else { |
56 pos = y; |
57 // horizontal scroller |
57 sb = &w->vscroll; |
58 assert(wi->type == WWT_HSCROLLBAR); |
58 break; |
59 w->flags4 |= WF_HSCROLL; |
59 } |
60 mi = wi->left; |
60 case WWT_SCROLL2BAR: { |
61 ma = wi->right; |
61 // 2nd vertical scroller |
62 pos = x; |
62 w->flags4 &= ~WF_HSCROLL; |
63 sb = &w->hscroll; |
63 w->flags4 |= WF_SCROLL2; |
|
64 mi = wi->top; |
|
65 ma = wi->bottom; |
|
66 pos = y; |
|
67 sb = &w->vscroll2; |
|
68 break; |
|
69 } |
|
70 case WWT_HSCROLLBAR: { |
|
71 // horizontal scroller |
|
72 assert(wi->type == WWT_HSCROLLBAR); |
|
73 w->flags4 |= WF_HSCROLL; |
|
74 mi = wi->left; |
|
75 ma = wi->right; |
|
76 pos = x; |
|
77 sb = &w->hscroll; |
|
78 } |
64 } |
79 } |
65 |
|
66 if (pos <= mi+9) { |
80 if (pos <= mi+9) { |
67 // Pressing the upper button? |
81 // Pressing the upper button? |
68 if (!_demo_mode) { |
82 if (!_demo_mode) { |
69 w->flags4 |= WF_SCROLL_UP; |
83 w->flags4 |= WF_SCROLL_UP; |
70 if (_scroller_click_timeout == 0) { |
84 if (_scroller_click_timeout == 0) { |
256 case WWT_SCROLLBAR: { |
270 case WWT_SCROLLBAR: { |
257 Point pt; |
271 Point pt; |
258 int c1,c2; |
272 int c1,c2; |
259 |
273 |
260 // draw up/down buttons |
274 // draw up/down buttons |
261 DrawFrameRect(r.left, r.top, r.right, r.top+9, wi->color, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == WF_SCROLL_UP ? 0x20 : 0); |
275 DrawFrameRect(r.left, r.top, r.right, r.top+9, wi->color, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP ? 0x20 : 0); |
262 DrawFrameRect(r.left, r.bottom-9, r.right, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == WF_SCROLL_DOWN ? 0x20 : 0); |
276 DrawFrameRect(r.left, r.bottom-9, r.right, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN ? 0x20 : 0); |
263 |
277 |
264 // draw icons in up/down buttons |
278 // draw icons in up/down buttons |
265 DoDrawString("\xA0", r.left+2, r.top, 0x10); |
279 DoDrawString("\xA0", r.left+2, r.top, 0x10); |
266 DoDrawString("\xAA", r.left+2, r.bottom-9, 0x10); |
280 DoDrawString("\xAA", r.left+2, r.bottom-9, 0x10); |
267 |
281 |
277 GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2); |
291 GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2); |
278 GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1); |
292 GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1); |
279 GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2); |
293 GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2); |
280 |
294 |
281 pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom); |
295 pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom); |
282 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == WF_SCROLL_MIDDLE ? 0x20 : 0); |
296 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? 0x20 : 0); |
|
297 break; |
|
298 } |
|
299 case WWT_SCROLL2BAR: { |
|
300 Point pt; |
|
301 int c1,c2; |
|
302 |
|
303 // draw up/down buttons |
|
304 DrawFrameRect(r.left, r.top, r.right, r.top+9, wi->color, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2) ? 0x20 : 0); |
|
305 DrawFrameRect(r.left, r.bottom-9, r.right, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2) ? 0x20 : 0); |
|
306 |
|
307 // draw icons in up/down buttons |
|
308 DoDrawString("\xA0", r.left+2, r.top, 0x10); |
|
309 DoDrawString("\xAA", r.left+2, r.bottom-9, 0x10); |
|
310 |
|
311 c1 = _color_list[wi->color&0xF].window_color_1a; |
|
312 c2 = _color_list[wi->color&0xF].window_color_2; |
|
313 |
|
314 // draw "shaded" background |
|
315 GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2); |
|
316 GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | 0x8000); |
|
317 |
|
318 // draw shaded lines |
|
319 GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1); |
|
320 GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2); |
|
321 GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1); |
|
322 GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2); |
|
323 |
|
324 pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom); |
|
325 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? 0x20 : 0); |
283 break; |
326 break; |
284 } |
327 } |
285 |
328 |
286 // horizontal scrollbar |
329 // horizontal scrollbar |
287 case WWT_HSCROLLBAR: { |
330 case WWT_HSCROLLBAR: { |
419 void DropdownMenuWndProc(Window *w, WindowEvent *e) |
463 void DropdownMenuWndProc(Window *w, WindowEvent *e) |
420 { |
464 { |
421 int item; |
465 int item; |
422 |
466 |
423 switch(e->event) { |
467 switch(e->event) { |
424 case WE_PAINT: { |
468 case WE_PAINT: { |
425 int x,y,i,sel; |
469 int x,y,i,sel; |
426 uint32 dis; |
470 uint32 dis; |
427 |
471 bool hidden; |
428 DrawWindowWidgets(w); |
472 |
429 |
473 DrawWindowWidgets(w); |
430 x = 1; |
474 |
431 y = 2; |
475 x = 1; |
432 sel = _dropdown_selindex; |
476 y = 2; |
433 dis = _dropdown_disabled; |
477 sel = _dropdown_selindex; |
434 |
478 dis = _dropdown_disabled; |
435 for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) { |
479 hidden = _dropdown_hide_disabled; |
436 if (_dropdown_items[i] != 0) { |
480 |
437 if (sel == 0) { |
481 |
438 GfxFillRect(x+1, y, x+w->width-4, y + 9, 0); |
482 for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) { |
|
483 if (!(hidden) | !(dis & 1)) { |
|
484 if (_dropdown_items[i] != 0) { |
|
485 if (sel == 0) { |
|
486 GfxFillRect(x+1, y, x+w->width-4, y + 9, 0); |
|
487 } |
|
488 DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16); |
|
489 |
|
490 if (dis & 1) { |
|
491 GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 + |
|
492 _color_list[_dropdown_menu_widgets[0].color].window_color_bga); |
|
493 } |
|
494 } else { |
|
495 int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a; |
|
496 int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2; |
|
497 GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1); |
|
498 GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2); |
|
499 } |
|
500 y += 10; |
|
501 sel--; |
439 } |
502 } |
440 DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16); |
503 dis>>=1; |
441 |
504 } |
442 if (dis & 1) { |
505 } break; |
443 GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 + |
506 |
444 _color_list[_dropdown_menu_widgets[0].color].window_color_bga); |
507 case WE_CLICK: { |
|
508 item = GetDropdownItem(w); |
|
509 if (item >= 0) { |
|
510 _dropdown_var1 = 4; |
|
511 _dropdown_selindex = item; |
|
512 SetWindowDirty(w); |
|
513 } |
|
514 } break; |
|
515 |
|
516 case WE_MOUSELOOP: { |
|
517 Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum); |
|
518 if (w2 == NULL) { |
|
519 DeleteWindow(w); |
|
520 return; |
|
521 } |
|
522 |
|
523 if (_dropdown_var1 != 0 && --_dropdown_var1 == 0) { |
|
524 WindowEvent e; |
|
525 e.event = WE_DROPDOWN_SELECT; |
|
526 e.dropdown.button = _dropdown_button; |
|
527 e.dropdown.index = _dropdown_selindex; |
|
528 w2->wndproc(w2, &e); |
|
529 DeleteWindow(w); |
|
530 return; |
|
531 } |
|
532 |
|
533 if (_dropdown_var2 != 0) { |
|
534 item = GetDropdownItem(w); |
|
535 |
|
536 if (!_left_button_clicked) { |
|
537 _dropdown_var2 = 0; |
|
538 if (item < 0) |
|
539 return; |
|
540 _dropdown_var1 = 2; |
|
541 } else { |
|
542 if (item < 0) |
|
543 return; |
445 } |
544 } |
446 } else { |
545 |
447 int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a; |
546 _dropdown_selindex = item; |
448 int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2; |
547 SetWindowDirty(w); |
449 GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1); |
548 } |
450 GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2); |
549 } break; |
451 } |
550 |
452 y += 10; |
551 case WE_DESTROY: { |
453 sel--; |
552 Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum); |
454 dis>>=1; |
553 if (w2 != NULL) { |
455 } |
554 CLRBIT(w2->click_state, _dropdown_button); |
456 } break; |
555 InvalidateWidget(w2, _dropdown_button); |
457 |
556 } |
458 case WE_CLICK: { |
557 } break; |
459 item = GetDropdownItem(w); |
|
460 if (item >= 0) { |
|
461 _dropdown_var1 = 4; |
|
462 _dropdown_selindex = item; |
|
463 SetWindowDirty(w); |
|
464 } |
|
465 } break; |
|
466 |
|
467 case WE_MOUSELOOP: { |
|
468 Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum); |
|
469 if (w2 == NULL) { |
|
470 DeleteWindow(w); |
|
471 return; |
|
472 } |
|
473 |
|
474 if (_dropdown_var1 != 0 && --_dropdown_var1 == 0) { |
|
475 WindowEvent e; |
|
476 e.event = WE_DROPDOWN_SELECT; |
|
477 e.dropdown.button = _dropdown_button; |
|
478 e.dropdown.index = _dropdown_selindex; |
|
479 w2->wndproc(w2, &e); |
|
480 DeleteWindow(w); |
|
481 return; |
|
482 } |
|
483 |
|
484 if (_dropdown_var2 != 0) { |
|
485 item = GetDropdownItem(w); |
|
486 |
|
487 if (!_left_button_clicked) { |
|
488 _dropdown_var2 = 0; |
|
489 if (item < 0) |
|
490 return; |
|
491 _dropdown_var1 = 2; |
|
492 } else { |
|
493 if (item < 0) |
|
494 return; |
|
495 } |
|
496 |
|
497 _dropdown_selindex = item; |
|
498 SetWindowDirty(w); |
|
499 } |
|
500 } break; |
|
501 |
|
502 case WE_DESTROY: { |
|
503 Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum); |
|
504 if (w2 != NULL) { |
|
505 CLRBIT(w2->click_state, _dropdown_button); |
|
506 InvalidateWidget(w2, _dropdown_button); |
|
507 } |
|
508 } break; |
|
509 } |
558 } |
510 } |
559 } |
511 |
560 |
512 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask) |
561 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, bool remove_filtered_strings) |
513 { |
562 { |
514 WindowNumber num; |
563 WindowNumber num; |
515 WindowClass cls; |
564 WindowClass cls; |
516 int i,t1,t2; |
565 int i,t1,t2; |
517 const Widget *wi; |
566 const Widget *wi; |
518 Window *w2; |
567 Window *w2; |
519 uint32 old_click_state = w->click_state; |
568 uint32 old_click_state = w->click_state; |
520 |
569 |
521 _dropdown_disabled = disabled_mask; |
570 _dropdown_disabled = disabled_mask; |
|
571 _dropdown_hide_disabled = remove_filtered_strings; |
522 |
572 |
523 cls = w->window_class; |
573 cls = w->window_class; |
524 num = w->window_number; |
574 num = w->window_number; |
525 DeleteWindowById(WC_DROPDOWN_MENU, 0); |
575 DeleteWindowById(WC_DROPDOWN_MENU, 0); |
526 w = FindWindowById(cls, num); |
576 w = FindWindowById(cls, num); |