2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Point pt;
|
|
|
|
int height, count, pos, cap;
|
|
|
|
|
|
|
|
top += 10;
|
|
|
|
bottom -= 9;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
height = (bottom - top);
|
|
|
|
|
|
|
|
pos = sb->pos;
|
|
|
|
count = sb->count;
|
|
|
|
cap = sb->cap;
|
|
|
|
|
2005-07-08 22:25:24 +00:00
|
|
|
if (count != 0) top += height * pos / count;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (cap > count) cap = count;
|
|
|
|
if (count != 0)
|
|
|
|
bottom -= (count - pos - cap) * height / count;
|
|
|
|
|
|
|
|
pt.x = top;
|
|
|
|
pt.y = bottom - 1;
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* Special handling for the scrollbar widget type.
|
|
|
|
* Handles the special scrolling buttons and other
|
|
|
|
* scrolling.
|
|
|
|
* Parameters:
|
|
|
|
* w - Window.
|
|
|
|
* wi - Pointer to the scrollbar widget.
|
|
|
|
* x - The X coordinate of the mouse click.
|
|
|
|
* y - The Y coordinate of the mouse click.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y)
|
|
|
|
{
|
|
|
|
int mi, ma, pos;
|
|
|
|
Scrollbar *sb;
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
switch (wi->type) {
|
|
|
|
case WWT_SCROLLBAR: {
|
|
|
|
// vertical scroller
|
|
|
|
w->flags4 &= ~WF_HSCROLL;
|
|
|
|
w->flags4 &= ~WF_SCROLL2;
|
|
|
|
mi = wi->top;
|
|
|
|
ma = wi->bottom;
|
|
|
|
pos = y;
|
|
|
|
sb = &w->vscroll;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WWT_SCROLL2BAR: {
|
|
|
|
// 2nd vertical scroller
|
|
|
|
w->flags4 &= ~WF_HSCROLL;
|
|
|
|
w->flags4 |= WF_SCROLL2;
|
|
|
|
mi = wi->top;
|
|
|
|
ma = wi->bottom;
|
|
|
|
pos = y;
|
|
|
|
sb = &w->vscroll2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WWT_HSCROLLBAR: {
|
|
|
|
// horizontal scroller
|
2005-01-03 19:45:18 +00:00
|
|
|
w->flags4 &= ~WF_SCROLL2;
|
2005-01-02 17:23:04 +00:00
|
|
|
w->flags4 |= WF_HSCROLL;
|
|
|
|
mi = wi->left;
|
|
|
|
ma = wi->right;
|
|
|
|
pos = x;
|
|
|
|
sb = &w->hscroll;
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
2005-01-02 22:28:56 +00:00
|
|
|
default: return; //this should never happen
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
if (pos <= mi+9) {
|
|
|
|
// Pressing the upper button?
|
2005-11-04 14:57:53 +00:00
|
|
|
w->flags4 |= WF_SCROLL_UP;
|
|
|
|
if (_scroller_click_timeout == 0) {
|
|
|
|
_scroller_click_timeout = 6;
|
|
|
|
if (sb->pos != 0) sb->pos--;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-11-04 14:57:53 +00:00
|
|
|
_left_button_clicked = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else if (pos >= ma-10) {
|
|
|
|
// Pressing the lower button?
|
2005-11-04 14:57:53 +00:00
|
|
|
w->flags4 |= WF_SCROLL_DOWN;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-11-04 14:57:53 +00:00
|
|
|
if (_scroller_click_timeout == 0) {
|
|
|
|
_scroller_click_timeout = 6;
|
|
|
|
if ((byte)(sb->pos + sb->cap) < sb->count)
|
|
|
|
sb->pos++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-11-04 14:57:53 +00:00
|
|
|
_left_button_clicked = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2004-09-10 19:02:27 +00:00
|
|
|
//
|
2004-08-09 17:04:08 +00:00
|
|
|
Point pt = HandleScrollbarHittest(sb, mi, ma);
|
|
|
|
|
|
|
|
if (pos < pt.x) {
|
|
|
|
sb->pos = max(sb->pos - sb->cap, 0);
|
|
|
|
} else if (pos > pt.y) {
|
|
|
|
sb->pos = min(
|
2004-09-10 19:02:27 +00:00
|
|
|
sb->pos + sb->cap,
|
2004-08-09 17:04:08 +00:00
|
|
|
max(sb->count - sb->cap, 0)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
_scrollbar_start_pos = pt.x - mi - 9;
|
|
|
|
_scrollbar_size = ma - mi - 23;
|
|
|
|
w->flags4 |= WF_SCROLL_MIDDLE;
|
|
|
|
_scrolling_scrollbar = true;
|
|
|
|
_cursorpos_drag_start = _cursor.pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
|
2005-07-08 00:14:19 +00:00
|
|
|
/** Returns the index for the widget located at the given position
|
|
|
|
* relative to the window. It includes all widget-corner pixels as well.
|
|
|
|
* @param *w Window to look inside
|
|
|
|
* @param x,y Window client coordinates
|
|
|
|
* @return A widget index, or -1 if no widget was found.
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-09-18 20:56:44 +00:00
|
|
|
int GetWidgetFromPos(const Window *w, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const Widget *wi;
|
|
|
|
int index, found_index = -1;
|
|
|
|
|
|
|
|
// Go through the widgets and check if we find the widget that the coordinate is
|
|
|
|
// inside.
|
2005-07-08 00:14:19 +00:00
|
|
|
for (index = 0,wi = w->widget; wi->type != WWT_LAST; index++, wi++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME)
|
|
|
|
continue;
|
|
|
|
|
2005-07-08 00:14:19 +00:00
|
|
|
if (x >= wi->left && x <= wi->right && y >= wi->top && y <= wi->bottom &&
|
|
|
|
!HASBIT(w->hidden_state,index)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
found_index = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawWindowWidgets(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const Widget *wi;
|
2005-10-22 06:39:32 +00:00
|
|
|
const DrawPixelInfo* dpi = _cur_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
Rect r;
|
|
|
|
uint32 cur_click, cur_disabled, cur_hidden;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
wi = w->widget;
|
|
|
|
|
|
|
|
cur_click = w->click_state;
|
|
|
|
cur_disabled = w->disabled_state;
|
|
|
|
cur_hidden = w->hidden_state;
|
|
|
|
|
|
|
|
do {
|
2005-04-07 00:59:54 +00:00
|
|
|
bool clicked = (cur_click & 1);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (dpi->left > (r.right=/*w->left + */wi->right) ||
|
|
|
|
dpi->left + dpi->width <= (r.left=wi->left/* + w->left*/) ||
|
|
|
|
dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
|
|
|
|
dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
|
|
|
|
(cur_hidden&1))
|
|
|
|
continue;
|
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
switch (wi->type & WWT_MASK) {
|
|
|
|
case WWT_PANEL: /* WWT_IMGBTN */
|
2004-08-09 17:04:08 +00:00
|
|
|
case WWT_PANEL_2: {
|
|
|
|
int img;
|
|
|
|
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
|
|
|
|
if ((img = wi->unkA) != 0) { // has an image
|
|
|
|
if ((wi->type & WWT_MASK) == WWT_PANEL_2 && clicked) img++; // show diff image when clicked
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(img, r.left + 1 + clicked, r.top + 1 + clicked);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
goto draw_default;
|
|
|
|
}
|
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
case WWT_CLOSEBOX: /* WWT_TEXTBTN */
|
2004-08-09 17:04:08 +00:00
|
|
|
case WWT_4: {
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case WWT_5: {
|
|
|
|
StringID str = wi->unkA;
|
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
if ((wi->type&WWT_MASK) == WWT_4 && clicked) str++;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, 0);
|
|
|
|
//DrawStringCentered((r.left + r.right+1)>>1, ((r.top+r.bottom + 1)>>1) - 5, str, 0);
|
2005-07-15 15:09:52 +00:00
|
|
|
goto draw_default;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_6: {
|
|
|
|
StringID str;
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if ((str = wi->unkA) != 0) {
|
|
|
|
DrawString(r.left+2, r.top+1, str, 0);
|
|
|
|
}
|
|
|
|
goto draw_default;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_MATRIX: {
|
2004-09-10 19:02:27 +00:00
|
|
|
int c, d, ctr;
|
2004-08-09 17:04:08 +00:00
|
|
|
int x, amt1, amt2;
|
|
|
|
int color;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
c = (wi->unkA&0xFF);
|
|
|
|
amt1 = (wi->right - wi->left + 1) / c;
|
|
|
|
|
|
|
|
d = (wi->unkA >> 8);
|
|
|
|
amt2 = (wi->bottom - wi->top + 1) / d;
|
|
|
|
|
|
|
|
color = _color_list[wi->color&0xF].window_color_bgb;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
x = r.left;
|
|
|
|
for(ctr=c; --ctr; ) {
|
|
|
|
x += amt1;
|
|
|
|
GfxFillRect(x, r.top+1, x, r.bottom-1, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
x = r.top;
|
|
|
|
for(ctr=d; --ctr; ) {
|
|
|
|
x += amt2;
|
|
|
|
GfxFillRect(r.left+1, x, r.right-1, x, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
color = _color_list[wi->color&0xF].window_color_1b;
|
|
|
|
|
|
|
|
x = r.left-1;
|
|
|
|
for(ctr=c; --ctr; ) {
|
|
|
|
x += amt1;
|
|
|
|
GfxFillRect(x, r.top+1, x, r.bottom-1, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
x = r.top-1;
|
|
|
|
for(ctr=d; --ctr; ) {
|
|
|
|
x += amt2;
|
|
|
|
GfxFillRect(r.left+1, x, r.right-1, x, color);
|
|
|
|
}
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
goto draw_default;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vertical scrollbar
|
|
|
|
case WWT_SCROLLBAR: {
|
|
|
|
Point pt;
|
|
|
|
int c1,c2;
|
|
|
|
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// draw up/down buttons
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!(((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
c1 = _color_list[wi->color&0xF].window_color_1a;
|
|
|
|
c2 = _color_list[wi->color&0xF].window_color_2;
|
|
|
|
|
|
|
|
// draw "shaded" background
|
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw shaded lines
|
|
|
|
GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
|
|
|
|
GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : 0);
|
2005-01-02 17:23:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WWT_SCROLL2BAR: {
|
|
|
|
Point pt;
|
|
|
|
int c1,c2;
|
|
|
|
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
// draw up/down buttons
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-09-10 07:38:03 +00:00
|
|
|
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
c1 = _color_list[wi->color&0xF].window_color_1a;
|
|
|
|
c2 = _color_list[wi->color&0xF].window_color_2;
|
|
|
|
|
|
|
|
// draw "shaded" background
|
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
|
2005-01-02 17:23:04 +00:00
|
|
|
|
|
|
|
// draw shaded lines
|
|
|
|
GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
|
|
|
|
GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
|
|
|
|
GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
|
|
|
|
|
|
|
|
pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
|
2005-06-15 17:27:14 +00:00
|
|
|
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) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// horizontal scrollbar
|
|
|
|
case WWT_HSCROLLBAR: {
|
|
|
|
Point pt;
|
|
|
|
int c1,c2;
|
|
|
|
|
2005-01-04 21:45:38 +00:00
|
|
|
assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
|
2005-01-04 21:28:09 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(SPR_ARROW_LEFT, r.left + 1 + clicked, r.top + 1 + clicked);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.right-9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(SPR_ARROW_RIGHT, r.right - 8 + clicked, r.top + 1 + clicked);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
c1 = _color_list[wi->color&0xF].window_color_1a;
|
|
|
|
c2 = _color_list[wi->color&0xF].window_color_2;
|
|
|
|
|
|
|
|
// draw "shaded" background
|
|
|
|
GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2);
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c1 | PALETTE_MODIFIER_GREYOUT);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// draw shaded lines
|
|
|
|
GfxFillRect(r.left+10, r.top+2, r.right-10, r.top+2, c1);
|
|
|
|
GfxFillRect(r.left+10, r.top+3, r.right-10, r.top+3, c2);
|
|
|
|
GfxFillRect(r.left+10, r.top+7, r.right-10, r.top+7, c1);
|
|
|
|
GfxFillRect(r.left+10, r.top+8, r.right-10, r.top+8, c2);
|
|
|
|
|
|
|
|
// draw actual scrollbar
|
|
|
|
pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_FRAME: {
|
|
|
|
int c1,c2;
|
2005-01-03 17:55:25 +00:00
|
|
|
int x2 = r.left; // by default the left side is the left side of the widget
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (wi->unkA != 0) {
|
|
|
|
x2 = DrawString(r.left+6, r.top, wi->unkA, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
c1 = _color_list[wi->color].window_color_1a;
|
|
|
|
c2 = _color_list[wi->color].window_color_2;
|
|
|
|
|
|
|
|
//Line from upper left corner to start of text
|
|
|
|
GfxFillRect(r.left, r.top+4, r.left+4,r.top+4, c1);
|
|
|
|
GfxFillRect(r.left+1, r.top+5, r.left+4,r.top+5, c2);
|
|
|
|
|
|
|
|
// Line from end of text to upper right corner
|
|
|
|
GfxFillRect(x2, r.top+4, r.right-1,r.top+4,c1);
|
|
|
|
GfxFillRect(x2, r.top+5, r.right-2,r.top+5,c2);
|
|
|
|
|
|
|
|
// Line from upper left corner to bottom left corner
|
|
|
|
GfxFillRect(r.left, r.top+5, r.left, r.bottom-1, c1);
|
|
|
|
GfxFillRect(r.left+1, r.top+6, r.left+1, r.bottom-2, c2);
|
|
|
|
|
|
|
|
//Line from upper right corner to bottom right corner
|
|
|
|
GfxFillRect(r.right-1, r.top+5, r.right-1, r.bottom-2, c1);
|
|
|
|
GfxFillRect(r.right, r.top+4, r.right, r.bottom-1, c2);
|
|
|
|
|
|
|
|
GfxFillRect(r.left+1, r.bottom-1, r.right-1, r.bottom-1, c1);
|
|
|
|
GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
|
|
|
|
|
2005-07-15 15:09:52 +00:00
|
|
|
goto draw_default;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 23:33:04 +00:00
|
|
|
case WWT_STICKYBOX: {
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, r.left + 2 + clicked, r.top + 3 + clicked);
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WWT_RESIZEBOX: {
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2005-04-07 00:59:54 +00:00
|
|
|
clicked = !!(w->flags4 & WF_SIZING);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
DrawSprite(SPR_WINDOW_RESIZE, r.left + 3 + clicked, r.top + 3 + clicked);
|
2004-12-15 23:33:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WWT_CAPTION: {
|
2005-01-04 21:28:09 +00:00
|
|
|
assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
|
|
|
|
DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->caption_color != 0xFF) {
|
|
|
|
GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _color_list[_player_colors[w->caption_color]].window_color_1b);
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->unkA, 0x84);
|
|
|
|
draw_default:;
|
|
|
|
if (cur_disabled & 1) {
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _color_list[wi->color&0xF].unk2 | PALETTE_MODIFIER_GREYOUT);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (cur_click>>=1, cur_disabled>>=1, cur_hidden >>= 1, (++wi)->type != WWT_LAST);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
|
|
|
//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
|
2005-06-15 17:27:14 +00:00
|
|
|
DrawFrameRect(0, 0, w->width-1, w->height-1, 0xF, FR_BORDERONLY);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
|
|
|
static uint _dropdown_item_count;
|
|
|
|
static const StringID *_dropdown_items;
|
|
|
|
static int _dropdown_selindex;
|
|
|
|
static byte _dropdown_button;
|
|
|
|
static WindowClass _dropdown_windowclass;
|
|
|
|
static WindowNumber _dropdown_windownum;
|
|
|
|
static byte _dropdown_var1;
|
|
|
|
static byte _dropdown_var2;
|
|
|
|
|
2005-01-04 13:45:58 +00:00
|
|
|
static const Widget _dropdown_menu_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-09-06 18:15:13 +00:00
|
|
|
};
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
static int GetDropdownItem(const Window *w)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
2005-09-23 07:44:03 +00:00
|
|
|
byte item, counter;
|
2004-09-06 18:15:13 +00:00
|
|
|
int y;
|
|
|
|
|
|
|
|
if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
|
|
|
|
return -1;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
y = _cursor.pos.y - w->top - 2;
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
return - 1;
|
|
|
|
|
|
|
|
item = y / 10;
|
2005-11-12 11:10:12 +00:00
|
|
|
if (item >= _dropdown_item_count || (HASBIT(w->disabled_state, item) && !HASBIT(w->hidden_state, item)) || _dropdown_items[item] == 0)
|
2004-09-06 18:15:13 +00:00
|
|
|
return - 1;
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
// Skip hidden items -- +1 for each hidden item before the clicked item.
|
|
|
|
for (counter = 0; item >= counter; ++counter)
|
2005-11-12 11:10:12 +00:00
|
|
|
if (HASBIT(w->hidden_state, counter)) item++;
|
2005-09-23 07:44:03 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void DropdownMenuWndProc(Window *w, WindowEvent *e)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
|
|
|
int item;
|
|
|
|
|
|
|
|
switch(e->event) {
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int x,y,i,sel;
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
x = 1;
|
|
|
|
y = 2;
|
|
|
|
sel = _dropdown_selindex;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) {
|
2005-11-12 11:10:12 +00:00
|
|
|
if (HASBIT(w->hidden_state, i)) {
|
2005-01-02 17:23:04 +00:00
|
|
|
sel--;
|
2005-01-26 11:23:54 +00:00
|
|
|
continue;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2005-01-26 11:23:54 +00:00
|
|
|
if (_dropdown_items[i] != 0) {
|
|
|
|
if (sel == 0) {
|
|
|
|
GfxFillRect(x+1, y, x+w->width-4, y + 9, 0);
|
|
|
|
}
|
|
|
|
DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
|
|
|
|
|
2005-11-12 11:10:12 +00:00
|
|
|
if (HASBIT(w->disabled_state, i)) {
|
2005-07-28 09:17:32 +00:00
|
|
|
GfxFillRect(x, y, x+w->width-3, y + 9, PALETTE_MODIFIER_GREYOUT |
|
2005-01-26 11:23:54 +00:00
|
|
|
_color_list[_dropdown_menu_widgets[0].color].window_color_bga);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a;
|
|
|
|
int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2;
|
|
|
|
GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1);
|
|
|
|
GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2);
|
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
sel--;
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_CLICK: {
|
|
|
|
item = GetDropdownItem(w);
|
|
|
|
if (item >= 0) {
|
|
|
|
_dropdown_var1 = 4;
|
|
|
|
_dropdown_selindex = item;
|
|
|
|
SetWindowDirty(w);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_MOUSELOOP: {
|
|
|
|
Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum);
|
|
|
|
if (w2 == NULL) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if (_dropdown_var1 != 0 && --_dropdown_var1 == 0) {
|
|
|
|
WindowEvent e;
|
|
|
|
e.event = WE_DROPDOWN_SELECT;
|
|
|
|
e.dropdown.button = _dropdown_button;
|
|
|
|
e.dropdown.index = _dropdown_selindex;
|
|
|
|
w2->wndproc(w2, &e);
|
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
if (_dropdown_var2 != 0) {
|
|
|
|
item = GetDropdownItem(w);
|
|
|
|
|
|
|
|
if (!_left_button_clicked) {
|
|
|
|
_dropdown_var2 = 0;
|
|
|
|
if (item < 0)
|
|
|
|
return;
|
|
|
|
_dropdown_var1 = 2;
|
|
|
|
} else {
|
|
|
|
if (item < 0)
|
|
|
|
return;
|
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
_dropdown_selindex = item;
|
|
|
|
SetWindowDirty(w);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
case WE_DESTROY: {
|
|
|
|
Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum);
|
|
|
|
if (w2 != NULL) {
|
|
|
|
CLRBIT(w2->click_state, _dropdown_button);
|
|
|
|
InvalidateWidget(w2, _dropdown_button);
|
|
|
|
}
|
|
|
|
} break;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask)
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
|
|
|
WindowNumber num;
|
|
|
|
WindowClass cls;
|
2005-01-03 19:45:18 +00:00
|
|
|
int i;
|
2004-09-06 18:15:13 +00:00
|
|
|
const Widget *wi;
|
|
|
|
Window *w2;
|
|
|
|
uint32 old_click_state = w->click_state;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
cls = w->window_class;
|
|
|
|
num = w->window_number;
|
|
|
|
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
|
|
|
w = FindWindowById(cls, num);
|
|
|
|
|
|
|
|
if (HASBIT(old_click_state, button))
|
|
|
|
return;
|
|
|
|
|
|
|
|
SETBIT(w->click_state, button);
|
|
|
|
|
|
|
|
InvalidateWidget(w, button);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
for(i=0;strings[i] != INVALID_STRING_ID;i++);
|
|
|
|
if (i == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_dropdown_items = strings;
|
|
|
|
_dropdown_selindex = selected;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
_dropdown_windowclass = w->window_class;
|
|
|
|
_dropdown_windownum = w->window_number;
|
|
|
|
_dropdown_button = button;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
_dropdown_var1 = 0;
|
|
|
|
_dropdown_var2 = 1;
|
|
|
|
|
|
|
|
wi = &w->widget[button];
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
if (hidden_mask != 0) {
|
2005-01-02 17:23:04 +00:00
|
|
|
int j;
|
|
|
|
for(j=0; _dropdown_items[j] != INVALID_STRING_ID; j++) {
|
2005-09-23 07:44:03 +00:00
|
|
|
if (HASBIT(hidden_mask, j)) {
|
2005-01-02 17:23:04 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-23 07:44:03 +00:00
|
|
|
_dropdown_item_count = i;
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
w2 = AllocateWindow(
|
|
|
|
w->left + wi[-1].left + 1,
|
|
|
|
w->top + wi->bottom + 2,
|
2005-01-03 19:45:18 +00:00
|
|
|
wi->right - wi[-1].left + 1,
|
|
|
|
i * 10 + 4,
|
2004-09-06 18:15:13 +00:00
|
|
|
DropdownMenuWndProc,
|
|
|
|
0x3F,
|
|
|
|
_dropdown_menu_widgets);
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
w2->widget[0].color = wi->color;
|
|
|
|
w2->widget[0].right = wi->right - wi[-1].left;
|
|
|
|
w2->widget[0].bottom = i * 10 + 3;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
|
|
|
w2->flags4 &= ~WF_WHITE_BORDER_MASK;
|
2005-11-12 11:10:12 +00:00
|
|
|
|
|
|
|
w2->disabled_state = disabled_mask;
|
|
|
|
w2->hidden_state = hidden_mask;
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|