2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2006-10-06 21:10:14 +00:00
|
|
|
#include <stdarg.h>
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gfx.h"
|
2004-09-03 19:59:05 +00:00
|
|
|
#include "viewport.h"
|
2004-08-24 08:34:28 +00:00
|
|
|
#include "console.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-10-15 11:06:54 +00:00
|
|
|
#include "table/sprites.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#include "genworld.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
// delta between mouse cursor and upper left corner of dragged window
|
|
|
|
static Point _drag_delta;
|
|
|
|
|
2006-10-06 21:10:14 +00:00
|
|
|
void CDECL SetWindowWidgetsDisabledState(Window *w, bool disab_stat, int widgets, ...)
|
|
|
|
{
|
|
|
|
va_list wdg_list;
|
|
|
|
|
|
|
|
va_start(wdg_list, widgets);
|
|
|
|
|
|
|
|
while (widgets != WIDGET_LIST_END) {
|
2006-10-06 21:30:09 +00:00
|
|
|
SetWindowWidgetDisabledState(w, widgets, disab_stat);
|
2006-10-06 21:10:14 +00:00
|
|
|
widgets = va_arg(wdg_list, int);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(wdg_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets, ...)
|
|
|
|
{
|
|
|
|
va_list wdg_list;
|
|
|
|
|
|
|
|
va_start(wdg_list, widgets);
|
|
|
|
|
|
|
|
while (widgets != WIDGET_LIST_END) {
|
|
|
|
SetWindowWidgetHiddenState(w, widgets, hidden_stat);
|
|
|
|
widgets = va_arg(wdg_list, int);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(wdg_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...)
|
|
|
|
{
|
|
|
|
va_list wdg_list;
|
|
|
|
|
|
|
|
va_start(wdg_list, widgets);
|
|
|
|
|
|
|
|
while (widgets != WIDGET_LIST_END) {
|
|
|
|
SetWindowWidgetLoweredState(w, widgets, lowered_stat);
|
|
|
|
widgets = va_arg(wdg_list, int);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(wdg_list);
|
|
|
|
}
|
|
|
|
|
2006-10-03 20:16:20 +00:00
|
|
|
void RaiseWindowButtons(Window *w)
|
|
|
|
{
|
|
|
|
const Widget *wi = w->widget;
|
|
|
|
uint i = 0;
|
|
|
|
|
|
|
|
for (i = 0; wi->type != WWT_LAST; i++, wi++) {
|
|
|
|
if (IsWindowWidgetLowered(w, i)) {
|
|
|
|
RaiseWindowWidget(w, i);
|
|
|
|
InvalidateWidget(w, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void HandleButtonClick(Window *w, byte widget)
|
|
|
|
{
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, widget);
|
2004-08-09 17:04:08 +00:00
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
|
|
|
InvalidateWidget(w, widget);
|
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static Window *StartWindowDrag(Window *w);
|
|
|
|
static Window *StartWindowSizing(Window *w);
|
2006-01-05 12:40:50 +00:00
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DispatchLeftClickEvent(Window *w, int x, int y)
|
2005-11-04 14:01:44 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
WindowEvent e;
|
|
|
|
const Widget *wi;
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.click.pt.x = x;
|
|
|
|
e.we.click.pt.y = y;
|
2004-08-09 17:04:08 +00:00
|
|
|
e.event = WE_CLICK;
|
|
|
|
|
|
|
|
if (w->desc_flags & WDF_DEF_WIDGET) {
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.click.widget = GetWidgetFromPos(w, x, y);
|
|
|
|
if (e.we.click.widget < 0) return; /* exit if clicked outside of widgets */
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
wi = &w->widget[e.we.click.widget];
|
2004-09-12 21:49:38 +00:00
|
|
|
|
2004-09-12 14:12:33 +00:00
|
|
|
/* don't allow any interaction if the button has been disabled */
|
2006-10-06 01:33:27 +00:00
|
|
|
if (IsWidgetDisabled(wi)) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-24 14:15:17 +00:00
|
|
|
if (wi->type & WWB_MASK) {
|
2004-09-12 14:12:33 +00:00
|
|
|
/* special widget handling for buttons*/
|
2006-02-01 07:36:15 +00:00
|
|
|
switch (wi->type) {
|
2006-10-24 14:15:17 +00:00
|
|
|
case WWT_PANEL | WWB_PUSHBUTTON: /* WWT_PUSHBTN */
|
|
|
|
case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
|
|
|
|
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
|
|
|
|
HandleButtonClick(w, e.we.click.widget);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-02 17:23:04 +00:00
|
|
|
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
|
2006-09-23 02:39:24 +00:00
|
|
|
ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (w->desc_flags & WDF_STD_BTN) {
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e.we.click.widget == 0) { /* 'X' */
|
2005-01-03 19:45:18 +00:00
|
|
|
DeleteWindow(w);
|
2005-01-11 12:15:08 +00:00
|
|
|
return;
|
2005-01-23 13:09:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e.we.click.widget == 1) { /* 'Title bar' */
|
2005-01-23 13:42:26 +00:00
|
|
|
StartWindowDrag(w); // if not return then w = StartWindowDrag(w); to get correct pointer
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-23 13:42:26 +00:00
|
|
|
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
|
|
|
|
StartWindowSizing(w); // if not return then w = StartWindowSizing(w); to get correct pointer
|
|
|
|
return;
|
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
|
|
|
|
w->flags4 ^= WF_STICKY;
|
2006-09-23 02:39:24 +00:00
|
|
|
InvalidateWidget(w, e.we.click.widget);
|
2005-01-23 13:42:26 +00:00
|
|
|
return;
|
2004-12-15 23:33:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-16 12:30:52 +00:00
|
|
|
|
|
|
|
w->wndproc(w, &e);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DispatchRightClickEvent(Window *w, int x, int y)
|
2005-11-04 14:01:44 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
WindowEvent e;
|
|
|
|
|
|
|
|
/* default tooltips handler? */
|
|
|
|
if (w->desc_flags & WDF_STD_TOOLTIPS) {
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.click.widget = GetWidgetFromPos(w, x, y);
|
|
|
|
if (e.we.click.widget < 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
return; /* exit if clicked outside of widgets */
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
if (w->widget[e.we.click.widget].tooltips != 0) {
|
|
|
|
GuiShowTooltips(w->widget[e.we.click.widget].tooltips);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e.event = WE_RCLICK;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.click.pt.x = x;
|
|
|
|
e.we.click.pt.y = y;
|
2004-09-05 14:20:36 +00:00
|
|
|
w->wndproc(w, &e);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-08 00:14:19 +00:00
|
|
|
/** Dispatch the mousewheel-action to the window which will scroll any
|
|
|
|
* compatible scrollbars if the mouse is pointed over the bar or its contents
|
|
|
|
* @param *w Window
|
|
|
|
* @param widget the widget where the scrollwheel was used
|
|
|
|
* @param wheel scroll up or down
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-08 00:14:19 +00:00
|
|
|
const Widget *wi1, *wi2;
|
2005-01-11 00:24:27 +00:00
|
|
|
Scrollbar *sb;
|
|
|
|
|
2005-07-08 00:14:19 +00:00
|
|
|
if (widget < 0) return;
|
|
|
|
|
|
|
|
wi1 = &w->widget[widget];
|
|
|
|
wi2 = &w->widget[widget + 1];
|
|
|
|
|
2005-01-11 00:24:27 +00:00
|
|
|
/* The listbox can only scroll if scrolling was done on the scrollbar itself,
|
2005-01-15 08:58:31 +00:00
|
|
|
* or on the listbox (and the next item is (must be) the scrollbar)
|
2005-01-11 00:24:27 +00:00
|
|
|
* XXX - should be rewritten as a widget-dependent scroller but that's
|
|
|
|
* not happening until someone rewrites the whole widget-code */
|
2005-01-15 08:58:31 +00:00
|
|
|
if ((sb = &w->vscroll, wi1->type == WWT_SCROLLBAR) || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR) ||
|
2005-01-11 00:24:27 +00:00
|
|
|
(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
|
|
|
|
|
|
|
|
if (sb->count > sb->cap) {
|
|
|
|
int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap);
|
|
|
|
if (pos != sb->pos) {
|
|
|
|
sb->pos = pos;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
|
2006-01-05 12:40:50 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
DrawPixelInfo bk;
|
|
|
|
_cur_dpi = &bk;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
2004-09-05 14:20:36 +00:00
|
|
|
if (right > w->left &&
|
2004-08-09 17:04:08 +00:00
|
|
|
bottom > w->top &&
|
|
|
|
left < w->left + w->width &&
|
|
|
|
top < w->top + w->height) {
|
2005-11-14 19:48:04 +00:00
|
|
|
DrawOverlappedWindow(w, left, top, right, bottom);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Window *v = w;
|
2004-08-09 17:04:08 +00:00
|
|
|
int x;
|
|
|
|
|
|
|
|
while (++v != _last_window) {
|
|
|
|
if (right > v->left &&
|
2005-07-08 22:25:24 +00:00
|
|
|
bottom > v->top &&
|
2004-08-09 17:04:08 +00:00
|
|
|
left < v->left + v->width &&
|
|
|
|
top < v->top + v->height) {
|
|
|
|
if (left < (x=v->left)) {
|
|
|
|
DrawOverlappedWindow(w, left, top, x, bottom);
|
|
|
|
DrawOverlappedWindow(w, x, top, right, bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right > (x=v->left + v->width)) {
|
|
|
|
DrawOverlappedWindow(w, left, top, x, bottom);
|
|
|
|
DrawOverlappedWindow(w, x, top, right, bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top < (x=v->top)) {
|
|
|
|
DrawOverlappedWindow(w, left, top, right, x);
|
|
|
|
DrawOverlappedWindow(w, left, x, right, bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom > (x=v->top + v->height)) {
|
|
|
|
DrawOverlappedWindow(w, left, top, right, x);
|
|
|
|
DrawOverlappedWindow(w, left, x, right, bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2004-09-05 14:20:36 +00:00
|
|
|
DrawPixelInfo *dp = _cur_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
dp->width = right - left;
|
|
|
|
dp->height = bottom - top;
|
|
|
|
dp->left = left - w->left;
|
|
|
|
dp->top = top - w->top;
|
|
|
|
dp->pitch = _screen.pitch;
|
|
|
|
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
|
|
|
|
dp->zoom = 0;
|
|
|
|
CallWindowEventNP(w, WE_PAINT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallWindowEventNP(Window *w, int event)
|
|
|
|
{
|
|
|
|
WindowEvent e;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
e.event = event;
|
|
|
|
w->wndproc(w, &e);
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
void SetWindowDirty(const Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-23 13:04:44 +00:00
|
|
|
if (w == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteWindow(Window *w)
|
|
|
|
{
|
|
|
|
WindowClass wc;
|
|
|
|
WindowNumber wn;
|
|
|
|
Window *v;
|
|
|
|
int count;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (_thd.place_mode != VHM_NONE &&
|
|
|
|
_thd.window_class == w->window_class &&
|
|
|
|
_thd.window_number == w->window_number) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
|
|
|
|
wc = w->window_class;
|
|
|
|
wn = w->window_number;
|
|
|
|
|
|
|
|
CallWindowEventNP(w, WE_DESTROY);
|
|
|
|
|
|
|
|
w = FindWindowById(wc, wn);
|
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (w->viewport != NULL) {
|
|
|
|
CLRBIT(_active_viewports, w->viewport - _viewports);
|
|
|
|
w->viewport->width = 0;
|
|
|
|
w->viewport = NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
free(w->widget);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
v = --_last_window;
|
|
|
|
count = (byte*)v - (byte*)w;
|
2005-01-16 11:04:45 +00:00
|
|
|
memmove(w, w + 1, count);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window *FindWindowById(WindowClass cls, WindowNumber number)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == cls && w->window_number == number) return w;
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteWindowById(WindowClass cls, WindowNumber number)
|
|
|
|
{
|
|
|
|
DeleteWindow(FindWindowById(cls, number));
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-13 16:50:20 +00:00
|
|
|
void DeleteWindowByClass(WindowClass cls)
|
|
|
|
{
|
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2005-01-13 16:50:20 +00:00
|
|
|
for (w = _windows; w != _last_window;) {
|
|
|
|
if (w->window_class == cls) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
w = _windows;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2005-01-13 16:50:20 +00:00
|
|
|
w++;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2005-01-13 16:50:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-13 20:33:51 +00:00
|
|
|
void DeletePlayerWindows(PlayerID pi)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window;) {
|
|
|
|
if (w->caption_color == pi) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
w = _windows;
|
|
|
|
} else {
|
|
|
|
w++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Also delete the player specific windows, that haven't got the caption set */
|
|
|
|
DeleteWindowById(WC_BUY_COMPANY, pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change the owner of all the windows one player can take over from another player (like vehicle view windows) */
|
|
|
|
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->caption_color != old_player) continue;
|
|
|
|
if (w->window_class == WC_PLAYER_COLOR) continue;
|
|
|
|
if (w->window_class == WC_FINANCES) continue;
|
|
|
|
if (w->window_class == WC_STATION_LIST) continue;
|
|
|
|
if (w->window_class == WC_TRAINS_LIST) continue;
|
|
|
|
if (w->window_class == WC_ROADVEH_LIST) continue;
|
|
|
|
if (w->window_class == WC_SHIPS_LIST) continue;
|
|
|
|
if (w->window_class == WC_AIRCRAFT_LIST) continue;
|
|
|
|
if (w->window_class == WC_BUY_COMPANY) continue;
|
|
|
|
if (w->window_class == WC_COMPANY) continue;
|
|
|
|
w->caption_color = new_player;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static Window *BringWindowToFront(Window *w);
|
2006-01-05 12:40:50 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
|
|
|
|
{
|
|
|
|
Window *w = FindWindowById(cls, number);
|
|
|
|
|
|
|
|
if (w != NULL) {
|
|
|
|
w->flags4 |= WF_WHITE_BORDER_MASK;
|
|
|
|
SetWindowDirty(w);
|
2004-11-14 08:15:50 +00:00
|
|
|
w = BringWindowToFront(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
static inline bool IsVitalWindow(const Window *w)
|
|
|
|
{
|
|
|
|
WindowClass wc = w->window_class;
|
|
|
|
return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** On clicking on a window, make it the frontmost window of all. However
|
|
|
|
* there are certain windows that always need to be on-top; these include
|
|
|
|
* - Toolbar, Statusbar (always on)
|
|
|
|
* - New window, Chatbar (only if open)
|
|
|
|
* @param w window that is put into the foreground
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static Window *BringWindowToFront(Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *v;
|
2004-11-14 08:11:05 +00:00
|
|
|
Window temp;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
v = _last_window;
|
|
|
|
do {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (--v < _windows) return w;
|
2005-04-05 21:03:30 +00:00
|
|
|
} while (IsVitalWindow(v));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w == v) return w;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
assert(w < v);
|
|
|
|
|
2004-11-14 08:11:05 +00:00
|
|
|
temp = *w;
|
|
|
|
memmove(w, w + 1, (v - w) * sizeof(Window));
|
|
|
|
*v = temp;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-14 08:11:05 +00:00
|
|
|
SetWindowDirty(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-14 08:11:05 +00:00
|
|
|
return v;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
/** We have run out of windows, so find a suitable candidate for replacement.
|
|
|
|
* Keep all important windows intact. These are
|
|
|
|
* - Main window (gamefield), Toolbar, Statusbar (always on)
|
|
|
|
* - News window, Chatbar (when on)
|
|
|
|
* - Any sticked windows since we wanted to keep these
|
|
|
|
* @return w pointer to the window that is going to be deleted
|
|
|
|
*/
|
2004-12-22 17:37:21 +00:00
|
|
|
static Window *FindDeletableWindow(void)
|
|
|
|
{
|
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-12-22 17:37:21 +00:00
|
|
|
for (w = _windows; w < endof(_windows); w++) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
|
|
|
|
return w;
|
|
|
|
}
|
2004-12-22 17:37:21 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
/** A window must be freed, and all are marked as important windows. Ease the
|
|
|
|
* restriction a bit by allowing to delete sticky windows. Keep important/vital
|
|
|
|
* windows intact (Main window, Toolbar, Statusbar, News Window, Chatbar)
|
|
|
|
* @see FindDeletableWindow()
|
|
|
|
* @return w Pointer to the window that is being deleted
|
|
|
|
*/
|
2004-12-22 17:37:21 +00:00
|
|
|
static Window *ForceFindDeletableWindow(void)
|
|
|
|
{
|
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-12-22 17:37:21 +00:00
|
|
|
for (w = _windows;; w++) {
|
|
|
|
assert(w < _last_window);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w;
|
2004-12-22 17:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
bool IsWindowOfPrototype(const Window *w, const Widget *widget)
|
2005-01-03 19:45:18 +00:00
|
|
|
{
|
|
|
|
return (w->original_widget == widget);
|
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
/* Copies 'widget' to 'w->widget' to allow for resizable windows */
|
2005-01-03 19:45:18 +00:00
|
|
|
void AssignWidgetToWindow(Window *w, const Widget *widget)
|
|
|
|
{
|
|
|
|
w->original_widget = widget;
|
|
|
|
|
|
|
|
if (widget != NULL) {
|
|
|
|
uint index = 1;
|
2006-07-26 03:33:12 +00:00
|
|
|
const Widget *wi;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
for (wi = widget; wi->type != WWT_LAST; wi++) index++;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
w->widget = realloc(w->widget, sizeof(*w->widget) * index);
|
|
|
|
memcpy(w->widget, widget, sizeof(*w->widget) * index);
|
|
|
|
} else {
|
2005-01-03 19:45:18 +00:00
|
|
|
w->widget = NULL;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2005-01-03 19:45:18 +00:00
|
|
|
}
|
|
|
|
|
2006-09-02 20:09:16 +00:00
|
|
|
/* Open a new window.
|
|
|
|
* This function is called from AllocateWindow() or AllocateWindowDesc()
|
|
|
|
* See descriptions for those functions for usage
|
|
|
|
* See AllocateWindow() for description of arguments.
|
|
|
|
* Only addition here is window_number, which is the window_number being assigned to the new window
|
2005-04-05 21:03:30 +00:00
|
|
|
*/
|
2006-09-02 20:09:16 +00:00
|
|
|
static Window *LocalAllocateWindow(
|
2005-04-05 21:03:30 +00:00
|
|
|
int x, int y, int width, int height,
|
2006-09-02 20:09:16 +00:00
|
|
|
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-04-05 21:03:30 +00:00
|
|
|
Window *w = _last_window; // last window keeps track of the highest open window
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
// We have run out of windows, close one and use that as the place for our new one
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w >= endof(_windows)) {
|
2004-12-22 17:37:21 +00:00
|
|
|
w = FindDeletableWindow();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w == NULL) w = ForceFindDeletableWindow();
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-12-22 17:37:21 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
w = _last_window;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
/* XXX - This very strange construction makes sure that the chatbar is always
|
|
|
|
* on top of other windows. Why? It is created as last_window (so, on top).
|
|
|
|
* Any other window will go below toolbar/statusbar/news window, which implicitely
|
|
|
|
* also means it is below the chatbar. Very likely needs heavy improvement
|
|
|
|
* to de-braindeadize */
|
|
|
|
if (w != _windows && cls != WC_SEND_NETWORK_MSG) {
|
2004-08-09 17:04:08 +00:00
|
|
|
Window *v;
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
/* XXX - if not this order (toolbar/statusbar and then news), game would
|
|
|
|
* crash because it will try to copy a negative size for the news-window.
|
|
|
|
* Eg. window was already moved BELOW news (which is below toolbar/statusbar)
|
|
|
|
* and now needs to move below those too. That is a negative move. */
|
2004-08-09 17:04:08 +00:00
|
|
|
v = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
2005-04-05 21:03:30 +00:00
|
|
|
if (v != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
memmove(v+1, v, (byte*)w - (byte*)v);
|
|
|
|
w = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = FindWindowById(WC_STATUS_BAR, 0);
|
2005-04-05 21:03:30 +00:00
|
|
|
if (v != NULL) {
|
|
|
|
memmove(v+1, v, (byte*)w - (byte*)v);
|
|
|
|
w = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = FindWindowById(WC_NEWS_WINDOW, 0);
|
|
|
|
if (v != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
memmove(v+1, v, (byte*)w - (byte*)v);
|
|
|
|
w = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
// Set up window properties
|
|
|
|
memset(w, 0, sizeof(Window));
|
2004-08-09 17:04:08 +00:00
|
|
|
w->window_class = cls;
|
2005-04-05 21:03:30 +00:00
|
|
|
w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
|
2004-08-09 17:04:08 +00:00
|
|
|
w->caption_color = 0xFF;
|
|
|
|
w->left = x;
|
|
|
|
w->top = y;
|
|
|
|
w->width = width;
|
|
|
|
w->height = height;
|
|
|
|
w->wndproc = proc;
|
2005-01-03 19:45:18 +00:00
|
|
|
AssignWidgetToWindow(w, widget);
|
|
|
|
w->resize.width = width;
|
|
|
|
w->resize.height = height;
|
|
|
|
w->resize.step_width = 1;
|
|
|
|
w->resize.step_height = 1;
|
2006-09-02 20:09:16 +00:00
|
|
|
w->window_number = window_number;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_last_window++;
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-23 10:59:03 +00:00
|
|
|
CallWindowEventNP(w, WE_CREATE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2006-09-02 20:09:16 +00:00
|
|
|
/**
|
|
|
|
* Open a new window. If there is no space for a new window, close an open
|
|
|
|
* window. Try to avoid stickied windows, but if there is no else, close one of
|
|
|
|
* those as well. Then make sure all created windows are below some always-on-top
|
|
|
|
* ones. Finally set all variables and call the WE_CREATE event
|
|
|
|
* @param x offset in pixels from the left of the screen
|
|
|
|
* @param y offset in pixels from the top of the screen
|
|
|
|
* @param width width in pixels of the window
|
|
|
|
* @param height height in pixels of the window
|
|
|
|
* @param *proc @see WindowProc function to call when any messages/updates happen to the window
|
|
|
|
* @param cls @see WindowClass class of the window, used for identification and grouping
|
|
|
|
* @param *widget @see Widget pointer to the window layout and various elements
|
|
|
|
* @return @see Window pointer of the newly created window
|
|
|
|
*/
|
|
|
|
Window *AllocateWindow(
|
|
|
|
int x, int y, int width, int height,
|
|
|
|
WindowProc *proc, WindowClass cls, const Widget *widget)
|
|
|
|
{
|
|
|
|
return LocalAllocateWindow(x, y, width, height, proc, cls, widget, 0);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
typedef struct SizeRect {
|
|
|
|
int left,top,width,height;
|
|
|
|
} SizeRect;
|
|
|
|
|
|
|
|
|
|
|
|
static SizeRect _awap_r;
|
|
|
|
|
|
|
|
static bool IsGoodAutoPlace1(int left, int top)
|
|
|
|
{
|
|
|
|
int right,bottom;
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
_awap_r.left= left;
|
|
|
|
_awap_r.top = top;
|
|
|
|
right = _awap_r.width + left;
|
|
|
|
bottom = _awap_r.height + top;
|
|
|
|
|
|
|
|
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height)
|
|
|
|
return false;
|
|
|
|
|
2004-09-05 14:20:36 +00:00
|
|
|
// Make sure it is not obscured by any window.
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == WC_MAIN_WINDOW) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-05 14:20:36 +00:00
|
|
|
if (right > w->left &&
|
2005-11-14 19:48:04 +00:00
|
|
|
w->left + w->width > left &&
|
2004-08-09 17:04:08 +00:00
|
|
|
bottom > w->top &&
|
2005-11-14 19:48:04 +00:00
|
|
|
w->top + w->height > top) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsGoodAutoPlace2(int left, int top)
|
|
|
|
{
|
|
|
|
int width,height;
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
_awap_r.left= left;
|
|
|
|
_awap_r.top = top;
|
|
|
|
width = _awap_r.width;
|
|
|
|
height = _awap_r.height;
|
|
|
|
|
|
|
|
if (left < -(width>>2) || left > _screen.width - (width>>1))
|
|
|
|
return false;
|
|
|
|
if (top < 22 || top > _screen.height - (height>>2))
|
|
|
|
return false;
|
|
|
|
|
2004-09-05 14:20:36 +00:00
|
|
|
// Make sure it is not obscured by any window.
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == WC_MAIN_WINDOW) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-05 14:20:36 +00:00
|
|
|
if (left + width > w->left &&
|
2005-11-14 19:48:04 +00:00
|
|
|
w->left + w->width > left &&
|
2004-08-09 17:04:08 +00:00
|
|
|
top + height > w->top &&
|
2005-11-14 19:48:04 +00:00
|
|
|
w->top + w->height > top) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static Point GetAutoPlacePosition(int width, int height)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
Window *w;
|
|
|
|
Point pt;
|
|
|
|
|
|
|
|
_awap_r.width = width;
|
|
|
|
_awap_r.height = height;
|
|
|
|
|
|
|
|
if (IsGoodAutoPlace1(0, 24)) goto ok_pos;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == WC_MAIN_WINDOW) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos;
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == WC_MAIN_WINDOW) continue;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos;
|
|
|
|
if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int left=0,top=24;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
restart:;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->left == left && w->top == top) {
|
|
|
|
left += 5;
|
|
|
|
top += 5;
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
pt.x = left;
|
|
|
|
pt.y = top;
|
|
|
|
return pt;
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
ok_pos:;
|
|
|
|
pt.x = _awap_r.left;
|
|
|
|
pt.y = _awap_r.top;
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2006-09-02 20:09:16 +00:00
|
|
|
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Point pt;
|
|
|
|
Window *w;
|
|
|
|
|
2006-11-11 09:47:44 +00:00
|
|
|
/* By default position a child window at an offset of 10/10 of its parent.
|
|
|
|
* However if it falls too extremely outside window positions, reposition
|
|
|
|
* it to an automatic place */
|
|
|
|
if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ &&
|
|
|
|
(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
|
|
|
|
w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
pt.x = w->left + 10;
|
2006-11-11 09:47:44 +00:00
|
|
|
if (pt.x > _screen.width + 10 - desc->width) {
|
2004-08-09 17:04:08 +00:00
|
|
|
pt.x = (_screen.width + 10 - desc->width) - 20;
|
2006-11-11 09:47:44 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
pt.y = w->top + 10;
|
|
|
|
} else {
|
2006-11-11 10:12:00 +00:00
|
|
|
switch (desc->left) {
|
|
|
|
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
|
|
|
|
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
|
|
|
pt.x = (w->left + w->width) - desc->width;
|
|
|
|
} break;
|
|
|
|
case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */
|
|
|
|
pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left;
|
|
|
|
break;
|
|
|
|
case WDP_AUTO: /* Find a good automatic position for the window */
|
|
|
|
pt = GetAutoPlacePosition(desc->width, desc->height);
|
|
|
|
goto allocate_window;
|
|
|
|
case WDP_CENTER: /* Centre the window horizontally */
|
|
|
|
pt.x = (_screen.width - desc->width) / 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pt.x = desc->left;
|
|
|
|
if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (desc->top) {
|
|
|
|
case WDP_CENTER: /* Centre the window vertically */
|
|
|
|
pt.y = (_screen.height - desc->height) / 2;
|
|
|
|
break;
|
|
|
|
/* WDP_AUTO sets the position at once and is controlled by desc->left.
|
|
|
|
* Both left and top must be set to WDP_AUTO */
|
|
|
|
case WDP_AUTO:
|
|
|
|
NOT_REACHED();
|
|
|
|
assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO);
|
|
|
|
/* fallthrough */
|
|
|
|
default:
|
|
|
|
pt.y = desc->top;
|
|
|
|
if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-11 10:12:00 +00:00
|
|
|
allocate_window:
|
2006-09-02 20:09:16 +00:00
|
|
|
w = LocalAllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets, window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
w->desc_flags = desc->flags;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2006-09-02 20:09:16 +00:00
|
|
|
/**
|
|
|
|
* Open a new window.
|
|
|
|
* @param *desc The pointer to the WindowDesc to be created
|
|
|
|
* @return @see Window pointer of the newly created window
|
|
|
|
*/
|
|
|
|
Window *AllocateWindowDesc(const WindowDesc *desc)
|
|
|
|
{
|
|
|
|
return LocalAllocateWindowDesc(desc, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a new window.
|
|
|
|
* @param *desc The pointer to the WindowDesc to be created
|
|
|
|
* @param window_number the window number of the new window
|
|
|
|
* @return @see Window pointer of the newly created window
|
|
|
|
*/
|
|
|
|
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
if (BringWindowToFrontById(desc->cls, window_number)) return NULL;
|
|
|
|
w = LocalAllocateWindowDesc(desc, window_number);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
Window *FindWindowFromPt(int x, int y)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
--w;
|
|
|
|
if (IS_INSIDE_1D(x, w->left, w->width) &&
|
2005-11-14 19:48:04 +00:00
|
|
|
IS_INSIDE_1D(y, w->top, w->height)) {
|
|
|
|
return w;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitWindowSystem(void)
|
2004-09-03 19:59:05 +00:00
|
|
|
{
|
2004-08-25 08:55:53 +00:00
|
|
|
IConsoleClose();
|
2005-03-09 19:48:20 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
memset(&_windows, 0, sizeof(_windows));
|
|
|
|
_last_window = _windows;
|
|
|
|
memset(_viewports, 0, sizeof(_viewports));
|
|
|
|
_active_viewports = 0;
|
2005-02-22 14:52:20 +00:00
|
|
|
_no_scroll = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-03-09 19:48:20 +00:00
|
|
|
void UnInitWindowSystem(void)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
// delete all malloced widgets
|
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
free(w->widget);
|
|
|
|
w->widget = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetWindowSystem(void)
|
|
|
|
{
|
|
|
|
UnInitWindowSystem();
|
|
|
|
InitWindowSystem();
|
2005-05-02 17:14:31 +00:00
|
|
|
_thd.pos.x = 0;
|
|
|
|
_thd.pos.y = 0;
|
2006-01-24 18:08:04 +00:00
|
|
|
_thd.new_pos.x = 0;
|
|
|
|
_thd.new_pos.y = 0;
|
2005-03-09 19:48:20 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void DecreaseWindowCounters(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
|
2005-03-09 19:48:20 +00:00
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
--w;
|
|
|
|
// Unclick scrollbar buttons if they are pressed.
|
|
|
|
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
|
|
|
|
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
CallWindowEventNP(w, WE_MOUSELOOP);
|
|
|
|
}
|
|
|
|
|
2005-03-09 19:48:20 +00:00
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
--w;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) {
|
|
|
|
CallWindowEventNP(w, WE_TIMEOUT);
|
2006-10-03 20:16:20 +00:00
|
|
|
if (w->desc_flags & WDF_UNCLICK_BUTTONS) RaiseWindowButtons(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
Window *GetCallbackWnd(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
return FindWindowById(_thd.window_class, _thd.window_number);
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void HandlePlacePresize(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
WindowEvent e;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_special_mouse_mode != WSM_PRESIZE) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
w = GetCallbackWnd();
|
|
|
|
if (w == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.place.pt = GetTileBelowCursor();
|
|
|
|
if (e.we.place.pt.x == -1) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_thd.selend.x = -1;
|
|
|
|
return;
|
|
|
|
}
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
e.event = WE_PLACE_PRESIZE;
|
|
|
|
w->wndproc(w, &e);
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static bool HandleDragDrop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
WindowEvent e;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_special_mouse_mode != WSM_DRAGDROP) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_left_button_down) return false;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
w = GetCallbackWnd();
|
|
|
|
|
|
|
|
ResetObjectToPlace();
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// send an event in client coordinates.
|
|
|
|
e.event = WE_DRAGDROP;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.dragdrop.pt.x = _cursor.pos.x - w->left;
|
|
|
|
e.we.dragdrop.pt.y = _cursor.pos.y - w->top;
|
|
|
|
e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
w->wndproc(w, &e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static bool HandlePopupMenu(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
WindowEvent e;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!_popup_menu_active) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
w = FindWindowById(WC_TOOLBAR_MENU, 0);
|
|
|
|
if (w == NULL) {
|
|
|
|
_popup_menu_active = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_left_button_down) {
|
|
|
|
e.event = WE_POPUPMENU_OVER;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.popupmenu.pt = _cursor.pos;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
_popup_menu_active = false;
|
|
|
|
e.event = WE_POPUPMENU_SELECT;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.popupmenu.pt = _cursor.pos;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-16 12:30:52 +00:00
|
|
|
w->wndproc(w, &e);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static bool HandleMouseOver(void)
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
WindowEvent e;
|
|
|
|
static Window *last_w = NULL;
|
|
|
|
|
|
|
|
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
|
|
|
|
|
|
|
|
// We changed window, put a MOUSEOVER event to the last window
|
2005-11-14 19:48:04 +00:00
|
|
|
if (last_w != NULL && last_w != w) {
|
2004-12-04 17:54:56 +00:00
|
|
|
e.event = WE_MOUSEOVER;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.mouseover.pt.x = -1;
|
|
|
|
e.we.mouseover.pt.y = -1;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (last_w->wndproc) last_w->wndproc(last_w, &e);
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
last_w = w;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w != NULL) {
|
2004-12-04 17:54:56 +00:00
|
|
|
// send an event in client coordinates.
|
|
|
|
e.event = WE_MOUSEOVER;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.mouseover.pt.x = _cursor.pos.x - w->left;
|
|
|
|
e.we.mouseover.pt.y = _cursor.pos.y - w->top;
|
2004-12-04 17:54:56 +00:00
|
|
|
if (w->widget != NULL) {
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y);
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
w->wndproc(w, &e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouseover never stops execution
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-11-04 14:01:44 +00:00
|
|
|
|
|
|
|
static bool _dragging_window;
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static bool HandleWindowDragging(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
// Get out immediately if no window is being dragged at all.
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!_dragging_window) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Otherwise find the window...
|
2004-11-10 21:14:16 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->flags4 & WF_DRAGGING) {
|
2004-11-13 10:53:42 +00:00
|
|
|
const Widget *t = &w->widget[1]; // the title bar ... ugh
|
2004-11-10 21:14:16 +00:00
|
|
|
const Window *v;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int nx;
|
|
|
|
int ny;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Stop the dragging if the left mouse button was released
|
|
|
|
if (!_left_button_down) {
|
2004-11-10 21:14:16 +00:00
|
|
|
w->flags4 &= ~WF_DRAGGING;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
x = _cursor.pos.x + _drag_delta.x;
|
|
|
|
y = _cursor.pos.y + _drag_delta.y;
|
|
|
|
nx = x;
|
|
|
|
ny = y;
|
|
|
|
|
|
|
|
if (_patches.window_snap_radius != 0) {
|
2004-11-11 21:20:15 +00:00
|
|
|
int hsnap = _patches.window_snap_radius;
|
|
|
|
int vsnap = _patches.window_snap_radius;
|
|
|
|
int delta;
|
2004-11-10 21:14:16 +00:00
|
|
|
|
|
|
|
for (v = _windows; v != _last_window; ++v) {
|
|
|
|
if (v == w) continue; // Don't snap at yourself
|
|
|
|
|
|
|
|
if (y + w->height > v->top && y < v->top + v->height) {
|
|
|
|
// Your left border <-> other right border
|
|
|
|
delta = abs(v->left + v->width - x);
|
|
|
|
if (delta <= hsnap) {
|
|
|
|
nx = v->left + v->width;
|
|
|
|
hsnap = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Your right border <-> other left border
|
|
|
|
delta = abs(v->left - x - w->width);
|
|
|
|
if (delta <= hsnap) {
|
|
|
|
nx = v->left - w->width;
|
|
|
|
hsnap = delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-11 21:20:15 +00:00
|
|
|
if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
|
|
|
|
// Your left border <-> other left border
|
|
|
|
delta = abs(v->left - x);
|
|
|
|
if (delta <= hsnap) {
|
|
|
|
nx = v->left;
|
|
|
|
hsnap = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Your right border <-> other right border
|
|
|
|
delta = abs(v->left + v->width - x - w->width);
|
|
|
|
if (delta <= hsnap) {
|
|
|
|
nx = v->left + v->width - w->width;
|
|
|
|
hsnap = delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
if (x + w->width > v->left && x < v->left + v->width) {
|
|
|
|
// Your top border <-> other bottom border
|
|
|
|
delta = abs(v->top + v->height - y);
|
|
|
|
if (delta <= vsnap) {
|
|
|
|
ny = v->top + v->height;
|
|
|
|
vsnap = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Your bottom border <-> other top border
|
|
|
|
delta = abs(v->top - y - w->height);
|
|
|
|
if (delta <= vsnap) {
|
|
|
|
ny = v->top - w->height;
|
|
|
|
vsnap = delta;
|
|
|
|
}
|
|
|
|
}
|
2004-11-11 21:20:15 +00:00
|
|
|
|
|
|
|
if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
|
|
|
|
// Your top border <-> other top border
|
|
|
|
delta = abs(v->top - y);
|
|
|
|
if (delta <= vsnap) {
|
|
|
|
ny = v->top;
|
|
|
|
vsnap = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Your bottom border <-> other bottom border
|
|
|
|
delta = abs(v->top + v->height - y - w->height);
|
|
|
|
if (delta <= vsnap) {
|
|
|
|
ny = v->top + v->height - w->height;
|
|
|
|
vsnap = delta;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
// Make sure the window doesn't leave the screen
|
|
|
|
// 13 is the height of the title bar
|
2004-11-13 10:53:42 +00:00
|
|
|
nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
|
2004-11-10 21:14:16 +00:00
|
|
|
ny = clamp(ny, 0, _screen.height - 13);
|
|
|
|
|
2004-11-13 10:53:42 +00:00
|
|
|
// Make sure the title bar isn't hidden by behind the main tool bar
|
|
|
|
v = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
|
|
|
if (v != NULL) {
|
|
|
|
int v_bottom = v->top + v->height;
|
|
|
|
int v_right = v->left + v->width;
|
|
|
|
if (ny + t->top >= v->top && ny + t->top < v_bottom) {
|
2004-11-13 11:08:50 +00:00
|
|
|
if ((v->left < 13 && nx + t->left < v->left) ||
|
|
|
|
(v_right > _screen.width - 13 && nx + t->right > v_right)) {
|
2004-11-13 10:53:42 +00:00
|
|
|
ny = v_bottom;
|
|
|
|
} else {
|
|
|
|
if (nx + t->left > v->left - 13 &&
|
|
|
|
nx + t->right < v_right + 13) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w->top >= v_bottom) {
|
2004-11-13 10:53:42 +00:00
|
|
|
ny = v_bottom;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else if (w->left < nx) {
|
2004-11-13 10:53:42 +00:00
|
|
|
nx = v->left - 13 - t->left;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2004-11-13 10:53:42 +00:00
|
|
|
nx = v_right + 13 - t->right;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-11-13 10:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
if (w->viewport != NULL) {
|
|
|
|
w->viewport->left += nx - w->left;
|
|
|
|
w->viewport->top += ny - w->top;
|
|
|
|
}
|
|
|
|
w->left = nx;
|
|
|
|
w->top = ny;
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
return false;
|
|
|
|
} else if (w->flags4 & WF_SIZING) {
|
|
|
|
WindowEvent e;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Stop the sizing if the left mouse button was released */
|
|
|
|
if (!_left_button_down) {
|
|
|
|
w->flags4 &= ~WF_SIZING;
|
2005-04-07 00:59:54 +00:00
|
|
|
SetWindowDirty(w);
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = _cursor.pos.x - _drag_delta.x;
|
|
|
|
y = _cursor.pos.y - _drag_delta.y;
|
|
|
|
|
2005-11-18 20:28:55 +00:00
|
|
|
/* X and Y has to go by step.. calculate it.
|
|
|
|
* The cast to int is necessary else x/y are implicitly casted to
|
|
|
|
* unsigned int, which won't work. */
|
|
|
|
if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-11-18 20:28:55 +00:00
|
|
|
if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
/* Check if we don't go below the minimum set size */
|
|
|
|
if ((int)w->width + x < (int)w->resize.width)
|
|
|
|
x = w->resize.width - w->width;
|
|
|
|
if ((int)w->height + y < (int)w->resize.height)
|
|
|
|
y = w->resize.height - w->height;
|
|
|
|
|
|
|
|
/* Window already on size */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (x == 0 && y == 0) return false;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
/* Now find the new cursor pos.. this is NOT _cursor, because
|
|
|
|
we move in steps. */
|
|
|
|
_drag_delta.x += x;
|
|
|
|
_drag_delta.y += y;
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
|
|
/* Scroll through all the windows and update the widgets if needed */
|
|
|
|
{
|
|
|
|
Widget *wi = w->widget;
|
|
|
|
bool resize_height = false;
|
|
|
|
bool resize_width = false;
|
|
|
|
|
|
|
|
while (wi->type != WWT_LAST) {
|
2006-10-06 01:33:27 +00:00
|
|
|
/* Isolate the resizing flags */
|
|
|
|
byte rsizeflag = GB(wi->display_flags, 0, 4);
|
|
|
|
|
|
|
|
if (rsizeflag != RESIZE_NONE) {
|
2005-01-03 19:45:18 +00:00
|
|
|
/* Resize this widget */
|
2006-10-06 01:33:27 +00:00
|
|
|
if (rsizeflag & RESIZE_LEFT) {
|
2005-01-03 19:45:18 +00:00
|
|
|
wi->left += x;
|
|
|
|
resize_width = true;
|
|
|
|
}
|
2006-10-06 01:33:27 +00:00
|
|
|
if (rsizeflag & RESIZE_RIGHT) {
|
2005-01-03 19:45:18 +00:00
|
|
|
wi->right += x;
|
|
|
|
resize_width = true;
|
|
|
|
}
|
|
|
|
|
2006-10-06 01:33:27 +00:00
|
|
|
if (rsizeflag & RESIZE_TOP) {
|
2005-01-03 19:45:18 +00:00
|
|
|
wi->top += y;
|
|
|
|
resize_height = true;
|
|
|
|
}
|
2006-10-06 01:33:27 +00:00
|
|
|
if (rsizeflag & RESIZE_BOTTOM) {
|
2005-01-03 19:45:18 +00:00
|
|
|
wi->bottom += y;
|
|
|
|
resize_height = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wi++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We resized at least 1 widget, so let's rezise the window totally */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (resize_width) w->width = x + w->width;
|
|
|
|
if (resize_height) w->height = y + w->height;
|
2005-01-03 19:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
e.event = WE_RESIZE;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.sizing.size.x = x + w->width;
|
|
|
|
e.we.sizing.size.y = y + w->height;
|
|
|
|
e.we.sizing.diff.x = x;
|
|
|
|
e.we.sizing.diff.y = y;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->wndproc(w, &e);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_dragging_window = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static Window *StartWindowDrag(Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
w->flags4 |= WF_DRAGGING;
|
|
|
|
_dragging_window = true;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2004-11-10 21:14:16 +00:00
|
|
|
_drag_delta.x = w->left - _cursor.pos.x;
|
|
|
|
_drag_delta.y = w->top - _cursor.pos.y;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
w = BringWindowToFront(w);
|
|
|
|
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
static Window *StartWindowSizing(Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
w->flags4 |= WF_SIZING;
|
|
|
|
_dragging_window = true;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
_drag_delta.x = _cursor.pos.x;
|
|
|
|
_drag_delta.y = _cursor.pos.y;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
w = BringWindowToFront(w);
|
|
|
|
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
2005-04-07 00:59:54 +00:00
|
|
|
SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static bool HandleScrollbarScrolling(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
int i;
|
|
|
|
int pos;
|
|
|
|
Scrollbar *sb;
|
|
|
|
|
|
|
|
// Get out quickly if no item is being scrolled
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!_scrolling_scrollbar) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// Find the scrolling window
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->flags4 & WF_SCROLL_MIDDLE) {
|
|
|
|
// Abort if no button is clicked any more.
|
|
|
|
if (!_left_button_down) {
|
|
|
|
w->flags4 &= ~WF_SCROLL_MIDDLE;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (w->flags4 & WF_HSCROLL) {
|
|
|
|
sb = &w->hscroll;
|
|
|
|
i = _cursor.pos.x - _cursorpos_drag_start.x;
|
2005-01-02 17:23:04 +00:00
|
|
|
} else if (w->flags4 & WF_SCROLL2){
|
|
|
|
sb = &w->vscroll2;
|
|
|
|
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
sb = &w->vscroll;
|
|
|
|
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the item we want to move to and make sure it's inside bounds.
|
|
|
|
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
|
|
|
|
if (pos != sb->pos) {
|
|
|
|
sb->pos = pos;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
return false;
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_scrolling_scrollbar = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static bool HandleViewportScroll(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-21 14:59:58 +00:00
|
|
|
WindowEvent e;
|
2004-08-09 17:04:08 +00:00
|
|
|
Window *w;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!_scrolling_viewport) return true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-21 14:34:59 +00:00
|
|
|
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
|
|
|
|
|
|
|
|
if (!_right_button_down || w == NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
_cursor.fix_at = false;
|
|
|
|
_scrolling_viewport = false;
|
|
|
|
return true;
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2005-11-19 12:37:28 +00:00
|
|
|
if (_patches.reverse_scroll) {
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.scroll.delta.x = -_cursor.delta.x;
|
|
|
|
e.we.scroll.delta.y = -_cursor.delta.y;
|
2005-11-19 12:37:28 +00:00
|
|
|
} else {
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.scroll.delta.x = _cursor.delta.x;
|
|
|
|
e.we.scroll.delta.y = _cursor.delta.y;
|
2005-11-19 12:37:28 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 14:34:59 +00:00
|
|
|
/* Create a scroll-event and send it to the window */
|
2006-08-21 14:59:58 +00:00
|
|
|
e.event = WE_SCROLL;
|
|
|
|
w->wndproc(w, &e);
|
2006-02-06 09:18:04 +00:00
|
|
|
|
|
|
|
_cursor.delta.x = 0;
|
|
|
|
_cursor.delta.y = 0;
|
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static Window *MaybeBringWindowToFront(Window *w)
|
|
|
|
{
|
|
|
|
Window *u;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w->window_class == WC_MAIN_WINDOW ||
|
|
|
|
IsVitalWindow(w) ||
|
|
|
|
w->window_class == WC_TOOLTIPS ||
|
|
|
|
w->window_class == WC_DROPDOWN_MENU) {
|
|
|
|
return w;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
for (u = w; ++u != _last_window;) {
|
2005-11-14 19:48:04 +00:00
|
|
|
if (u->window_class == WC_MAIN_WINDOW ||
|
|
|
|
IsVitalWindow(u) ||
|
|
|
|
u->window_class == WC_TOOLTIPS ||
|
|
|
|
u->window_class == WC_DROPDOWN_MENU) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (w->left + w->width <= u->left ||
|
|
|
|
u->left + u->width <= w->left ||
|
|
|
|
w->top + w->height <= u->top ||
|
2005-11-14 19:48:04 +00:00
|
|
|
u->top + u->height <= w->top) {
|
|
|
|
continue;
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
|
|
|
|
return BringWindowToFront(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-04-05 21:03:30 +00:00
|
|
|
/** Send a message from one window to another. The receiving window is found by
|
|
|
|
* @param w @see Window pointer pointing to the other window
|
|
|
|
* @param msg Specifies the message to be sent
|
|
|
|
* @param wparam Specifies additional message-specific information
|
|
|
|
* @param lparam Specifies additional message-specific information
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam)
|
2005-04-05 21:03:30 +00:00
|
|
|
{
|
|
|
|
WindowEvent e;
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
e.event = WE_MESSAGE;
|
|
|
|
e.we.message.msg = msg;
|
|
|
|
e.we.message.wparam = wparam;
|
|
|
|
e.we.message.lparam = lparam;
|
2005-04-05 21:03:30 +00:00
|
|
|
|
|
|
|
w->wndproc(w, &e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Send a message from one window to another. The receiving window is found by
|
|
|
|
* @param wnd_class @see WindowClass class AND
|
|
|
|
* @param wnd_num @see WindowNumber number, mostly 0
|
|
|
|
* @param msg Specifies the message to be sent
|
|
|
|
* @param wparam Specifies additional message-specific information
|
|
|
|
* @param lparam Specifies additional message-specific information
|
|
|
|
*/
|
|
|
|
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam)
|
|
|
|
{
|
|
|
|
Window *w = FindWindowById(wnd_class, wnd_num);
|
|
|
|
if (w != NULL) SendWindowMessageW(w, msg, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2006-11-07 12:51:34 +00:00
|
|
|
/** Send a message from one window to another. The message will be sent
|
|
|
|
* to ALL windows of the windowclass specified in the first parameter
|
|
|
|
* @param wnd_class @see WindowClass class
|
|
|
|
* @param msg Specifies the message to be sent
|
|
|
|
* @param wparam Specifies additional message-specific information
|
|
|
|
* @param lparam Specifies additional message-specific information
|
|
|
|
*/
|
|
|
|
void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint lparam)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == wnd_class) SendWindowMessageW(w, msg, wparam, lparam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void HandleKeypress(uint32 key)
|
|
|
|
{
|
|
|
|
Window *w;
|
2006-09-23 02:39:24 +00:00
|
|
|
WindowEvent e;
|
2006-09-04 20:40:33 +00:00
|
|
|
/* Stores if a window with a textfield for typing is open
|
|
|
|
* If this is the case, keypress events are only passed to windows with text fields and
|
|
|
|
* to thein this main toolbar. */
|
2004-12-14 17:38:48 +00:00
|
|
|
bool query_open = false;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Setup event
|
2006-09-23 02:39:24 +00:00
|
|
|
e.event = WE_KEYPRESS;
|
|
|
|
e.we.keypress.ascii = key & 0xFF;
|
|
|
|
e.we.keypress.keycode = key >> 16;
|
|
|
|
e.we.keypress.cont = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-14 17:38:48 +00:00
|
|
|
// check if we have a query string window open before allowing hotkeys
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (FindWindowById(WC_QUERY_STRING, 0) != NULL ||
|
|
|
|
FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL ||
|
|
|
|
FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL ||
|
|
|
|
FindWindowById(WC_CONSOLE, 0) != NULL ||
|
|
|
|
FindWindowById(WC_SAVELOAD, 0) != NULL) {
|
2004-12-14 17:38:48 +00:00
|
|
|
query_open = true;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-12-14 17:38:48 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Call the event, start with the uppermost window.
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
--w;
|
2004-12-14 17:38:48 +00:00
|
|
|
// if a query window is open, only call the event for certain window types
|
2005-11-14 19:48:04 +00:00
|
|
|
if (query_open &&
|
|
|
|
w->window_class != WC_QUERY_STRING &&
|
|
|
|
w->window_class != WC_SEND_NETWORK_MSG &&
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
w->window_class != WC_GENERATE_LANDSCAPE &&
|
2005-11-14 19:48:04 +00:00
|
|
|
w->window_class != WC_CONSOLE &&
|
|
|
|
w->window_class != WC_SAVELOAD) {
|
2004-12-14 17:38:48 +00:00
|
|
|
continue;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2006-09-23 02:39:24 +00:00
|
|
|
w->wndproc(w, &e);
|
|
|
|
if (!e.we.keypress.cont) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-04-03 13:35:43 +00:00
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e.we.keypress.cont) {
|
2005-04-04 16:47:03 +00:00
|
|
|
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
|
|
|
// When there is no toolbar w is null, check for that
|
2006-09-23 02:39:24 +00:00
|
|
|
if (w != NULL) w->wndproc(w, &e);
|
2005-04-04 16:47:03 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
extern void UpdateTileSelection(void);
|
|
|
|
extern bool VpHandlePlaceSizingDrag(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-26 04:16:39 +00:00
|
|
|
static void MouseLoop(int click, int mousewheel)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int x,y;
|
|
|
|
Window *w;
|
|
|
|
ViewPort *vp;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DecreaseWindowCounters();
|
|
|
|
HandlePlacePresize();
|
|
|
|
UpdateTileSelection();
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!VpHandlePlaceSizingDrag()) return;
|
|
|
|
if (!HandleDragDrop()) return;
|
|
|
|
if (!HandlePopupMenu()) return;
|
|
|
|
if (!HandleWindowDragging()) return;
|
|
|
|
if (!HandleScrollbarScrolling()) return;
|
|
|
|
if (!HandleViewportScroll()) return;
|
|
|
|
if (!HandleMouseOver()) return;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
x = _cursor.pos.x;
|
|
|
|
y = _cursor.pos.y;
|
|
|
|
|
|
|
|
if (click == 0 && mousewheel == 0) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w = FindWindowFromPt(x, y);
|
2006-02-01 06:32:03 +00:00
|
|
|
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
vp = IsPtInWindowViewport(w, x, y);
|
2006-02-06 09:18:04 +00:00
|
|
|
if (vp != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
x -= vp->left;
|
|
|
|
y -= vp->top;
|
|
|
|
//here allows scrolling in both x and y axis
|
|
|
|
#define scrollspeed 3
|
2005-10-23 13:04:44 +00:00
|
|
|
if (x - 15 < 0) {
|
|
|
|
WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom;
|
|
|
|
} else if (15 - (vp->width - x) > 0) {
|
|
|
|
WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom;
|
|
|
|
}
|
|
|
|
if (y - 15 < 0) {
|
|
|
|
WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom;
|
|
|
|
} else if (15 - (vp->height - y) > 0) {
|
|
|
|
WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom;
|
|
|
|
}
|
2004-09-05 14:20:36 +00:00
|
|
|
#undef scrollspeed
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = FindWindowFromPt(x, y);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
w = MaybeBringWindowToFront(w);
|
|
|
|
vp = IsPtInWindowViewport(w, x, y);
|
2006-08-21 14:59:58 +00:00
|
|
|
|
|
|
|
/* Don't allow any action in a viewport if either in menu of in generating world */
|
|
|
|
if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return;
|
|
|
|
|
|
|
|
if (mousewheel != 0) {
|
|
|
|
WindowEvent e;
|
|
|
|
|
|
|
|
/* Send WE_MOUSEWHEEL event to window */
|
|
|
|
e.event = WE_MOUSEWHEEL;
|
2006-09-23 02:39:24 +00:00
|
|
|
e.we.wheel.wheel = mousewheel;
|
2006-08-21 14:59:58 +00:00
|
|
|
w->wndproc(w, &e);
|
|
|
|
|
|
|
|
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
|
|
|
|
if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (vp != NULL) {
|
2006-08-21 14:59:58 +00:00
|
|
|
switch (click) {
|
|
|
|
case 1:
|
|
|
|
DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
|
|
|
|
if (_thd.place_mode != 0 &&
|
|
|
|
// query button and place sign button work in pause mode
|
|
|
|
_cursor.sprite != SPR_CURSOR_QUERY &&
|
|
|
|
_cursor.sprite != SPR_CURSOR_SIGN &&
|
|
|
|
_pause != 0 &&
|
|
|
|
!_cheats.build_in_pause.value) {
|
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-21 14:59:58 +00:00
|
|
|
if (_thd.place_mode == 0) {
|
|
|
|
HandleViewportClicked(vp, x, y);
|
|
|
|
} else {
|
|
|
|
PlaceObject();
|
|
|
|
}
|
|
|
|
break;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2006-08-21 14:59:58 +00:00
|
|
|
case 2:
|
|
|
|
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
|
|
|
|
_scrolling_viewport = true;
|
|
|
|
_cursor.fix_at = true;
|
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-11-13 14:54:09 +00:00
|
|
|
switch (click) {
|
|
|
|
case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top); break;
|
|
|
|
case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-26 04:16:39 +00:00
|
|
|
void InputLoop(void)
|
|
|
|
{
|
|
|
|
int click;
|
|
|
|
int mousewheel;
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
/*
|
|
|
|
* During the generation of the world, there might be
|
|
|
|
* another thread that is currently building for example
|
|
|
|
* a road. To not interfere with those tasks, we should
|
|
|
|
* NOT change the _current_player here.
|
|
|
|
*
|
|
|
|
* This is not necessary either, as the only events that
|
|
|
|
* can be handled are the 'close application' events
|
|
|
|
*/
|
|
|
|
if (!IsGeneratingWorld()) _current_player = _local_player;
|
2005-03-26 04:16:39 +00:00
|
|
|
|
|
|
|
// Handle pressed keys
|
2006-06-10 08:37:41 +00:00
|
|
|
if (_pressed_key != 0) {
|
|
|
|
HandleKeypress(_pressed_key);
|
|
|
|
_pressed_key = 0;
|
2005-03-26 04:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse event?
|
|
|
|
click = 0;
|
|
|
|
if (_left_button_down && !_left_button_clicked) {
|
|
|
|
_left_button_clicked = true;
|
|
|
|
click = 1;
|
|
|
|
} else if (_right_button_clicked) {
|
|
|
|
_right_button_clicked = false;
|
|
|
|
click = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
mousewheel = 0;
|
|
|
|
if (_cursor.wheel) {
|
|
|
|
mousewheel = _cursor.wheel;
|
|
|
|
_cursor.wheel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseLoop(click, mousewheel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static int _we4_timer;
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void UpdateWindows(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
int t;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
t = _we4_timer + 1;
|
|
|
|
if (t >= 100) {
|
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w--;
|
|
|
|
CallWindowEventNP(w, WE_4);
|
|
|
|
}
|
|
|
|
t = 0;
|
|
|
|
}
|
|
|
|
_we4_timer = t;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w--;
|
|
|
|
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
|
|
|
w->flags4 -= WF_WHITE_BORDER_ONE;
|
|
|
|
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) {
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawDirtyBlocks();
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->viewport != NULL) UpdateViewportPosition(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
DrawTextMessage();
|
2004-08-09 17:04:08 +00:00
|
|
|
// Redraw mouse cursor in case it was hidden
|
|
|
|
DrawMouseCursor();
|
2004-09-05 14:20:36 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
int GetMenuItemIndex(const Window *w, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
|
|
|
|
y /= 10;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (y < WP(w, const menu_d).item_count &&
|
|
|
|
!HASBIT(WP(w, const menu_d).disabled_items, y)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
return y;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-12-24 15:01:17 +00:00
|
|
|
void InvalidateWindow(WindowClass cls, WindowNumber number)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Window *w;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == cls && w->window_number == number) SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
void InvalidateWidget(const Window *w, byte widget_index)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
const Widget *wi = &w->widget[widget_index];
|
2005-05-28 17:01:26 +00:00
|
|
|
|
|
|
|
/* Don't redraw the window if the widget is invisible or of no-type */
|
2006-10-06 01:33:27 +00:00
|
|
|
if (wi->type == WWT_EMPTY || IsWidgetHidden(wi)) return;
|
2005-05-28 17:01:26 +00:00
|
|
|
|
|
|
|
SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-12-24 15:01:17 +00:00
|
|
|
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Window *w;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == cls && w->window_number == number) {
|
2004-08-09 17:04:08 +00:00
|
|
|
InvalidateWidget(w, widget_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-24 15:01:17 +00:00
|
|
|
void InvalidateWindowClasses(WindowClass cls)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == cls) SetWindowDirty(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-07 14:30:13 +00:00
|
|
|
void InvalidateThisWindowData(Window *w)
|
|
|
|
{
|
|
|
|
CallWindowEventNP(w, WE_INVALIDATE_DATA);
|
|
|
|
}
|
|
|
|
|
2006-10-05 12:59:28 +00:00
|
|
|
void InvalidateWindowData(WindowClass cls, WindowNumber number)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; w++) {
|
2006-10-07 14:30:13 +00:00
|
|
|
if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InvalidateWindowClassesData(WindowClass cls)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
|
if (w->window_class == cls) InvalidateThisWindowData(w);
|
2006-10-05 12:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void CallWindowTickEvent(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
for (w = _last_window; w != _windows;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
--w;
|
|
|
|
CallWindowEventNP(w, WE_TICK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void DeleteNonVitalWindows(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
for (w = _windows; w != _last_window;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->window_class != WC_MAIN_WINDOW &&
|
|
|
|
w->window_class != WC_SELECT_GAME &&
|
|
|
|
w->window_class != WC_MAIN_TOOLBAR &&
|
|
|
|
w->window_class != WC_STATUS_BAR &&
|
|
|
|
w->window_class != WC_TOOLBAR_MENU &&
|
2004-12-15 23:33:04 +00:00
|
|
|
w->window_class != WC_TOOLTIPS &&
|
|
|
|
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
w = _windows;
|
|
|
|
} else {
|
|
|
|
w++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
/* It is possible that a stickied window gets to a position where the
|
2004-12-22 17:37:21 +00:00
|
|
|
* 'close' button is outside the gaming area. You cannot close it then; except
|
|
|
|
* with this function. It closes all windows calling the standard function,
|
|
|
|
* then, does a little hacked loop of closing all stickied windows. Note
|
|
|
|
* that standard windows (status bar, etc.) are not stickied, so these aren't affected */
|
|
|
|
void DeleteAllNonVitalWindows(void)
|
|
|
|
{
|
|
|
|
Window *w;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-12-22 17:37:21 +00:00
|
|
|
// Delete every window except for stickied ones
|
|
|
|
DeleteNonVitalWindows();
|
|
|
|
// Delete all sticked windows
|
|
|
|
for (w = _windows; w != _last_window;) {
|
|
|
|
if (w->flags4 & WF_STICKY) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
w = _windows;
|
2006-06-27 21:25:53 +00:00
|
|
|
} else {
|
2004-12-22 17:37:21 +00:00
|
|
|
w++;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-12-22 17:37:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-11 00:54:06 +00:00
|
|
|
/* Delete all always on-top windows to get an empty screen */
|
|
|
|
void HideVitalWindows(void)
|
|
|
|
{
|
|
|
|
DeleteWindowById(WC_MAIN_TOOLBAR, 0);
|
|
|
|
DeleteWindowById(WC_STATUS_BAR, 0);
|
|
|
|
}
|
|
|
|
|
2004-09-05 14:20:36 +00:00
|
|
|
int PositionMainToolbar(Window *w)
|
2004-08-16 21:02:06 +00:00
|
|
|
{
|
2004-08-16 22:15:44 +00:00
|
|
|
DEBUG(misc, 1) ("Repositioning Main Toolbar...");
|
2004-08-16 21:02:06 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) {
|
2004-08-16 21:02:06 +00:00
|
|
|
w = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2004-08-16 21:02:06 +00:00
|
|
|
|
|
|
|
switch (_patches.toolbar_pos) {
|
2006-11-11 09:47:44 +00:00
|
|
|
case 1: w->left = (_screen.width - w->width) / 2; break;
|
2005-07-08 22:25:24 +00:00
|
|
|
case 2: w->left = _screen.width - w->width; break;
|
|
|
|
default: w->left = 0;
|
2004-08-16 21:02:06 +00:00
|
|
|
}
|
|
|
|
SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part
|
|
|
|
return w->left;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void RelocateAllWindows(int neww, int newh)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (w = _windows; w != _last_window; w++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
int left, top;
|
2004-09-05 14:20:36 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->window_class == WC_MAIN_WINDOW) {
|
|
|
|
ViewPort *vp = w->viewport;
|
|
|
|
vp->width = w->width = neww;
|
|
|
|
vp->height = w->height = newh;
|
|
|
|
vp->virtual_width = neww << vp->zoom;
|
|
|
|
vp->virtual_height = newh << vp->zoom;
|
|
|
|
continue; // don't modify top,left
|
2004-09-03 19:59:05 +00:00
|
|
|
}
|
|
|
|
|
2004-08-24 08:34:28 +00:00
|
|
|
IConsoleResize();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-06 09:18:04 +00:00
|
|
|
switch (w->window_class) {
|
|
|
|
case WC_MAIN_TOOLBAR:
|
|
|
|
top = w->top;
|
|
|
|
left = PositionMainToolbar(w); // changes toolbar orientation
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WC_SELECT_GAME:
|
|
|
|
case WC_GAME_OPTIONS:
|
|
|
|
case WC_NETWORK_WINDOW:
|
|
|
|
top = (newh - w->height) >> 1;
|
|
|
|
left = (neww - w->width) >> 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WC_NEWS_WINDOW:
|
|
|
|
top = newh - w->height;
|
|
|
|
left = (neww - w->width) >> 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WC_STATUS_BAR:
|
|
|
|
top = newh - w->height;
|
|
|
|
left = (neww - w->width) >> 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WC_SEND_NETWORK_MSG:
|
|
|
|
top = (newh - 26); // 26 = height of status bar + height of chat bar
|
|
|
|
left = (neww - w->width) >> 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
left = w->left;
|
|
|
|
if (left + (w->width >> 1) >= neww) left = neww - w->width;
|
|
|
|
top = w->top;
|
|
|
|
if (top + (w->height >> 1) >= newh) top = newh - w->height;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (w->viewport != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w->viewport->left += left - w->left;
|
|
|
|
w->viewport->top += top - w->top;
|
|
|
|
}
|
|
|
|
|
|
|
|
w->left = left;
|
|
|
|
w->top = top;
|
|
|
|
}
|
|
|
|
}
|