widget.c
changeset 193 0a7025304867
parent 176 84990c4b9212
child 507 04b5403aaf6b
equal deleted inserted replaced
192:614bba52258d 193:0a7025304867
     9 	Point pt;
     9 	Point pt;
    10 	int height, count, pos, cap;
    10 	int height, count, pos, cap;
    11 
    11 
    12 	top += 10;
    12 	top += 10;
    13 	bottom -= 9;
    13 	bottom -= 9;
    14 	
    14 
    15 	height = (bottom - top);
    15 	height = (bottom - top);
    16 
    16 
    17 	pos = sb->pos;
    17 	pos = sb->pos;
    18 	count = sb->count;
    18 	count = sb->count;
    19 	cap = sb->cap;
    19 	cap = sb->cap;
    20 
    20 
    21 	if (count != 0)	top += height * pos / count;
    21 	if (count != 0)	top += height * pos / count;
    22 	
    22 
    23 	if (cap > count) cap = count;
    23 	if (cap > count) cap = count;
    24 	if (count != 0)
    24 	if (count != 0)
    25 		bottom -= (count - pos - cap) * height / count;
    25 		bottom -= (count - pos - cap) * height / count;
    26 
    26 
    27 	pt.x = top;
    27 	pt.x = top;
    59 		mi = wi->left;
    59 		mi = wi->left;
    60 		ma = wi->right;
    60 		ma = wi->right;
    61 		pos = x;
    61 		pos = x;
    62 		sb = &w->hscroll;
    62 		sb = &w->hscroll;
    63 	}
    63 	}
    64 	
    64 
    65 	if (pos <= mi+9) {
    65 	if (pos <= mi+9) {
    66 		// Pressing the upper button?
    66 		// Pressing the upper button?
    67 		if (!_demo_mode) {
    67 		if (!_demo_mode) {
    68 			w->flags4 |= WF_SCROLL_UP;
    68 			w->flags4 |= WF_SCROLL_UP;
    69 			if (_scroller_click_timeout == 0) {
    69 			if (_scroller_click_timeout == 0) {
    74 		}
    74 		}
    75 	} else if (pos >= ma-10) {
    75 	} else if (pos >= ma-10) {
    76 		// Pressing the lower button?
    76 		// Pressing the lower button?
    77 		if (!_demo_mode) {
    77 		if (!_demo_mode) {
    78 			w->flags4 |= WF_SCROLL_DOWN;
    78 			w->flags4 |= WF_SCROLL_DOWN;
    79 			
    79 
    80 			if (_scroller_click_timeout == 0) {
    80 			if (_scroller_click_timeout == 0) {
    81 				_scroller_click_timeout = 6;
    81 				_scroller_click_timeout = 6;
    82 				if ((byte)(sb->pos + sb->cap) < sb->count)
    82 				if ((byte)(sb->pos + sb->cap) < sb->count)
    83 					sb->pos++;
    83 					sb->pos++;
    84 			}
    84 			}
    85 			_left_button_clicked = false;
    85 			_left_button_clicked = false;
    86 		}
    86 		}
    87 	} else {
    87 	} else {
    88 		// 
    88 		//
    89 		Point pt = HandleScrollbarHittest(sb, mi, ma);
    89 		Point pt = HandleScrollbarHittest(sb, mi, ma);
    90 
    90 
    91 		if (pos < pt.x) {
    91 		if (pos < pt.x) {
    92 			sb->pos = max(sb->pos - sb->cap, 0);
    92 			sb->pos = max(sb->pos - sb->cap, 0);
    93 		} else if (pos > pt.y) {
    93 		} else if (pos > pt.y) {
    94 			sb->pos = min(
    94 			sb->pos = min(
    95 				sb->pos + sb->cap, 
    95 				sb->pos + sb->cap,
    96 				max(sb->count - sb->cap, 0)
    96 				max(sb->count - sb->cap, 0)
    97 			);
    97 			);
    98 		} else {
    98 		} else {
    99 			_scrollbar_start_pos = pt.x - mi - 9;
    99 			_scrollbar_start_pos = pt.x - mi - 9;
   100 			_scrollbar_size = ma - mi - 23;
   100 			_scrollbar_size = ma - mi - 23;
   145 	const Widget *wi;
   145 	const Widget *wi;
   146 	DrawPixelInfo *dpi = _cur_dpi;
   146 	DrawPixelInfo *dpi = _cur_dpi;
   147 	Rect r;
   147 	Rect r;
   148 	uint32 dparam_backup[10];
   148 	uint32 dparam_backup[10];
   149 	uint32 cur_click, cur_disabled, cur_hidden;
   149 	uint32 cur_click, cur_disabled, cur_hidden;
   150 	
   150 
   151 	if (w->desc_flags & WDF_RESTORE_DPARAM)	COPY_OUT_DPARAM(dparam_backup, 0, lengthof(dparam_backup));
   151 	if (w->desc_flags & WDF_RESTORE_DPARAM)	COPY_OUT_DPARAM(dparam_backup, 0, lengthof(dparam_backup));
   152 	
   152 
   153 	wi = w->widget;
   153 	wi = w->widget;
   154 
   154 
   155 	cur_click = w->click_state;
   155 	cur_click = w->click_state;
   156 	cur_disabled = w->disabled_state;
   156 	cur_disabled = w->disabled_state;
   157 	cur_hidden = w->hidden_state;
   157 	cur_hidden = w->hidden_state;
   188 
   188 
   189 		case WWT_5: {
   189 		case WWT_5: {
   190 			StringID str = wi->unkA;
   190 			StringID str = wi->unkA;
   191 
   191 
   192 			if ((wi->type&WWT_MASK) == WWT_4 && (cur_click&1)) str++;
   192 			if ((wi->type&WWT_MASK) == WWT_4 && (cur_click&1)) str++;
   193 			
   193 
   194 			DrawStringCentered((r.left + r.right+1)>>1, ((r.top+r.bottom + 1)>>1) - 5, str, 0);
   194 			DrawStringCentered((r.left + r.right+1)>>1, ((r.top+r.bottom + 1)>>1) - 5, str, 0);
   195 			goto restore_dparam;
   195 			goto restore_dparam;
   196 		}
   196 		}
   197 
   197 
   198 		case WWT_6: {
   198 		case WWT_6: {
   205 			}
   205 			}
   206 			goto draw_default;
   206 			goto draw_default;
   207 		}
   207 		}
   208 
   208 
   209 		case WWT_MATRIX: {
   209 		case WWT_MATRIX: {
   210 			int c, d, ctr;	
   210 			int c, d, ctr;
   211 			int x, amt1, amt2;
   211 			int x, amt1, amt2;
   212 			int color;
   212 			int color;
   213 		
   213 
   214 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color,
   214 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color,
   215 					(cur_click & 1) ? 0x20 : 0);
   215 					(cur_click & 1) ? 0x20 : 0);
   216 			
   216 
   217 			c = (wi->unkA&0xFF);
   217 			c = (wi->unkA&0xFF);
   218 			amt1 = (wi->right - wi->left + 1) / c;
   218 			amt1 = (wi->right - wi->left + 1) / c;
   219 
   219 
   220 			d = (wi->unkA >> 8);
   220 			d = (wi->unkA >> 8);
   221 			amt2 = (wi->bottom - wi->top + 1) / d;
   221 			amt2 = (wi->bottom - wi->top + 1) / d;
   222 
   222 
   223 			color = _color_list[wi->color&0xF].window_color_bgb;
   223 			color = _color_list[wi->color&0xF].window_color_bgb;
   224 			
   224 
   225 			x = r.left;
   225 			x = r.left;
   226 			for(ctr=c; --ctr; ) {
   226 			for(ctr=c; --ctr; ) {
   227 				x += amt1;
   227 				x += amt1;
   228 				GfxFillRect(x, r.top+1, x, r.bottom-1, color);
   228 				GfxFillRect(x, r.top+1, x, r.bottom-1, color);
   229 			}
   229 			}
   246 			for(ctr=d; --ctr; ) {
   246 			for(ctr=d; --ctr; ) {
   247 				x += amt2;
   247 				x += amt2;
   248 				GfxFillRect(r.left+1, x, r.right-1, x, color);
   248 				GfxFillRect(r.left+1, x, r.right-1, x, color);
   249 			}
   249 			}
   250 
   250 
   251 			goto draw_default;			
   251 			goto draw_default;
   252 		}
   252 		}
   253 
   253 
   254 		// vertical scrollbar
   254 		// vertical scrollbar
   255 		case WWT_SCROLLBAR: {
   255 		case WWT_SCROLLBAR: {
   256 			Point pt;
   256 			Point pt;
   274 			// draw shaded lines
   274 			// draw shaded lines
   275 			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
   275 			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
   276 			GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
   276 			GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
   277 			GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
   277 			GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
   278 			GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
   278 			GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
   279 			
   279 
   280 			pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
   280 			pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
   281 			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == WF_SCROLL_MIDDLE ? 0x20 : 0);
   281 			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == WF_SCROLL_MIDDLE ? 0x20 : 0);
   282 			break;
   282 			break;
   283 		}
   283 		}
   284 
   284 
   348 		}
   348 		}
   349 
   349 
   350 		case WWT_CAPTION: {
   350 		case WWT_CAPTION: {
   351 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, 0x10);
   351 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, 0x10);
   352 			DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? 0x60 : 0x70);
   352 			DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? 0x60 : 0x70);
   353 			
   353 
   354 			if (w->caption_color != 0xFF) {
   354 			if (w->caption_color != 0xFF) {
   355 				GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _color_list[_player_colors[w->caption_color]].window_color_1b);
   355 				GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _color_list[_player_colors[w->caption_color]].window_color_1b);
   356 			}
   356 			}
   357 
   357 
   358 			DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->unkA, 0x84);
   358 			DrawStringCentered( (r.left+r.right+1)>>1, r.top+2, wi->unkA, 0x84);
   363 				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _color_list[wi->color&0xF].unk2 | 0x8000);
   363 				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _color_list[wi->color&0xF].unk2 | 0x8000);
   364 			}
   364 			}
   365 		}
   365 		}
   366 		}
   366 		}
   367 	} while (cur_click>>=1, cur_disabled>>=1, cur_hidden >>= 1, (++wi)->type != WWT_LAST);
   367 	} while (cur_click>>=1, cur_disabled>>=1, cur_hidden >>= 1, (++wi)->type != WWT_LAST);
   368 	
   368 
   369 
   369 
   370 	if (w->flags4 & WF_WHITE_BORDER_MASK) {
   370 	if (w->flags4 & WF_WHITE_BORDER_MASK) {
   371 		//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
   371 		//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
   372 		DrawFrameRect(0, 0, w->width-1, w->height-1, 0xF, 0x10);
   372 		DrawFrameRect(0, 0, w->width-1, w->height-1, 0xF, 0x10);
   373 	}
   373 	}
   394 	uint item;
   394 	uint item;
   395 	int y;
   395 	int y;
   396 
   396 
   397 	if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
   397 	if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
   398 		return -1;
   398 		return -1;
   399 	
   399 
   400 	y = _cursor.pos.y - w->top - 2;
   400 	y = _cursor.pos.y - w->top - 2;
   401 
   401 
   402 	if (y < 0)
   402 	if (y < 0)
   403 		return - 1;
   403 		return - 1;
   404 
   404 
   431 					GfxFillRect(x+1, y, x+w->width-4, y + 9, 0);
   431 					GfxFillRect(x+1, y, x+w->width-4, y + 9, 0);
   432 				}
   432 				}
   433 				DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
   433 				DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
   434 
   434 
   435 				if (dis & 1) {
   435 				if (dis & 1) {
   436 					GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 + 
   436 					GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 +
   437 						_color_list[_dropdown_menu_widgets[0].color].window_color_bga);
   437 						_color_list[_dropdown_menu_widgets[0].color].window_color_bga);
   438 				}
   438 				}
   439 			} else {
   439 			} else {
   440 				int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a;
   440 				int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a;
   441 				int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2;
   441 				int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2;
   489 
   489 
   490 			_dropdown_selindex = item;
   490 			_dropdown_selindex = item;
   491 			SetWindowDirty(w);
   491 			SetWindowDirty(w);
   492 		}
   492 		}
   493 	} break;
   493 	} break;
   494 		
   494 
   495 	case WE_DESTROY: {
   495 	case WE_DESTROY: {
   496 		Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum);
   496 		Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum);
   497 		if (w2 != NULL) {
   497 		if (w2 != NULL) {
   498 			CLRBIT(w2->click_state, _dropdown_button);
   498 			CLRBIT(w2->click_state, _dropdown_button);
   499 			InvalidateWidget(w2, _dropdown_button);
   499 			InvalidateWidget(w2, _dropdown_button);
   508 	WindowClass cls;
   508 	WindowClass cls;
   509 	int i,t1,t2;
   509 	int i,t1,t2;
   510 	const Widget *wi;
   510 	const Widget *wi;
   511 	Window *w2;
   511 	Window *w2;
   512 	uint32 old_click_state = w->click_state;
   512 	uint32 old_click_state = w->click_state;
   513 	
   513 
   514 	_dropdown_disabled = disabled_mask;
   514 	_dropdown_disabled = disabled_mask;
   515 
   515 
   516 	cls = w->window_class;
   516 	cls = w->window_class;
   517 	num = w->window_number;
   517 	num = w->window_number;
   518 	DeleteWindowById(WC_DROPDOWN_MENU, 0);
   518 	DeleteWindowById(WC_DROPDOWN_MENU, 0);
   522 		return;
   522 		return;
   523 
   523 
   524 	SETBIT(w->click_state, button);
   524 	SETBIT(w->click_state, button);
   525 
   525 
   526 	InvalidateWidget(w, button);
   526 	InvalidateWidget(w, button);
   527 	
   527 
   528 	for(i=0;strings[i] != INVALID_STRING_ID;i++);
   528 	for(i=0;strings[i] != INVALID_STRING_ID;i++);
   529 	if (i == 0)
   529 	if (i == 0)
   530 		return;
   530 		return;
   531 
   531 
   532 	_dropdown_items = strings;
   532 	_dropdown_items = strings;
   533 	_dropdown_item_count = i;
   533 	_dropdown_item_count = i;
   534 	_dropdown_selindex = selected;
   534 	_dropdown_selindex = selected;
   535 	
   535 
   536 	_dropdown_windowclass = w->window_class;
   536 	_dropdown_windowclass = w->window_class;
   537 	_dropdown_windownum = w->window_number;
   537 	_dropdown_windownum = w->window_number;
   538 	_dropdown_button = button;
   538 	_dropdown_button = button;
   539 	
   539 
   540 	_dropdown_var1 = 0;
   540 	_dropdown_var1 = 0;
   541 	_dropdown_var2 = 1;
   541 	_dropdown_var2 = 1;
   542 
   542 
   543 	wi = &w->widget[button];
   543 	wi = &w->widget[button];
   544 
   544 
   545 	_dropdown_menu_widgets[0].color = wi->color;
   545 	_dropdown_menu_widgets[0].color = wi->color;
   546 
   546 
   547 	w2 = AllocateWindow(
   547 	w2 = AllocateWindow(
   548 		w->left + wi[-1].left + 1,
   548 		w->left + wi[-1].left + 1,
   549 		w->top + wi->bottom + 2,
   549 		w->top + wi->bottom + 2,
   550 		(_dropdown_menu_widgets[0].right=t1=wi->right - wi[-1].left, t1 + 1), 
   550 		(_dropdown_menu_widgets[0].right=t1=wi->right - wi[-1].left, t1 + 1),
   551 		(_dropdown_menu_widgets[0].bottom=t2=i*10+3, t2+1), 
   551 		(_dropdown_menu_widgets[0].bottom=t2=i*10+3, t2+1),
   552 		DropdownMenuWndProc,
   552 		DropdownMenuWndProc,
   553 		0x3F,
   553 		0x3F,
   554 		_dropdown_menu_widgets);
   554 		_dropdown_menu_widgets);
   555 
   555 
   556 
   556