author | convert-repo |
Mon, 07 Apr 2008 16:21:55 +0000 | |
changeset 10076 | dfd70e42c4ae |
parent 9194 | 685d482d1e6c |
child 10083 | 9fb63cf5cc90 |
child 10328 | 721fe18a2176 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6158
diff
changeset
|
3 |
/** @file window.cpp windowing system, widgets and events */ |
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6158
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
6 |
#include <stdarg.h> |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1867
diff
changeset
|
7 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1112
diff
changeset
|
8 |
#include "debug.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8720
diff
changeset
|
9 |
#include "player_func.h" |
8720
4e60c30e2006
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8673
diff
changeset
|
10 |
#include "gfx_func.h" |
126 | 11 |
#include "console.h" |
8720
4e60c30e2006
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8673
diff
changeset
|
12 |
#include "viewport_func.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
13 |
#include "variables.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
14 |
#include "genworld.h" |
7433
8e410e7ec0d7
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
7374
diff
changeset
|
15 |
#include "blitter/factory.hpp" |
8602
9e75e594a068
(svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents:
8564
diff
changeset
|
16 |
#include "window_gui.h" |
8619
c2434269c3eb
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8617
diff
changeset
|
17 |
#include "zoom_func.h" |
8626
440dfcd14c4a
(svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents:
8619
diff
changeset
|
18 |
#include "core/alloc_func.hpp" |
8635
3bbb6f87fced
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8627
diff
changeset
|
19 |
#include "map_func.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8635
diff
changeset
|
20 |
#include "vehicle_base.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8764
diff
changeset
|
21 |
#include "settings_type.h" |
0 | 22 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
23 |
#include "table/sprites.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
24 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
25 |
/* delta between mouse cursor and upper left corner of dragged window */ |
350 | 26 |
static Point _drag_delta; |
27 |
||
8564
f4a063368ba9
(svn r11629) -Fix [FS#1527]: many viewports could crash the scenario editor.
rubidium
parents:
8532
diff
changeset
|
28 |
static Window _windows[MAX_NUMBER_OF_WINDOWS]; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
29 |
Window *_z_windows[lengthof(_windows)]; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
30 |
Window **_last_z_window; ///< always points to the next free space in the z-array |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
31 |
|
8764
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
32 |
Point _cursorpos_drag_start; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
33 |
|
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
34 |
int _scrollbar_start_pos; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
35 |
int _scrollbar_size; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
36 |
byte _scroller_click_timeout; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
37 |
|
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
38 |
bool _scrolling_scrollbar; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
39 |
bool _scrolling_viewport; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
40 |
bool _popup_menu_active; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
41 |
|
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
42 |
byte _special_mouse_mode; |
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
43 |
|
65746a5248ec
(svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents:
8760
diff
changeset
|
44 |
|
8489
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
45 |
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...) |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
46 |
{ |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
47 |
va_list wdg_list; |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
48 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
49 |
va_start(wdg_list, widgets); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
50 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
51 |
while (widgets != WIDGET_LIST_END) { |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
52 |
SetWidgetDisabledState(widgets, disab_stat); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
53 |
widgets = va_arg(wdg_list, int); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
54 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
55 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
56 |
va_end(wdg_list); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
57 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
58 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
59 |
void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...) |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
60 |
{ |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
61 |
va_list wdg_list; |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
62 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
63 |
va_start(wdg_list, widgets); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
64 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
65 |
while (widgets != WIDGET_LIST_END) { |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
66 |
SetWidgetHiddenState(widgets, hidden_stat); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
67 |
widgets = va_arg(wdg_list, int); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
68 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
69 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
70 |
va_end(wdg_list); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
71 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
72 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
73 |
void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...) |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
74 |
{ |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
75 |
va_list wdg_list; |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
76 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
77 |
va_start(wdg_list, widgets); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
78 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
79 |
while (widgets != WIDGET_LIST_END) { |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
80 |
SetWidgetLoweredState(widgets, lowered_stat); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
81 |
widgets = va_arg(wdg_list, int); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
82 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
83 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
84 |
va_end(wdg_list); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
85 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
86 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
87 |
void Window::RaiseButtons() |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
88 |
{ |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
89 |
uint i; |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
90 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
91 |
for (i = 0; i < this->widget_count; i++) { |
8528
04b4ef9abd9b
(svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents:
8527
diff
changeset
|
92 |
if (this->IsWidgetLowered(i)) { |
04b4ef9abd9b
(svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents:
8527
diff
changeset
|
93 |
this->RaiseWidget(i); |
04b4ef9abd9b
(svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents:
8527
diff
changeset
|
94 |
this->InvalidateWidget(i); |
8489
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
95 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
96 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
97 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
98 |
|
8522
a1c44311e09e
(svn r11586) -Fix: make another widget 'accessor' function const when it should be const.
glx
parents:
8519
diff
changeset
|
99 |
void Window::InvalidateWidget(byte widget_index) const |
8489
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
100 |
{ |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
101 |
const Widget *wi = &this->widget[widget_index]; |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
102 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
103 |
/* Don't redraw the window if the widget is invisible or of no-type */ |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
104 |
if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return; |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
105 |
|
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
106 |
SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1); |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
107 |
} |
1e2a5fdb152f
(svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents:
8450
diff
changeset
|
108 |
|
8531
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
109 |
void Window::HandleButtonClick(byte widget) |
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
110 |
{ |
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
111 |
this->LowerWidget(widget); |
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
112 |
this->flags4 |= 5 << WF_TIMEOUT_SHL; |
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
113 |
this->InvalidateWidget(widget); |
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
114 |
} |
e87a51f162e2
(svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents:
8529
diff
changeset
|
115 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
116 |
static void StartWindowDrag(Window *w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
117 |
static void StartWindowSizing(Window *w); |
2817 | 118 |
|
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
119 |
static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click) |
2596 | 120 |
{ |
0 | 121 |
WindowEvent e; |
122 |
const Widget *wi; |
|
123 |
||
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
124 |
e.we.click.pt.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
125 |
e.we.click.pt.y = y; |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
126 |
e.event = double_click ? WE_DOUBLE_CLICK : WE_CLICK; |
0 | 127 |
|
128 |
if (w->desc_flags & WDF_DEF_WIDGET) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
129 |
e.we.click.widget = GetWidgetFromPos(w, x, y); |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
130 |
if (e.we.click.widget < 0) return; // exit if clicked outside of widgets |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
131 |
|
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
132 |
/* don't allow any interaction if the button has been disabled */ |
8493
3ab458f7cff4
(svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents:
8489
diff
changeset
|
133 |
if (w->IsWidgetDisabled(e.we.click.widget)) return; |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
211
diff
changeset
|
134 |
|
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
135 |
wi = &w->widget[e.we.click.widget]; |
0 | 136 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
137 |
if (wi->type & WWB_MASK) { |
211 | 138 |
/* special widget handling for buttons*/ |
2952 | 139 |
switch (wi->type) { |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
140 |
case WWT_PANEL | WWB_PUSHBUTTON: /* WWT_PUSHBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
141 |
case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
142 |
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ |
8532
3099f32f9bfd
(svn r11596) -Codechange: Use the Window member HandleButtonClick and remove its now useless counterpart function
belugas
parents:
8531
diff
changeset
|
143 |
w->HandleButtonClick(e.we.click.widget); |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
144 |
break; |
0 | 145 |
} |
842 | 146 |
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
147 |
ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y); |
0 | 148 |
} |
149 |
||
150 |
if (w->desc_flags & WDF_STD_BTN) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
151 |
if (e.we.click.widget == 0) { /* 'X' */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
152 |
DeleteWindow(w); |
984
a50e131688d2
(svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents:
983
diff
changeset
|
153 |
return; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
154 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
155 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
156 |
if (e.we.click.widget == 1) { /* 'Title bar' */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
157 |
StartWindowDrag(w); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
158 |
return; |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
159 |
} |
0 | 160 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
161 |
|
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
162 |
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
163 |
StartWindowSizing(w); |
8524
baf4ab1ba18d
(svn r11588) -Codechange: use the new member introduced in r11551
glx
parents:
8522
diff
changeset
|
164 |
w->InvalidateWidget(e.we.click.widget); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
165 |
return; |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
166 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
167 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
168 |
if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
169 |
w->flags4 ^= WF_STICKY; |
8524
baf4ab1ba18d
(svn r11588) -Codechange: use the new member introduced in r11551
glx
parents:
8522
diff
changeset
|
170 |
w->InvalidateWidget(e.we.click.widget); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
171 |
return; |
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
172 |
} |
0 | 173 |
} |
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
174 |
|
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
175 |
w->wndproc(w, &e); |
0 | 176 |
} |
177 |
||
4171 | 178 |
static void DispatchRightClickEvent(Window *w, int x, int y) |
2596 | 179 |
{ |
0 | 180 |
WindowEvent e; |
181 |
||
182 |
/* default tooltips handler? */ |
|
183 |
if (w->desc_flags & WDF_STD_TOOLTIPS) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
184 |
e.we.click.widget = GetWidgetFromPos(w, x, y); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
185 |
if (e.we.click.widget < 0) |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
186 |
return; // exit if clicked outside of widgets |
0 | 187 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
188 |
if (w->widget[e.we.click.widget].tooltips != 0) { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
189 |
GuiShowTooltips(w->widget[e.we.click.widget].tooltips); |
0 | 190 |
return; |
191 |
} |
|
192 |
} |
|
193 |
||
194 |
e.event = WE_RCLICK; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
195 |
e.we.click.pt.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
196 |
e.we.click.pt.y = y; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
197 |
w->wndproc(w, &e); |
0 | 198 |
} |
199 |
||
2021
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
200 |
/** Dispatch the mousewheel-action to the window which will scroll any |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
201 |
* compatible scrollbars if the mouse is pointed over the bar or its contents |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
202 |
* @param *w Window |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
203 |
* @param widget the widget where the scrollwheel was used |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
204 |
* @param wheel scroll up or down |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
205 |
*/ |
4171 | 206 |
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel) |
0 | 207 |
{ |
2021
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
208 |
const Widget *wi1, *wi2; |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
209 |
Scrollbar *sb; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
210 |
|
2021
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
211 |
if (widget < 0) return; |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
212 |
|
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
213 |
wi1 = &w->widget[widget]; |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
214 |
wi2 = &w->widget[widget + 1]; |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
215 |
|
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
216 |
/* The listbox can only scroll if scrolling was done on the scrollbar itself, |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
217 |
* or on the listbox (and the next item is (must be) the scrollbar) |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
218 |
* XXX - should be rewritten as a widget-dependent scroller but that's |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
219 |
* not happening until someone rewrites the whole widget-code */ |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
220 |
if ((sb = &w->vscroll, wi1->type == WWT_SCROLLBAR) || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR) || |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
221 |
(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
222 |
|
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
223 |
if (sb->count > sb->cap) { |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8414
diff
changeset
|
224 |
int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap); |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
225 |
if (pos != sb->pos) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
226 |
sb->pos = pos; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
227 |
SetWindowDirty(w); |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
228 |
} |
0 | 229 |
} |
230 |
} |
|
231 |
} |
|
232 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
233 |
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom); |
2817 | 234 |
|
0 | 235 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) |
236 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
237 |
Window* const *wz; |
0 | 238 |
DrawPixelInfo bk; |
239 |
_cur_dpi = &bk; |
|
240 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
241 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
242 |
const Window *w = *wz; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
243 |
if (right > w->left && |
0 | 244 |
bottom > w->top && |
245 |
left < w->left + w->width && |
|
246 |
top < w->top + w->height) { |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
247 |
DrawOverlappedWindow(wz, left, top, right, bottom); |
2639 | 248 |
} |
0 | 249 |
} |
250 |
} |
|
251 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
252 |
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom) |
0 | 253 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
254 |
Window* const *vz = wz; |
0 | 255 |
int x; |
256 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
257 |
while (++vz != _last_z_window) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
258 |
const Window *v = *vz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
259 |
|
0 | 260 |
if (right > v->left && |
2026 | 261 |
bottom > v->top && |
0 | 262 |
left < v->left + v->width && |
263 |
top < v->top + v->height) { |
|
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
264 |
if (left < (x = v->left)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
265 |
DrawOverlappedWindow(wz, left, top, x, bottom); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
266 |
DrawOverlappedWindow(wz, x, top, right, bottom); |
0 | 267 |
return; |
268 |
} |
|
269 |
||
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
270 |
if (right > (x = v->left + v->width)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
271 |
DrawOverlappedWindow(wz, left, top, x, bottom); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
272 |
DrawOverlappedWindow(wz, x, top, right, bottom); |
0 | 273 |
return; |
274 |
} |
|
275 |
||
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
276 |
if (top < (x = v->top)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
277 |
DrawOverlappedWindow(wz, left, top, right, x); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
278 |
DrawOverlappedWindow(wz, left, x, right, bottom); |
0 | 279 |
return; |
280 |
} |
|
281 |
||
6987
b0f13039bda2
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6977
diff
changeset
|
282 |
if (bottom > (x = v->top + v->height)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
283 |
DrawOverlappedWindow(wz, left, top, right, x); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
284 |
DrawOverlappedWindow(wz, left, x, right, bottom); |
0 | 285 |
return; |
286 |
} |
|
287 |
||
288 |
return; |
|
289 |
} |
|
290 |
} |
|
291 |
||
292 |
{ |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
293 |
DrawPixelInfo *dp = _cur_dpi; |
0 | 294 |
dp->width = right - left; |
295 |
dp->height = bottom - top; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
296 |
dp->left = left - (*wz)->left; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
297 |
dp->top = top - (*wz)->top; |
0 | 298 |
dp->pitch = _screen.pitch; |
7433
8e410e7ec0d7
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
7374
diff
changeset
|
299 |
dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top); |
7120
e31767effc16
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
7028
diff
changeset
|
300 |
dp->zoom = ZOOM_LVL_NORMAL; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
301 |
CallWindowEventNP(*wz, WE_PAINT); |
0 | 302 |
} |
303 |
} |
|
304 |
||
305 |
void CallWindowEventNP(Window *w, int event) |
|
306 |
{ |
|
307 |
WindowEvent e; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
308 |
|
0 | 309 |
e.event = event; |
310 |
w->wndproc(w, &e); |
|
311 |
} |
|
312 |
||
4171 | 313 |
void SetWindowDirty(const Window *w) |
0 | 314 |
{ |
2549 | 315 |
if (w == NULL) return; |
0 | 316 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); |
317 |
} |
|
318 |
||
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
319 |
/** Find the Window whose parent pointer points to this window |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
320 |
* @param w parent Window to find child of |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
321 |
* @return a Window pointer that is the child of w, or NULL otherwise */ |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
322 |
static Window *FindChildWindow(const Window *w) |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
323 |
{ |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
324 |
Window* const *wz; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
325 |
|
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
326 |
FOR_ALL_WINDOWS(wz) { |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
327 |
Window *v = *wz; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
328 |
if (v->parent == w) return v; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
329 |
} |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
330 |
|
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
331 |
return NULL; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
332 |
} |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
333 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
334 |
/** Find the z-value of a window. A window must already be open |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
335 |
* or the behaviour is undefined but function should never fail |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
336 |
* @param w window to query Z Position |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
337 |
* @return the window that matches it */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
338 |
Window **FindWindowZPosition(const Window *w) |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
339 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
340 |
Window **wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
341 |
|
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
342 |
for (wz = _z_windows; wz != _last_z_window; wz++) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
343 |
if (*wz == w) return wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
344 |
} |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
345 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
346 |
DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls", |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
347 |
w->window_class, w->window_number); |
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
348 |
return NULL; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
349 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
350 |
|
0 | 351 |
void DeleteWindow(Window *w) |
352 |
{ |
|
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
353 |
Window *v; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
354 |
Window **wz; |
2639 | 355 |
if (w == NULL) return; |
0 | 356 |
|
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
357 |
/* Delete any children a window might have in a head-recursive manner */ |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
358 |
v = FindChildWindow(w); |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
359 |
if (v != NULL) DeleteWindow(v); |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
360 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
361 |
if (_thd.place_mode != VHM_NONE && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
362 |
_thd.window_class == w->window_class && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
363 |
_thd.window_number == w->window_number) { |
0 | 364 |
ResetObjectToPlace(); |
365 |
} |
|
366 |
||
367 |
CallWindowEventNP(w, WE_DESTROY); |
|
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5121
diff
changeset
|
368 |
if (w->viewport != NULL) DeleteWindowViewport(w); |
0 | 369 |
|
370 |
SetWindowDirty(w); |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
371 |
free(w->widget); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
372 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
373 |
w->widget_count = 0; |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
374 |
w->parent = NULL; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
375 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
376 |
/* Find the window in the z-array, and effectively remove it |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
377 |
* by moving all windows after it one to the left */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
378 |
wz = FindWindowZPosition(w); |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
379 |
if (wz == NULL) return; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
380 |
memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
381 |
_last_z_window--; |
0 | 382 |
} |
383 |
||
384 |
Window *FindWindowById(WindowClass cls, WindowNumber number) |
|
385 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
386 |
Window* const *wz; |
0 | 387 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
388 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
389 |
Window *w = *wz; |
2639 | 390 |
if (w->window_class == cls && w->window_number == number) return w; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
391 |
} |
0 | 392 |
|
393 |
return NULL; |
|
394 |
} |
|
395 |
||
396 |
void DeleteWindowById(WindowClass cls, WindowNumber number) |
|
397 |
{ |
|
398 |
DeleteWindow(FindWindowById(cls, number)); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
399 |
} |
0 | 400 |
|
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
401 |
void DeleteWindowByClass(WindowClass cls) |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
402 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
403 |
Window* const *wz; |
2639 | 404 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
405 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
406 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
407 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
408 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
409 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
410 |
Window *w = *wz; |
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
411 |
if (w->window_class == cls) { |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
412 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
413 |
goto restart_search; |
2639 | 414 |
} |
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
415 |
} |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
416 |
} |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
417 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
418 |
/** Delete all windows of a player. We identify windows of a player |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
419 |
* by looking at the caption colour. If it is equal to the player ID |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
420 |
* then we say the window belongs to the player and should be deleted |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
421 |
* @param id PlayerID player identifier */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
422 |
void DeletePlayerWindows(PlayerID id) |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
423 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
424 |
Window* const *wz; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
425 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
426 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
427 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
428 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
429 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
430 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
431 |
Window *w = *wz; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
432 |
if (w->caption_color == id) { |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
433 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
434 |
goto restart_search; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
435 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
436 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
437 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
438 |
/* Also delete the player specific windows, that don't have a player-colour */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
439 |
DeleteWindowById(WC_BUY_COMPANY, id); |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
440 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
441 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
442 |
/** Change the owner of all the windows one player can take over from another |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
443 |
* player in the case of a company merger. Do not change ownership of windows |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
444 |
* that need to be deleted once takeover is complete |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
445 |
* @param old_player PlayerID of original owner of the window |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
446 |
* @param new_player PlayerID of the new owner of the window */ |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
447 |
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player) |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
448 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
449 |
Window* const *wz; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
450 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
451 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
452 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
453 |
|
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
454 |
if (w->caption_color != old_player) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
455 |
if (w->window_class == WC_PLAYER_COLOR) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
456 |
if (w->window_class == WC_FINANCES) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
457 |
if (w->window_class == WC_STATION_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
458 |
if (w->window_class == WC_TRAINS_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
459 |
if (w->window_class == WC_ROADVEH_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
460 |
if (w->window_class == WC_SHIPS_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
461 |
if (w->window_class == WC_AIRCRAFT_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
462 |
if (w->window_class == WC_BUY_COMPANY) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
463 |
if (w->window_class == WC_COMPANY) continue; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
464 |
|
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
465 |
w->caption_color = new_player; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
466 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
467 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
468 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
469 |
static void BringWindowToFront(const Window *w); |
2817 | 470 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
471 |
/** Find a window and make it the top-window on the screen. The window |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
472 |
* gets a white border for a brief period of time to visualize its "activation" |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
473 |
* @param cls WindowClass of the window to activate |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
474 |
* @param number WindowNumber of the window to activate |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
475 |
* @return a pointer to the window thus activated */ |
0 | 476 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number) |
477 |
{ |
|
478 |
Window *w = FindWindowById(cls, number); |
|
479 |
||
480 |
if (w != NULL) { |
|
481 |
w->flags4 |= WF_WHITE_BORDER_MASK; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
482 |
BringWindowToFront(w); |
0 | 483 |
SetWindowDirty(w); |
484 |
} |
|
485 |
||
486 |
return w; |
|
487 |
} |
|
488 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
489 |
static inline bool IsVitalWindow(const Window *w) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
490 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
491 |
WindowClass wc = w->window_class; |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
492 |
return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
493 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
494 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
495 |
/** On clicking on a window, make it the frontmost window of all. However |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
496 |
* there are certain windows that always need to be on-top; these include |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
497 |
* - Toolbar, Statusbar (always on) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
498 |
* - New window, Chatbar (only if open) |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
499 |
* The window is marked dirty for a repaint if the window is actually moved |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
500 |
* @param w window that is put into the foreground |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
501 |
* @return pointer to the window, the same as the input pointer |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
502 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
503 |
static void BringWindowToFront(const Window *w) |
0 | 504 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
505 |
Window *tempz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
506 |
Window **wz = FindWindowZPosition(w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
507 |
Window **vz = _last_z_window; |
0 | 508 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
509 |
/* Bring the window just below the vital windows */ |
0 | 510 |
do { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
511 |
if (--vz < _z_windows) return; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
512 |
} while (IsVitalWindow(*vz)); |
0 | 513 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
514 |
if (wz == vz) return; // window is already in the right position |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
515 |
assert(wz < vz); |
0 | 516 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
517 |
tempz = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
518 |
memmove(wz, wz + 1, (byte*)vz - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
519 |
*vz = tempz; |
0 | 520 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
521 |
SetWindowDirty(w); |
0 | 522 |
} |
523 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
524 |
/** We have run out of windows, so find a suitable candidate for replacement. |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
525 |
* Keep all important windows intact. These are |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
526 |
* - Main window (gamefield), Toolbar, Statusbar (always on) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
527 |
* - News window, Chatbar (when on) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
528 |
* - Any sticked windows since we wanted to keep these |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
529 |
* @return w pointer to the window that is going to be deleted |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
530 |
*/ |
6573 | 531 |
static Window *FindDeletableWindow() |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
532 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
533 |
Window* const *wz; |
2639 | 534 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
535 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
536 |
Window *w = *wz; |
2639 | 537 |
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) { |
538 |
return w; |
|
539 |
} |
|
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
540 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
541 |
return NULL; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
542 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
543 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
544 |
/** A window must be freed, and all are marked as important windows. Ease the |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
545 |
* restriction a bit by allowing to delete sticky windows. Keep important/vital |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
546 |
* windows intact (Main window, Toolbar, Statusbar, News Window, Chatbar) |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
547 |
* Start finding an appropiate candidate from the lowest z-values (bottom) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
548 |
* @see FindDeletableWindow() |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
549 |
* @return w Pointer to the window that is being deleted |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
550 |
*/ |
6573 | 551 |
static Window *ForceFindDeletableWindow() |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
552 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
553 |
Window* const *wz; |
2639 | 554 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
555 |
for (wz = _z_windows;; wz++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
556 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
557 |
assert(wz < _last_z_window); |
2639 | 558 |
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w; |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
559 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
560 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
561 |
|
4171 | 562 |
bool IsWindowOfPrototype(const Window *w, const Widget *widget) |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
563 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
564 |
return (w->original_widget == widget); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
565 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
566 |
|
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
567 |
/** Copies 'widget' to 'w->widget' to allow for resizable windows |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
568 |
* @param w Window on which to attach the widget array |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
569 |
* @param widget pointer of widget array to fill the window with */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
570 |
void AssignWidgetToWindow(Window *w, const Widget *widget) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
571 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
572 |
w->original_widget = widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
573 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
574 |
if (widget != NULL) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
575 |
uint index = 1; |
4171 | 576 |
const Widget *wi; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
577 |
|
2639 | 578 |
for (wi = widget; wi->type != WWT_LAST; wi++) index++; |
579 |
||
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
580 |
w->widget = ReallocT(w->widget, index); |
2639 | 581 |
memcpy(w->widget, widget, sizeof(*w->widget) * index); |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
582 |
w->widget_count = index - 1; |
2639 | 583 |
} else { |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
584 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
585 |
w->widget_count = 0; |
2639 | 586 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
587 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
588 |
|
6573 | 589 |
static Window *FindFreeWindow() |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
590 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
591 |
Window *w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
592 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
593 |
for (w = _windows; w < endof(_windows); w++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
594 |
Window* const *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
595 |
bool window_in_use = false; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
596 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
597 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
598 |
if (*wz == w) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
599 |
window_in_use = true; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
600 |
break; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
601 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
602 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
603 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
604 |
if (!window_in_use) return w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
605 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
606 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
607 |
assert(_last_z_window == endof(_z_windows)); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
608 |
return NULL; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
609 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
610 |
|
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
611 |
/** Open a new window. |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
612 |
* This function is called from AllocateWindow() or AllocateWindowDesc() |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
613 |
* See descriptions for those functions for usage |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
614 |
* See AllocateWindow() for description of arguments. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
615 |
* Only addition here is window_number, which is the window_number being assigned to the new window |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
616 |
* @param x offset in pixels from the left of the screen |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
617 |
* @param y offset in pixels from the top of the screen |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
618 |
* @param min_width minimum width in pixels of the window |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
619 |
* @param min_height minimum height in pixels of the window |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
620 |
* @param def_width default width in pixels of the window |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
621 |
* @param def_height default height in pixels of the window |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
622 |
* @param *proc see WindowProc function to call when any messages/updates happen to the window |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
623 |
* @param cls see WindowClass class of the window, used for identification and grouping |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
624 |
* @param *widget see Widget pointer to the window layout and various elements |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
625 |
* @param window_number number being assigned to the new window |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
626 |
* @param data the data to be given during the WE_CREATE message |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
627 |
* @return Window pointer of the newly created window */ |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
628 |
static Window *LocalAllocateWindow( |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
629 |
int x, int y, int min_width, int min_height, int def_width, int def_height, |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
630 |
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data) |
0 | 631 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
632 |
Window *w = FindFreeWindow(); |
0 | 633 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
634 |
/* We have run out of windows, close one and use that as the place for our new one */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
635 |
if (w == NULL) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
636 |
w = FindDeletableWindow(); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
637 |
if (w == NULL) w = ForceFindDeletableWindow(); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
638 |
DeleteWindow(w); |
0 | 639 |
} |
640 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
641 |
/* Set up window properties */ |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
642 |
memset(w, 0, sizeof(*w)); |
0 | 643 |
w->window_class = cls; |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
644 |
w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border |
0 | 645 |
w->caption_color = 0xFF; |
646 |
w->left = x; |
|
647 |
w->top = y; |
|
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
648 |
w->width = min_width; |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
649 |
w->height = min_height; |
0 | 650 |
w->wndproc = proc; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
651 |
AssignWidgetToWindow(w, widget); |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
652 |
w->resize.width = min_width; |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
653 |
w->resize.height = min_height; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
654 |
w->resize.step_width = 1; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
655 |
w->resize.step_height = 1; |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
656 |
w->window_number = window_number; |
0 | 657 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
658 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
659 |
Window **wz = _last_z_window; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
660 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
661 |
/* Hacky way of specifying always-on-top windows. These windows are |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
662 |
* always above other windows because they are moved below them. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
663 |
* status-bar is above news-window because it has been created earlier. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
664 |
* Also, as the chat-window is excluded from this, it will always be |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
665 |
* the last window, thus always on top. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
666 |
* XXX - Yes, ugly, probably needs something like w->always_on_top flag |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
667 |
* to implement correctly, but even then you need some kind of distinction |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
668 |
* between on-top of chat/news and status windows, because these conflict */ |
7564
2c73e371df89
(svn r10333) -Fix [FS#943]: News messages were shown on top of the endgame screen and high score chart.
rubidium
parents:
7514
diff
changeset
|
669 |
if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG && w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
670 |
if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
671 |
if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
672 |
if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
673 |
if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
674 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
675 |
assert(wz >= _z_windows); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
676 |
if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
677 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
678 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
679 |
*wz = w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
680 |
_last_z_window++; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
681 |
} |
0 | 682 |
|
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
683 |
WindowEvent e; |
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
684 |
e.event = WE_CREATE; |
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
685 |
e.we.create.data = data; |
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
686 |
w->wndproc(w, &e); |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
687 |
|
7849
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
688 |
/* Try to make windows smaller when our window is too small. |
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
689 |
* w->(width|height) is normally the same as min_(width|height), |
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
690 |
* but this way the GUIs can be made a little more dynamic; |
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
691 |
* one can use the same spec for multiple windows and those |
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
692 |
* can then determine the real minimum size of the window. */ |
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
693 |
if (w->width != def_width || w->height != def_height) { |
7840
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
694 |
/* Think about the overlapping toolbars when determining the minimum window size */ |
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
695 |
int free_height = _screen.height; |
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
696 |
const Window *wt = FindWindowById(WC_STATUS_BAR, 0); |
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
697 |
if (wt != NULL) free_height -= wt->height; |
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
698 |
wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
699 |
if (wt != NULL) free_height -= wt->height; |
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
700 |
|
7849
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
701 |
int enlarge_x = max(min(def_width - w->width, _screen.width - w->width), 0); |
eafce07e8f96
(svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents:
7840
diff
changeset
|
702 |
int enlarge_y = max(min(def_height - w->height, free_height - w->height), 0); |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
703 |
|
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
704 |
/* X and Y has to go by step.. calculate it. |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
705 |
* The cast to int is necessary else x/y are implicitly casted to |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
706 |
* unsigned int, which won't work. */ |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
707 |
if (w->resize.step_width > 1) enlarge_x -= enlarge_x % (int)w->resize.step_width; |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
708 |
if (w->resize.step_height > 1) enlarge_y -= enlarge_y % (int)w->resize.step_height; |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
709 |
|
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
710 |
ResizeWindow(w, enlarge_x, enlarge_y); |
7838
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
711 |
|
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
712 |
WindowEvent e; |
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
713 |
e.event = WE_RESIZE; |
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
714 |
e.we.sizing.size.x = w->width; |
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
715 |
e.we.sizing.size.y = w->height; |
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
716 |
e.we.sizing.diff.x = enlarge_x; |
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
717 |
e.we.sizing.diff.y = enlarge_y; |
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
718 |
w->wndproc(w, &e); |
7840
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
719 |
} |
7838
539b4d33ce87
(svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents:
7837
diff
changeset
|
720 |
|
7960
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
721 |
int nx = w->left; |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
722 |
int ny = w->top; |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
723 |
|
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
724 |
if (nx + w->width > _screen.width) nx -= (nx + w->width - _screen.width); |
7860
b2a4bed111b6
(svn r10727) -Codechange: when a window would fall outside of the screen (on the right) when opening it, move it to the left so it stays inside the screen.
rubidium
parents:
7859
diff
changeset
|
725 |
|
7840
0878bbe3d39a
(svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents:
7838
diff
changeset
|
726 |
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
7960
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
727 |
ny = max(ny, (wt == NULL || w == wt || y == 0) ? 0 : wt->height); |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
728 |
nx = max(nx, 0); |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
729 |
|
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
730 |
if (w->viewport != NULL) { |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
731 |
w->viewport->left += nx - w->left; |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
732 |
w->viewport->top += ny - w->top; |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
733 |
} |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
734 |
w->left = nx; |
af0f10d86051
(svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents:
7950
diff
changeset
|
735 |
w->top = ny; |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
736 |
|
0 | 737 |
SetWindowDirty(w); |
738 |
||
739 |
return w; |
|
740 |
} |
|
741 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
742 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
743 |
* Open a new window. If there is no space for a new window, close an open |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
744 |
* window. Try to avoid stickied windows, but if there is no else, close one of |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
745 |
* those as well. Then make sure all created windows are below some always-on-top |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
746 |
* ones. Finally set all variables and call the WE_CREATE event |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
747 |
* @param x offset in pixels from the left of the screen |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
748 |
* @param y offset in pixels from the top of the screen |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
749 |
* @param width width in pixels of the window |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
750 |
* @param height height in pixels of the window |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
751 |
* @param *proc see WindowProc function to call when any messages/updates happen to the window |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
752 |
* @param cls see WindowClass class of the window, used for identification and grouping |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
753 |
* @param *widget see Widget pointer to the window layout and various elements |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
754 |
* @return Window pointer of the newly created window */ |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
755 |
Window *AllocateWindow( |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
756 |
int x, int y, int width, int height, |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
757 |
WindowProc *proc, WindowClass cls, const Widget *widget, void *data) |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
758 |
{ |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
759 |
return LocalAllocateWindow(x, y, width, height, width, height, proc, cls, widget, 0, data); |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
760 |
} |
0 | 761 |
|
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
762 |
struct SizeRect { |
0 | 763 |
int left,top,width,height; |
6574
e1d1a12faaf7
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6573
diff
changeset
|
764 |
}; |
0 | 765 |
|
766 |
||
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
767 |
static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos) |
0 | 768 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
769 |
Window* const *wz; |
0 | 770 |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
771 |
int right = width + left; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
772 |
int bottom = height + top; |
0 | 773 |
|
774 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
|
775 |
return false; |
|
776 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
777 |
/* Make sure it is not obscured by any window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
778 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
779 |
const Window *w = *wz; |
2639 | 780 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 781 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
782 |
if (right > w->left && |
2639 | 783 |
w->left + w->width > left && |
0 | 784 |
bottom > w->top && |
2639 | 785 |
w->top + w->height > top) { |
786 |
return false; |
|
787 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
788 |
} |
0 | 789 |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
790 |
pos.x = left; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
791 |
pos.y = top; |
0 | 792 |
return true; |
793 |
} |
|
794 |
||
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
795 |
static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos) |
0 | 796 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
797 |
Window* const *wz; |
0 | 798 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
799 |
if (left < -(width>>2) || left > _screen.width - (width>>1)) return false; |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
800 |
if (top < 22 || top > _screen.height - (height>>2)) return false; |
0 | 801 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
802 |
/* Make sure it is not obscured by any window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
803 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
804 |
const Window *w = *wz; |
2639 | 805 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 806 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
807 |
if (left + width > w->left && |
2639 | 808 |
w->left + w->width > left && |
0 | 809 |
top + height > w->top && |
2639 | 810 |
w->top + w->height > top) { |
811 |
return false; |
|
812 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
813 |
} |
0 | 814 |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
815 |
pos.x = left; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
816 |
pos.y = top; |
0 | 817 |
return true; |
818 |
} |
|
819 |
||
1095 | 820 |
static Point GetAutoPlacePosition(int width, int height) |
821 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
822 |
Window* const *wz; |
0 | 823 |
Point pt; |
824 |
||
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
825 |
if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt; |
0 | 826 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
827 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
828 |
const Window *w = *wz; |
2639 | 829 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 830 |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
831 |
if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
832 |
if (IsGoodAutoPlace1(w->left - width - 2, w->top, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
833 |
if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
834 |
if (IsGoodAutoPlace1(w->left, w->top - height - 2, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
835 |
if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
836 |
if (IsGoodAutoPlace1(w->left - width - 2, w->top + w->height - height, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
837 |
if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
838 |
if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2, width, height, pt)) return pt; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
839 |
} |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
840 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
841 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
842 |
const Window *w = *wz; |
2639 | 843 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 844 |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
845 |
if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
846 |
if (IsGoodAutoPlace2(w->left - width - 2, w->top, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
847 |
if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
848 |
if (IsGoodAutoPlace2(w->left, w->top - height - 2, width, height, pt)) return pt; |
0 | 849 |
} |
850 |
||
851 |
{ |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
852 |
int left = 0, top = 24; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
853 |
|
7028
bca7019b2210
(svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents:
6988
diff
changeset
|
854 |
restart: |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
855 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
856 |
const Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
857 |
|
0 | 858 |
if (w->left == left && w->top == top) { |
859 |
left += 5; |
|
860 |
top += 5; |
|
861 |
goto restart; |
|
862 |
} |
|
863 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
864 |
|
0 | 865 |
pt.x = left; |
866 |
pt.y = top; |
|
867 |
return pt; |
|
868 |
} |
|
869 |
} |
|
870 |
||
8217
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
871 |
/** |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
872 |
* Set the x and y coordinates of a new window. |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
873 |
* |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
874 |
* @param *desc The pointer to the WindowDesc to be created |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
875 |
* @param window_number the window number of the new window |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
876 |
* @param data arbitrary data that is send with the WE_CREATE message |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
877 |
* |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
878 |
* @return see Window pointer of the newly created window |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
879 |
*/ |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
880 |
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data) |
0 | 881 |
{ |
882 |
Point pt; |
|
883 |
Window *w; |
|
884 |
||
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
885 |
/* By default position a child window at an offset of 10/10 of its parent. |
8217
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
886 |
* With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports) |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
887 |
* and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of |
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
888 |
* its parent. So it's exactly under the parent toolbar and no buttons will be covered. |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
889 |
* However if it falls too extremely outside window positions, reposition |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
890 |
* it to an automatic place */ |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
891 |
if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ && |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
892 |
(w = FindWindowById(desc->parent_cls, window_number)) != NULL && |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
893 |
w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) { |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
894 |
|
8217
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
895 |
pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10); |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
896 |
if (pt.x > _screen.width + 10 - desc->default_width) { |
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
897 |
pt.x = (_screen.width + 10 - desc->default_width) - 20; |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
898 |
} |
8217
ce7255c36b9e
(svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents:
7960
diff
changeset
|
899 |
pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10); |
0 | 900 |
} else { |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
901 |
switch (desc->left) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
902 |
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
903 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
904 |
pt.x = (w->left + w->width) - desc->default_width; |
6988
76eba6a9cc6f
(svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents:
6987
diff
changeset
|
905 |
} break; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
906 |
case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
907 |
pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
908 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
909 |
case WDP_AUTO: /* Find a good automatic position for the window */ |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
910 |
pt = GetAutoPlacePosition(desc->default_width, desc->default_height); |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
911 |
goto allocate_window; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
912 |
case WDP_CENTER: /* Centre the window horizontally */ |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
913 |
pt.x = (_screen.width - desc->default_width) / 2; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
914 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
915 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
916 |
pt.x = desc->left; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
917 |
if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
918 |
} |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
919 |
|
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
920 |
switch (desc->top) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
921 |
case WDP_CENTER: /* Centre the window vertically */ |
7837
65d7362153a6
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7797
diff
changeset
|
922 |
pt.y = (_screen.height - desc->default_height) / 2; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
923 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
924 |
/* WDP_AUTO sets the position at once and is controlled by desc->left. |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
925 |
* Both left and top must be set to WDP_AUTO */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
926 |
case WDP_AUTO: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
927 |
NOT_REACHED(); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
928 |
assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
929 |
/* fallthrough */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
930 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
931 |
pt.y = desc->top; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
932 |
if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
933 |
break; |
0 | 934 |
} |
935 |
} |
|
936 |
||
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
937 |
allocate_window: |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
938 |
w = LocalAllocateWindow(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data); |
0 | 939 |
w->desc_flags = desc->flags; |
940 |
return w; |
|
941 |
} |
|
942 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
943 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
944 |
* Open a new window. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
945 |
* @param *desc The pointer to the WindowDesc to be created |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
946 |
* @param data arbitrary data that is send with the WE_CREATE message |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
947 |
* @return Window pointer of the newly created window |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
948 |
*/ |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
949 |
Window *AllocateWindowDesc(const WindowDesc *desc, void *data) |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
950 |
{ |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
951 |
return LocalAllocateWindowDesc(desc, 0, data); |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
952 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
953 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
954 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
955 |
* Open a new window. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
956 |
* @param *desc The pointer to the WindowDesc to be created |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
957 |
* @param window_number the window number of the new window |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
958 |
* @param data arbitrary data that is send with the WE_CREATE message |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
959 |
* @return see Window pointer of the newly created window |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
960 |
*/ |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
961 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data) |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
962 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
963 |
Window *w; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
964 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
965 |
if (BringWindowToFrontById(desc->cls, window_number)) return NULL; |
7863
cc5dcf5c8ed4
(svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents:
7860
diff
changeset
|
966 |
w = LocalAllocateWindowDesc(desc, window_number, data); |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
967 |
return w; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
968 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
969 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
970 |
/** Do a search for a window at specific coordinates. For this we start |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
971 |
* at the topmost window, obviously and work our way down to the bottom |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
972 |
* @param x position x to query |
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
973 |
* @param y position y to query |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
974 |
* @return a pointer to the found window if any, NULL otherwise */ |
0 | 975 |
Window *FindWindowFromPt(int x, int y) |
976 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
977 |
Window* const *wz; |
0 | 978 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
979 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
980 |
Window *w = *--wz; |
8450
dce58137301f
(svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents:
8424
diff
changeset
|
981 |
if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) { |
2639 | 982 |
return w; |
983 |
} |
|
0 | 984 |
} |
985 |
||
986 |
return NULL; |
|
987 |
} |
|
988 |
||
6573 | 989 |
void InitWindowSystem() |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
990 |
{ |
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
991 |
IConsoleClose(); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
992 |
|
0 | 993 |
memset(&_windows, 0, sizeof(_windows)); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
994 |
_last_z_window = _z_windows; |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5121
diff
changeset
|
995 |
InitViewports(); |
1397
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1299
diff
changeset
|
996 |
_no_scroll = 0; |
0 | 997 |
} |
998 |
||
6573 | 999 |
void UnInitWindowSystem() |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1000 |
{ |
5664 | 1001 |
Window **wz; |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1002 |
|
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1003 |
restart_search: |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1004 |
/* Delete all windows, reset z-array. |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1005 |
*When we find the window to delete, we need to restart the search |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1006 |
* as deleting this window could cascade in deleting (many) others |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1007 |
* anywhere in the z-array. We call DeleteWindow() so that it can properly |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1008 |
* release own alloc'd memory, which otherwise could result in memleaks */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1009 |
FOR_ALL_WINDOWS(wz) { |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1010 |
DeleteWindow(*wz); |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1011 |
goto restart_search; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1012 |
} |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1013 |
|
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1014 |
assert(_last_z_window == _z_windows); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1015 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1016 |
|
6573 | 1017 |
void ResetWindowSystem() |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1018 |
{ |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1019 |
UnInitWindowSystem(); |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1020 |
InitWindowSystem(); |
1744
1677a99b0daf
(svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents:
1737
diff
changeset
|
1021 |
_thd.pos.x = 0; |
1677a99b0daf
(svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents:
1737
diff
changeset
|
1022 |
_thd.pos.y = 0; |
2877
c307d8f60e48
(svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents:
2817
diff
changeset
|
1023 |
_thd.new_pos.x = 0; |
c307d8f60e48
(svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents:
2817
diff
changeset
|
1024 |
_thd.new_pos.y = 0; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1025 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1026 |
|
6573 | 1027 |
static void DecreaseWindowCounters() |
0 | 1028 |
{ |
1029 |
Window *w; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1030 |
Window* const *wz; |
0 | 1031 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1032 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1033 |
w = *--wz; |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1034 |
/* Unclick scrollbar buttons if they are pressed. */ |
0 | 1035 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { |
1036 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); |
|
1037 |
SetWindowDirty(w); |
|
1038 |
} |
|
1039 |
CallWindowEventNP(w, WE_MOUSELOOP); |
|
1040 |
} |
|
1041 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1042 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1043 |
w = *--wz; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1044 |
|
0 | 1045 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { |
1046 |
CallWindowEventNP(w, WE_TIMEOUT); |
|
8528
04b4ef9abd9b
(svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents:
8527
diff
changeset
|
1047 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons(); |
0 | 1048 |
} |
1049 |
} |
|
1050 |
} |
|
1051 |
||
6573 | 1052 |
Window *GetCallbackWnd() |
0 | 1053 |
{ |
1054 |
return FindWindowById(_thd.window_class, _thd.window_number); |
|
1055 |
} |
|
1056 |
||
6573 | 1057 |
static void HandlePlacePresize() |
0 | 1058 |
{ |
1059 |
Window *w; |
|
1060 |
WindowEvent e; |
|
1061 |
||
2639 | 1062 |
if (_special_mouse_mode != WSM_PRESIZE) return; |
0 | 1063 |
|
2639 | 1064 |
w = GetCallbackWnd(); |
1065 |
if (w == NULL) return; |
|
0 | 1066 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1067 |
e.we.place.pt = GetTileBelowCursor(); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1068 |
if (e.we.place.pt.x == -1) { |
0 | 1069 |
_thd.selend.x = -1; |
1070 |
return; |
|
1071 |
} |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1072 |
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y); |
0 | 1073 |
e.event = WE_PLACE_PRESIZE; |
1074 |
w->wndproc(w, &e); |
|
1075 |
} |
|
1076 |
||
6573 | 1077 |
static bool HandleDragDrop() |
0 | 1078 |
{ |
1079 |
Window *w; |
|
1080 |
WindowEvent e; |
|
1081 |
||
2639 | 1082 |
if (_special_mouse_mode != WSM_DRAGDROP) return true; |
0 | 1083 |
|
2639 | 1084 |
if (_left_button_down) return false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1085 |
|
0 | 1086 |
w = GetCallbackWnd(); |
1087 |
||
2639 | 1088 |
if (w != NULL) { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1089 |
/* send an event in client coordinates. */ |
0 | 1090 |
e.event = WE_DRAGDROP; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1091 |
e.we.dragdrop.pt.x = _cursor.pos.x - w->left; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1092 |
e.we.dragdrop.pt.y = _cursor.pos.y - w->top; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1093 |
e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y); |
0 | 1094 |
w->wndproc(w, &e); |
1095 |
} |
|
9081
4c47047836f3
(svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents:
8766
diff
changeset
|
1096 |
|
4c47047836f3
(svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents:
8766
diff
changeset
|
1097 |
ResetObjectToPlace(); |
4c47047836f3
(svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents:
8766
diff
changeset
|
1098 |
|
0 | 1099 |
return false; |
1100 |
} |
|
1101 |
||
6573 | 1102 |
static bool HandlePopupMenu() |
0 | 1103 |
{ |
1104 |
Window *w; |
|
1105 |
WindowEvent e; |
|
1106 |
||
2639 | 1107 |
if (!_popup_menu_active) return true; |
0 | 1108 |
|
1109 |
w = FindWindowById(WC_TOOLBAR_MENU, 0); |
|
1110 |
if (w == NULL) { |
|
1111 |
_popup_menu_active = false; |
|
1112 |
return false; |
|
1113 |
} |
|
1114 |
||
1115 |
if (_left_button_down) { |
|
1116 |
e.event = WE_POPUPMENU_OVER; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1117 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1118 |
} else { |
1119 |
_popup_menu_active = false; |
|
1120 |
e.event = WE_POPUPMENU_SELECT; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1121 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1122 |
} |
1123 |
||
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
1124 |
w->wndproc(w, &e); |
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
1125 |
|
0 | 1126 |
return false; |
1127 |
} |
|
1128 |
||
6573 | 1129 |
static bool HandleMouseOver() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1130 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1131 |
Window *w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1132 |
WindowEvent e; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1133 |
static Window *last_w = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1134 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1135 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1136 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1137 |
/* We changed window, put a MOUSEOVER event to the last window */ |
2639 | 1138 |
if (last_w != NULL && last_w != w) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1139 |
e.event = WE_MOUSEOVER; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1140 |
e.we.mouseover.pt.x = -1; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1141 |
e.we.mouseover.pt.y = -1; |
2639 | 1142 |
if (last_w->wndproc) last_w->wndproc(last_w, &e); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1143 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1144 |
last_w = w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1145 |
|
2639 | 1146 |
if (w != NULL) { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1147 |
/* send an event in client coordinates. */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1148 |
e.event = WE_MOUSEOVER; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1149 |
e.we.mouseover.pt.x = _cursor.pos.x - w->left; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1150 |
e.we.mouseover.pt.y = _cursor.pos.y - w->top; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1151 |
if (w->widget != NULL) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1152 |
e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1153 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1154 |
w->wndproc(w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1155 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1156 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1157 |
/* Mouseover never stops execution */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1158 |
return true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1159 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1160 |
|
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1161 |
/** Update all the widgets of a window based on their resize flags |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1162 |
* Both the areas of the old window and the new sized window are set dirty |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1163 |
* ensuring proper redrawal. |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1164 |
* @param w Window to resize |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6939
diff
changeset
|
1165 |
* @param x delta x-size of changed window (positive if larger, etc.) |
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1166 |
* @param y delta y-size of changed window */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1167 |
void ResizeWindow(Window *w, int x, int y) |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1168 |
{ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1169 |
Widget *wi; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1170 |
bool resize_height = false; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1171 |
bool resize_width = false; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1172 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1173 |
if (x == 0 && y == 0) return; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1174 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1175 |
SetWindowDirty(w); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1176 |
for (wi = w->widget; wi->type != WWT_LAST; wi++) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1177 |
/* Isolate the resizing flags */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1178 |
byte rsizeflag = GB(wi->display_flags, 0, 4); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1179 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1180 |
if (rsizeflag == RESIZE_NONE) continue; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1181 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1182 |
/* Resize the widget based on its resize-flag */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1183 |
if (rsizeflag & RESIZE_LEFT) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1184 |
wi->left += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1185 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1186 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1187 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1188 |
if (rsizeflag & RESIZE_RIGHT) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1189 |
wi->right += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1190 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1191 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1192 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1193 |
if (rsizeflag & RESIZE_TOP) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1194 |
wi->top += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1195 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1196 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1197 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1198 |
if (rsizeflag & RESIZE_BOTTOM) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1199 |
wi->bottom += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1200 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1201 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1202 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1203 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1204 |
/* We resized at least 1 widget, so let's resize the window totally */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1205 |
if (resize_width) w->width += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1206 |
if (resize_height) w->height += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1207 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1208 |
SetWindowDirty(w); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1209 |
} |
2596 | 1210 |
|
1211 |
static bool _dragging_window; |
|
1212 |
||
6573 | 1213 |
static bool HandleWindowDragging() |
0 | 1214 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1215 |
Window* const *wz; |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1216 |
/* Get out immediately if no window is being dragged at all. */ |
2639 | 1217 |
if (!_dragging_window) return true; |
0 | 1218 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1219 |
/* Otherwise find the window... */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1220 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1221 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1222 |
|
350 | 1223 |
if (w->flags4 & WF_DRAGGING) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1224 |
const Widget *t = &w->widget[1]; // the title bar ... ugh |
350 | 1225 |
const Window *v; |
1226 |
int x; |
|
1227 |
int y; |
|
1228 |
int nx; |
|
1229 |
int ny; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1230 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1231 |
/* Stop the dragging if the left mouse button was released */ |
0 | 1232 |
if (!_left_button_down) { |
350 | 1233 |
w->flags4 &= ~WF_DRAGGING; |
0 | 1234 |
break; |
1235 |
} |
|
1236 |
||
1237 |
SetWindowDirty(w); |
|
1238 |
||
350 | 1239 |
x = _cursor.pos.x + _drag_delta.x; |
1240 |
y = _cursor.pos.y + _drag_delta.y; |
|
1241 |
nx = x; |
|
1242 |
ny = y; |
|
1243 |
||
1244 |
if (_patches.window_snap_radius != 0) { |
|
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1245 |
Window* const *vz; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1246 |
|
353 | 1247 |
int hsnap = _patches.window_snap_radius; |
1248 |
int vsnap = _patches.window_snap_radius; |
|
1249 |
int delta; |
|
350 | 1250 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1251 |
FOR_ALL_WINDOWS(vz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1252 |
const Window *v = *vz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1253 |
|
350 | 1254 |
if (v == w) continue; // Don't snap at yourself |
1255 |
||
1256 |
if (y + w->height > v->top && y < v->top + v->height) { |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1257 |
/* Your left border <-> other right border */ |
350 | 1258 |
delta = abs(v->left + v->width - x); |
1259 |
if (delta <= hsnap) { |
|
1260 |
nx = v->left + v->width; |
|
1261 |
hsnap = delta; |
|
1262 |
} |
|
1263 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1264 |
/* Your right border <-> other left border */ |
350 | 1265 |
delta = abs(v->left - x - w->width); |
1266 |
if (delta <= hsnap) { |
|
1267 |
nx = v->left - w->width; |
|
1268 |
hsnap = delta; |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
353 | 1272 |
if (w->top + w->height >= v->top && w->top <= v->top + v->height) { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1273 |
/* Your left border <-> other left border */ |
353 | 1274 |
delta = abs(v->left - x); |
1275 |
if (delta <= hsnap) { |
|
1276 |
nx = v->left; |
|
1277 |
hsnap = delta; |
|
1278 |
} |
|
1279 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1280 |
/* Your right border <-> other right border */ |
353 | 1281 |
delta = abs(v->left + v->width - x - w->width); |
1282 |
if (delta <= hsnap) { |
|
1283 |
nx = v->left + v->width - w->width; |
|
1284 |
hsnap = delta; |
|
1285 |
} |
|
1286 |
} |
|
1287 |
||
350 | 1288 |
if (x + w->width > v->left && x < v->left + v->width) { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1289 |
/* Your top border <-> other bottom border */ |
350 | 1290 |
delta = abs(v->top + v->height - y); |
1291 |
if (delta <= vsnap) { |
|
1292 |
ny = v->top + v->height; |
|
1293 |
vsnap = delta; |
|
1294 |
} |
|
1295 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1296 |
/* Your bottom border <-> other top border */ |
350 | 1297 |
delta = abs(v->top - y - w->height); |
1298 |
if (delta <= vsnap) { |
|
1299 |
ny = v->top - w->height; |
|
1300 |
vsnap = delta; |
|
1301 |
} |
|
1302 |
} |
|
353 | 1303 |
|
1304 |
if (w->left + w->width >= v->left && w->left <= v->left + v->width) { |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1305 |
/* Your top border <-> other top border */ |
353 | 1306 |
delta = abs(v->top - y); |
1307 |
if (delta <= vsnap) { |
|
1308 |
ny = v->top; |
|
1309 |
vsnap = delta; |
|
1310 |
} |
|
1311 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1312 |
/* Your bottom border <-> other bottom border */ |
353 | 1313 |
delta = abs(v->top + v->height - y - w->height); |
1314 |
if (delta <= vsnap) { |
|
1315 |
ny = v->top + v->height - w->height; |
|
1316 |
vsnap = delta; |
|
1317 |
} |
|
1318 |
} |
|
0 | 1319 |
} |
1320 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1321 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1322 |
/* Make sure the window doesn't leave the screen |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1323 |
* 13 is the height of the title bar */ |
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8414
diff
changeset
|
1324 |
nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left); |
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8414
diff
changeset
|
1325 |
ny = Clamp(ny, 0, _screen.height - 13); |
350 | 1326 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1327 |
/* Make sure the title bar isn't hidden by behind the main tool bar */ |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1328 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1329 |
if (v != NULL) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1330 |
int v_bottom = v->top + v->height; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1331 |
int v_right = v->left + v->width; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1332 |
if (ny + t->top >= v->top && ny + t->top < v_bottom) { |
371 | 1333 |
if ((v->left < 13 && nx + t->left < v->left) || |
1334 |
(v_right > _screen.width - 13 && nx + t->right > v_right)) { |
|
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1335 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1336 |
} else { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1337 |
if (nx + t->left > v->left - 13 && |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1338 |
nx + t->right < v_right + 13) { |
2639 | 1339 |
if (w->top >= v_bottom) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1340 |
ny = v_bottom; |
2639 | 1341 |
} else if (w->left < nx) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1342 |
nx = v->left - 13 - t->left; |
2639 | 1343 |
} else { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1344 |
nx = v_right + 13 - t->right; |
2639 | 1345 |
} |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1346 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1347 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1348 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1349 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1350 |
|
350 | 1351 |
if (w->viewport != NULL) { |
1352 |
w->viewport->left += nx - w->left; |
|
1353 |
w->viewport->top += ny - w->top; |
|
1354 |
} |
|
1355 |
w->left = nx; |
|
1356 |
w->top = ny; |
|
1357 |
||
0 | 1358 |
SetWindowDirty(w); |
1359 |
return false; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1360 |
} else if (w->flags4 & WF_SIZING) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1361 |
WindowEvent e; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1362 |
int x, y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1363 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1364 |
/* Stop the sizing if the left mouse button was released */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1365 |
if (!_left_button_down) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1366 |
w->flags4 &= ~WF_SIZING; |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1648
diff
changeset
|
1367 |
SetWindowDirty(w); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1368 |
break; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1369 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1370 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1371 |
x = _cursor.pos.x - _drag_delta.x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1372 |
y = _cursor.pos.y - _drag_delta.y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1373 |
|
2675
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1374 |
/* X and Y has to go by step.. calculate it. |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1375 |
* The cast to int is necessary else x/y are implicitly casted to |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1376 |
* unsigned int, which won't work. */ |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1377 |
if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1378 |
|
2675
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1379 |
if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1380 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1381 |
/* Check if we don't go below the minimum set size */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1382 |
if ((int)w->width + x < (int)w->resize.width) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1383 |
x = w->resize.width - w->width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1384 |
if ((int)w->height + y < (int)w->resize.height) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1385 |
y = w->resize.height - w->height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1386 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1387 |
/* Window already on size */ |
2639 | 1388 |
if (x == 0 && y == 0) return false; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1389 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1390 |
/* Now find the new cursor pos.. this is NOT _cursor, because |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1391 |
we move in steps. */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1392 |
_drag_delta.x += x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1393 |
_drag_delta.y += y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1394 |
|
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1395 |
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1396 |
ResizeWindow(w, x, y); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1397 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1398 |
e.event = WE_RESIZE; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1399 |
e.we.sizing.size.x = x + w->width; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1400 |
e.we.sizing.size.y = y + w->height; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1401 |
e.we.sizing.diff.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1402 |
e.we.sizing.diff.y = y; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1403 |
w->wndproc(w, &e); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1404 |
return false; |
0 | 1405 |
} |
1406 |
} |
|
1407 |
||
1408 |
_dragging_window = false; |
|
1409 |
return false; |
|
1410 |
} |
|
1411 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1412 |
static void StartWindowDrag(Window *w) |
0 | 1413 |
{ |
1414 |
w->flags4 |= WF_DRAGGING; |
|
1415 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1416 |
|
350 | 1417 |
_drag_delta.x = w->left - _cursor.pos.x; |
1418 |
_drag_delta.y = w->top - _cursor.pos.y; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1419 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1420 |
BringWindowToFront(w); |
0 | 1421 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
1422 |
} |
|
1423 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1424 |
static void StartWindowSizing(Window *w) |
0 | 1425 |
{ |
1426 |
w->flags4 |= WF_SIZING; |
|
1427 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1428 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1429 |
_drag_delta.x = _cursor.pos.x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1430 |
_drag_delta.y = _cursor.pos.y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1431 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1432 |
BringWindowToFront(w); |
0 | 1433 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
1434 |
} |
|
1435 |
||
1436 |
||
6573 | 1437 |
static bool HandleScrollbarScrolling() |
0 | 1438 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1439 |
Window* const *wz; |
0 | 1440 |
int i; |
1441 |
int pos; |
|
1442 |
Scrollbar *sb; |
|
1443 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1444 |
/* Get out quickly if no item is being scrolled */ |
2639 | 1445 |
if (!_scrolling_scrollbar) return true; |
0 | 1446 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1447 |
/* Find the scrolling window */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1448 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1449 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1450 |
|
0 | 1451 |
if (w->flags4 & WF_SCROLL_MIDDLE) { |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1452 |
/* Abort if no button is clicked any more. */ |
0 | 1453 |
if (!_left_button_down) { |
1454 |
w->flags4 &= ~WF_SCROLL_MIDDLE; |
|
1455 |
SetWindowDirty(w); |
|
1456 |
break; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1457 |
} |
0 | 1458 |
|
1459 |
if (w->flags4 & WF_HSCROLL) { |
|
1460 |
sb = &w->hscroll; |
|
1461 |
i = _cursor.pos.x - _cursorpos_drag_start.x; |
|
842 | 1462 |
} else if (w->flags4 & WF_SCROLL2){ |
1463 |
sb = &w->vscroll2; |
|
1464 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
0 | 1465 |
} else { |
1466 |
sb = &w->vscroll; |
|
1467 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
1468 |
} |
|
1469 |
||
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1470 |
/* Find the item we want to move to and make sure it's inside bounds. */ |
0 | 1471 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); |
1472 |
if (pos != sb->pos) { |
|
1473 |
sb->pos = pos; |
|
1474 |
SetWindowDirty(w); |
|
1475 |
} |
|
1476 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1477 |
} |
0 | 1478 |
} |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1479 |
|
0 | 1480 |
_scrolling_scrollbar = false; |
1481 |
return false; |
|
1482 |
} |
|
1483 |
||
6573 | 1484 |
static bool HandleViewportScroll() |
0 | 1485 |
{ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1486 |
WindowEvent e; |
0 | 1487 |
Window *w; |
1488 |
||
6615
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1489 |
bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1490 |
|
2639 | 1491 |
if (!_scrolling_viewport) return true; |
0 | 1492 |
|
4335
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1493 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1494 |
|
8351
5e100e34b417
(svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents:
8255
diff
changeset
|
1495 |
if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) { |
5e100e34b417
(svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents:
8255
diff
changeset
|
1496 |
_cursor.fix_at = false; |
5e100e34b417
(svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents:
8255
diff
changeset
|
1497 |
_scrolling_viewport = false; |
5e100e34b417
(svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents:
8255
diff
changeset
|
1498 |
return true; |
5e100e34b417
(svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents:
8255
diff
changeset
|
1499 |
} |
5e100e34b417
(svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents:
8255
diff
changeset
|
1500 |
|
8255
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1501 |
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE && w == FindWindowById(WC_MAIN_WINDOW, 0)) { |
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1502 |
/* If the main window is following a vehicle, then first let go of it! */ |
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1503 |
const Vehicle *veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1504 |
ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */ |
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1505 |
return true; |
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1506 |
} |
ba58769915ac
(svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents:
8217
diff
changeset
|
1507 |
|
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1508 |
if (_patches.reverse_scroll) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1509 |
e.we.scroll.delta.x = -_cursor.delta.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1510 |
e.we.scroll.delta.y = -_cursor.delta.y; |
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1511 |
} else { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1512 |
e.we.scroll.delta.x = _cursor.delta.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1513 |
e.we.scroll.delta.y = _cursor.delta.y; |
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1514 |
} |
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1515 |
|
6615
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1516 |
if (scrollwheel_scrolling) { |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1517 |
/* We are using scrollwheels for scrolling */ |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1518 |
e.we.scroll.delta.x = _cursor.h_wheel; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1519 |
e.we.scroll.delta.y = _cursor.v_wheel; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1520 |
_cursor.v_wheel = 0; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1521 |
_cursor.h_wheel = 0; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1522 |
} |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1523 |
|
4335
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1524 |
/* Create a scroll-event and send it to the window */ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1525 |
e.event = WE_SCROLL; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1526 |
w->wndproc(w, &e); |
0 | 1527 |
|
2989 | 1528 |
_cursor.delta.x = 0; |
1529 |
_cursor.delta.y = 0; |
|
1530 |
return false; |
|
0 | 1531 |
} |
1532 |
||
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1533 |
/** Check if a window can be made top-most window, and if so do |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1534 |
* it. If a window does not obscure any other windows, it will not |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1535 |
* be brought to the foreground. Also if the only obscuring windows |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1536 |
* are so-called system-windows, the window will not be moved. |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1537 |
* The function will return false when a child window of this window is a |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1538 |
* modal-popup; function returns a false and child window gets a white border |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1539 |
* @param w Window to bring on-top |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1540 |
* @return false if the window has an active modal child, true otherwise */ |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1541 |
static bool MaybeBringWindowToFront(const Window *w) |
0 | 1542 |
{ |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1543 |
bool bring_to_front = false; |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1544 |
Window* const *wz; |
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1545 |
Window* const *uz; |
0 | 1546 |
|
2639 | 1547 |
if (w->window_class == WC_MAIN_WINDOW || |
1548 |
IsVitalWindow(w) || |
|
1549 |
w->window_class == WC_TOOLTIPS || |
|
1550 |
w->window_class == WC_DROPDOWN_MENU) { |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1551 |
return true; |
2639 | 1552 |
} |
0 | 1553 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1554 |
wz = FindWindowZPosition(w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1555 |
for (uz = wz; ++uz != _last_z_window;) { |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1556 |
Window *u = *uz; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1557 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1558 |
/* A modal child will prevent the activation of the parent window */ |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1559 |
if (u->parent == w && (u->desc_flags & WDF_MODAL)) { |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1560 |
u->flags4 |= WF_WHITE_BORDER_MASK; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1561 |
SetWindowDirty(u); |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1562 |
return false; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1563 |
} |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1564 |
|
2639 | 1565 |
if (u->window_class == WC_MAIN_WINDOW || |
1566 |
IsVitalWindow(u) || |
|
1567 |
u->window_class == WC_TOOLTIPS || |
|
1568 |
u->window_class == WC_DROPDOWN_MENU) { |
|
1569 |
continue; |
|
1570 |
} |
|
0 | 1571 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1572 |
/* Window sizes don't interfere, leave z-order alone */ |
0 | 1573 |
if (w->left + w->width <= u->left || |
1574 |
u->left + u->width <= w->left || |
|
1575 |
w->top + w->height <= u->top || |
|
2639 | 1576 |
u->top + u->height <= w->top) { |
1577 |
continue; |
|
1578 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1579 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1580 |
bring_to_front = true; |
0 | 1581 |
} |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1582 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1583 |
if (bring_to_front) BringWindowToFront(w); |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1584 |
return true; |
0 | 1585 |
} |
1586 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1587 |
/** Send a message from one window to another. The receiving window is found by |
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
1588 |
* @param w Window pointer pointing to the other window |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1589 |
* @param msg Specifies the message to be sent |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1590 |
* @param wparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1591 |
* @param lparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1592 |
*/ |
4171 | 1593 |
static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1594 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1595 |
WindowEvent e; |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1596 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1597 |
e.event = WE_MESSAGE; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1598 |
e.we.message.msg = msg; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1599 |
e.we.message.wparam = wparam; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1600 |
e.we.message.lparam = lparam; |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1601 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1602 |
w->wndproc(w, &e); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1603 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1604 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1605 |
/** Send a message from one window to another. The receiving window is found by |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1606 |
* @param wnd_class see WindowClass class AND |
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1607 |
* @param wnd_num see WindowNumber number, mostly 0 |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1608 |
* @param msg Specifies the message to be sent |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1609 |
* @param wparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1610 |
* @param lparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1611 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1612 |
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1613 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1614 |
Window *w = FindWindowById(wnd_class, wnd_num); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1615 |
if (w != NULL) SendWindowMessageW(w, msg, wparam, lparam); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1616 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1617 |
|
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1618 |
/** Send a message from one window to another. The message will be sent |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1619 |
* to ALL windows of the windowclass specified in the first parameter |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1620 |
* @param wnd_class see WindowClass class |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1621 |
* @param msg Specifies the message to be sent |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1622 |
* @param wparam Specifies additional message-specific information |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1623 |
* @param lparam Specifies additional message-specific information |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1624 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1625 |
void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam) |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1626 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1627 |
Window* const *wz; |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1628 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1629 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1630 |
if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam); |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1631 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1632 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1633 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1634 |
/** Handle keyboard input. |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1635 |
* @param key Lower 8 bits contain the ASCII character, the higher |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1636 |
* 16 bits the keycode */ |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1637 |
void HandleKeypress(uint32 key) |
0 | 1638 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1639 |
Window* const *wz; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1640 |
WindowEvent e; |
8515
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1641 |
/* Stores if a window with a textfield for typing is open |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1642 |
* If this is the case, keypress events are only passed to windows with text fields and |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1643 |
* to thein this main toolbar. */ |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1644 |
bool query_open = false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1645 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1646 |
/* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1647 |
* During the generation of the world, there might be |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1648 |
* another thread that is currently building for example |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1649 |
* a road. To not interfere with those tasks, we should |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1650 |
* NOT change the _current_player here. |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1651 |
* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1652 |
* This is not necessary either, as the only events that |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1653 |
* can be handled are the 'close application' events |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1654 |
*/ |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1655 |
if (!IsGeneratingWorld()) _current_player = _local_player; |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1656 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1657 |
/* Setup event */ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1658 |
e.event = WE_KEYPRESS; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5090
diff
changeset
|
1659 |
e.we.keypress.key = GB(key, 0, 16); |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1660 |
e.we.keypress.keycode = GB(key, 16, 16); |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1661 |
e.we.keypress.cont = true; |
0 | 1662 |
|
8673
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1663 |
/* |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1664 |
* The Unicode standard defines an area called the private use area. Code points in this |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1665 |
* area are reserved for private use and thus not portable between systems. For instance, |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1666 |
* Apple defines code points for the arrow keys in this area, but these are only printable |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1667 |
* on a system running OS X. We don't want these keys to show up in text fields and such, |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1668 |
* and thus we have to clear the unicode character when we encounter such a key. |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1669 |
*/ |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1670 |
if (e.we.keypress.key >= 0xE000 && e.we.keypress.key <= 0xF8FF) e.we.keypress.key = 0; |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1671 |
|
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1672 |
/* |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1673 |
* If both key and keycode is zero, we don't bother to process the event. |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1674 |
*/ |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1675 |
if (e.we.keypress.key == 0 && e.we.keypress.keycode == 0) return; |
85d63e5a028e
(svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents:
8640
diff
changeset
|
1676 |
|
8515
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1677 |
/* check if we have a query string window open before allowing hotkeys */ |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1678 |
if (FindWindowById(WC_QUERY_STRING, 0) != NULL || |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1679 |
FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL || |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1680 |
FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL || |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1681 |
FindWindowById(WC_CONSOLE, 0) != NULL || |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1682 |
FindWindowById(WC_SAVELOAD, 0) != NULL || |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1683 |
FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) { |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1684 |
query_open = true; |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1685 |
} |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1686 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1687 |
/* Call the event, start with the uppermost window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1688 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1689 |
Window *w = *--wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1690 |
|
8515
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1691 |
/* if a query window is open, only call the event for certain window types */ |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1692 |
if (query_open && |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1693 |
w->window_class != WC_QUERY_STRING && |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1694 |
w->window_class != WC_SEND_NETWORK_MSG && |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1695 |
w->window_class != WC_GENERATE_LANDSCAPE && |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1696 |
w->window_class != WC_CONSOLE && |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1697 |
w->window_class != WC_SAVELOAD && |
d0401d967e99
(svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents:
8514
diff
changeset
|
1698 |
w->window_class != WC_COMPANY_PASSWORD_WINDOW) { |
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1699 |
continue; |
2639 | 1700 |
} |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1701 |
w->wndproc(w, &e); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1702 |
if (!e.we.keypress.cont) break; |
0 | 1703 |
} |
1637
5a51ba5fb8b7
(svn r2141) - Fix: Keys now hopefully only activate the right windows. If console/querybox/chatbox is open, all input goes there, if closed to game itself.
Darkvater
parents:
1570
diff
changeset
|
1704 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1705 |
if (e.we.keypress.cont) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1706 |
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1707 |
/* When there is no toolbar w is null, check for that */ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1708 |
if (w != NULL) w->wndproc(w, &e); |
1642
593a9b750b91
(svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents:
1637
diff
changeset
|
1709 |
} |
0 | 1710 |
} |
1711 |
||
9082
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1712 |
void HandleCtrlChanged() |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1713 |
{ |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1714 |
WindowEvent e; |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1715 |
|
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1716 |
e.event = WE_CTRL_CHANGED; |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1717 |
e.we.ctrl.cont = true; |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1718 |
|
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1719 |
/* Call the event, start with the uppermost window. */ |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1720 |
for (Window* const *wz = _last_z_window; wz != _z_windows;) { |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1721 |
Window *w = *--wz; |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1722 |
w->wndproc(w, &e); |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1723 |
if (!e.we.ctrl.cont) break; |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1724 |
} |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1725 |
} |
8217cb013e23
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents:
9081
diff
changeset
|
1726 |
|
6573 | 1727 |
extern void UpdateTileSelection(); |
1728 |
extern bool VpHandlePlaceSizingDrag(); |
|
0 | 1729 |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1730 |
static int _input_events_this_tick = 0; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1731 |
|
6573 | 1732 |
static void HandleAutoscroll() |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1733 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1734 |
Window *w; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1735 |
ViewPort *vp; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1736 |
int x = _cursor.pos.x; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1737 |
int y = _cursor.pos.y; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1738 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1739 |
if (_input_events_this_tick != 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1740 |
/* HandleAutoscroll is called only once per GameLoop() - so we can clear the counter here */ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1741 |
_input_events_this_tick = 0; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1742 |
/* there were some inputs this tick, don't scroll ??? */ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1743 |
return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1744 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1745 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1746 |
if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1747 |
w = FindWindowFromPt(x, y); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1748 |
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1749 |
vp = IsPtInWindowViewport(w, x, y); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1750 |
if (vp != NULL) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1751 |
x -= vp->left; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1752 |
y -= vp->top; |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1753 |
/* here allows scrolling in both x and y axis */ |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1754 |
#define scrollspeed 3 |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1755 |
if (x - 15 < 0) { |
7797
3f3c109e2109
(svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents:
7686
diff
changeset
|
1756 |
WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1757 |
} else if (15 - (vp->width - x) > 0) { |
7797
3f3c109e2109
(svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents:
7686
diff
changeset
|
1758 |
WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1759 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1760 |
if (y - 15 < 0) { |
7797
3f3c109e2109
(svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents:
7686
diff
changeset
|
1761 |
WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1762 |
} else if (15 - (vp->height - y) > 0) { |
7797
3f3c109e2109
(svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents:
7686
diff
changeset
|
1763 |
WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1764 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1765 |
#undef scrollspeed |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1766 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1767 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1768 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1769 |
|
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1770 |
enum MouseClick { |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1771 |
MC_NONE = 0, |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1772 |
MC_LEFT, |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1773 |
MC_RIGHT, |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1774 |
MC_DOUBLE_LEFT, |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1775 |
|
7514
98a024616010
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
7505
diff
changeset
|
1776 |
MAX_OFFSET_DOUBLE_CLICK = 5, ///< How much the mouse is allowed to move to call it a double click |
98a024616010
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
7505
diff
changeset
|
1777 |
TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1778 |
}; |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1779 |
|
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1780 |
void MouseLoop(MouseClick click, int mousewheel) |
0 | 1781 |
{ |
1782 |
int x,y; |
|
1783 |
Window *w; |
|
1784 |
ViewPort *vp; |
|
6615
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1785 |
bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1786 |
|
0 | 1787 |
DecreaseWindowCounters(); |
1788 |
HandlePlacePresize(); |
|
1789 |
UpdateTileSelection(); |
|
2639 | 1790 |
if (!VpHandlePlaceSizingDrag()) return; |
1791 |
if (!HandleDragDrop()) return; |
|
1792 |
if (!HandlePopupMenu()) return; |
|
1793 |
if (!HandleWindowDragging()) return; |
|
1794 |
if (!HandleScrollbarScrolling()) return; |
|
1795 |
if (!HandleViewportScroll()) return; |
|
1796 |
if (!HandleMouseOver()) return; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1797 |
|
0 | 1798 |
x = _cursor.pos.x; |
1799 |
y = _cursor.pos.y; |
|
1800 |
||
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1801 |
if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return; |
0 | 1802 |
|
1803 |
w = FindWindowFromPt(x, y); |
|
2639 | 1804 |
if (w == NULL) return; |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1805 |
if (!MaybeBringWindowToFront(w)) return; |
0 | 1806 |
vp = IsPtInWindowViewport(w, x, y); |
1807 |
||
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1808 |
/* Don't allow any action in a viewport if either in menu of in generating world */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1809 |
if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1810 |
|
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1811 |
if (mousewheel != 0) { |
6622
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1812 |
if (_patches.scrollwheel_scrolling == 0) { |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1813 |
/* Scrollwheel is in zoom mode. Make the zoom event. */ |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1814 |
WindowEvent e; |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1815 |
|
6622
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1816 |
/* Send WE_MOUSEWHEEL event to window */ |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1817 |
e.event = WE_MOUSEWHEEL; |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1818 |
e.we.wheel.wheel = mousewheel; |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1819 |
w->wndproc(w, &e); |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1820 |
} |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1821 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1822 |
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1823 |
if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1824 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1825 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1826 |
if (vp != NULL) { |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1827 |
if (scrollwheel_scrolling) click = MC_RIGHT; // we are using the scrollwheel in a viewport, so we emulate right mouse button |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1828 |
switch (click) { |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1829 |
case MC_DOUBLE_LEFT: |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1830 |
case MC_LEFT: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
1831 |
DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); |
8414
8c2ecc2dc12c
(svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents:
8351
diff
changeset
|
1832 |
if (_thd.place_mode != VHM_NONE && |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1833 |
/* query button and place sign button work in pause mode */ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1834 |
_cursor.sprite != SPR_CURSOR_QUERY && |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1835 |
_cursor.sprite != SPR_CURSOR_SIGN && |
6557
8381016f71f3
(svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents:
6443
diff
changeset
|
1836 |
_pause_game != 0 && |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1837 |
!_cheats.build_in_pause.value) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1838 |
return; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1839 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1840 |
|
8414
8c2ecc2dc12c
(svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents:
8351
diff
changeset
|
1841 |
if (_thd.place_mode == VHM_NONE) { |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1842 |
HandleViewportClicked(vp, x, y); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1843 |
} else { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1844 |
PlaceObject(); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1845 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1846 |
break; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1847 |
|
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1848 |
case MC_RIGHT: |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1849 |
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1850 |
_scrolling_viewport = true; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1851 |
_cursor.fix_at = true; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1852 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1853 |
break; |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1854 |
|
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1855 |
default: |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1856 |
break; |
0 | 1857 |
} |
1858 |
} else { |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1859 |
switch (click) { |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1860 |
case MC_DOUBLE_LEFT: DispatchLeftClickEvent(w, x - w->left, y - w->top, true); |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1861 |
/* fallthough, and also give a single-click for backwards compatible */ |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1862 |
case MC_LEFT: DispatchLeftClickEvent(w, x - w->left, y - w->top, false); break; |
6616
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1863 |
default: |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1864 |
if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break; |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1865 |
/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons. |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1866 |
* Simulate a right button click so we can get started. */ |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1867 |
/* fallthough */ |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1868 |
case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top); break; |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1869 |
} |
0 | 1870 |
} |
1871 |
} |
|
1872 |
||
6573 | 1873 |
void HandleMouseEvents() |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1874 |
{ |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1875 |
static int double_click_time = 0; |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1876 |
static int double_click_x = 0; |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1877 |
static int double_click_y = 0; |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1878 |
MouseClick click; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1879 |
int mousewheel; |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1880 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1881 |
/* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1882 |
* During the generation of the world, there might be |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1883 |
* another thread that is currently building for example |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1884 |
* a road. To not interfere with those tasks, we should |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1885 |
* NOT change the _current_player here. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1886 |
* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1887 |
* This is not necessary either, as the only events that |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1888 |
* can be handled are the 'close application' events |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1889 |
*/ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1890 |
if (!IsGeneratingWorld()) _current_player = _local_player; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1891 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1892 |
/* Mouse event? */ |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1893 |
click = MC_NONE; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1894 |
if (_left_button_down && !_left_button_clicked) { |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1895 |
click = MC_LEFT; |
7514
98a024616010
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
7505
diff
changeset
|
1896 |
if (double_click_time != 0 && _realtime_tick - double_click_time < TIME_BETWEEN_DOUBLE_CLICK && |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1897 |
double_click_x != 0 && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK && |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1898 |
double_click_y != 0 && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) { |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1899 |
click = MC_DOUBLE_LEFT; |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1900 |
} |
7514
98a024616010
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
7505
diff
changeset
|
1901 |
double_click_time = _realtime_tick; |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1902 |
double_click_x = _cursor.pos.x; |
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1903 |
double_click_y = _cursor.pos.y; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1904 |
_left_button_clicked = true; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1905 |
_input_events_this_tick++; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1906 |
} else if (_right_button_clicked) { |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1907 |
_right_button_clicked = false; |
7505
94a7391e0377
(svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents:
7433
diff
changeset
|
1908 |
click = MC_RIGHT; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1909 |
_input_events_this_tick++; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1910 |
} |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1911 |
|
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1912 |
mousewheel = 0; |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1913 |
if (_cursor.wheel) { |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1914 |
mousewheel = _cursor.wheel; |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1915 |
_cursor.wheel = 0; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1916 |
_input_events_this_tick++; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1917 |
} |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1918 |
|
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1919 |
MouseLoop(click, mousewheel); |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1920 |
} |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1921 |
|
6573 | 1922 |
void InputLoop() |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1923 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1924 |
HandleMouseEvents(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1925 |
HandleAutoscroll(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1926 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1927 |
|
6573 | 1928 |
void UpdateWindows() |
0 | 1929 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1930 |
Window* const *wz; |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1931 |
static int we4_timer = 0; |
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1932 |
int t = we4_timer + 1; |
0 | 1933 |
|
2639 | 1934 |
if (t >= 100) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1935 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1936 |
CallWindowEventNP(*--wz, WE_4); |
0 | 1937 |
} |
1938 |
t = 0; |
|
1939 |
} |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1940 |
we4_timer = t; |
0 | 1941 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1942 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1943 |
Window *w = *--wz; |
0 | 1944 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
1945 |
w->flags4 -= WF_WHITE_BORDER_ONE; |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1946 |
|
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1947 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) SetWindowDirty(w); |
0 | 1948 |
} |
1949 |
} |
|
1950 |
||
1951 |
DrawDirtyBlocks(); |
|
1952 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1953 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1954 |
if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz); |
0 | 1955 |
} |
7950
3d3ed007127a
(svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents:
7863
diff
changeset
|
1956 |
DrawChatMessage(); |
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6622
diff
changeset
|
1957 |
/* Redraw mouse cursor in case it was hidden */ |
0 | 1958 |
DrawMouseCursor(); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1959 |
} |
0 | 1960 |
|
1961 |
||
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2216
diff
changeset
|
1962 |
int GetMenuItemIndex(const Window *w, int x, int y) |
0 | 1963 |
{ |
1964 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { |
|
1965 |
y /= 10; |
|
1966 |
||
2639 | 1967 |
if (y < WP(w, const menu_d).item_count && |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8418
diff
changeset
|
1968 |
!HasBit(WP(w, const menu_d).disabled_items, y)) { |
0 | 1969 |
return y; |
2639 | 1970 |
} |
0 | 1971 |
} |
1972 |
return -1; |
|
1973 |
} |
|
1974 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1975 |
void InvalidateWindow(WindowClass cls, WindowNumber number) |
0 | 1976 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1977 |
Window* const *wz; |
0 | 1978 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1979 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1980 |
const Window *w = *wz; |
2639 | 1981 |
if (w->window_class == cls && w->window_number == number) SetWindowDirty(w); |
0 | 1982 |
} |
1983 |
} |
|
1984 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1985 |
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index) |
0 | 1986 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1987 |
Window* const *wz; |
0 | 1988 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1989 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1990 |
const Window *w = *wz; |
2639 | 1991 |
if (w->window_class == cls && w->window_number == number) { |
8524
baf4ab1ba18d
(svn r11588) -Codechange: use the new member introduced in r11551
glx
parents:
8522
diff
changeset
|
1992 |
w->InvalidateWidget(widget_index); |
0 | 1993 |
} |
1994 |
} |
|
1995 |
} |
|
1996 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1997 |
void InvalidateWindowClasses(WindowClass cls) |
0 | 1998 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1999 |
Window* const *wz; |
2639 | 2000 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2001 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2002 |
if ((*wz)->window_class == cls) SetWindowDirty(*wz); |
0 | 2003 |
} |
2004 |
} |
|
2005 |
||
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2006 |
void InvalidateThisWindowData(Window *w) |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2007 |
{ |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2008 |
CallWindowEventNP(w, WE_INVALIDATE_DATA); |
5198
2547d72f2db4
(svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents:
5143
diff
changeset
|
2009 |
SetWindowDirty(w); |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2010 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2011 |
|
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2012 |
void InvalidateWindowData(WindowClass cls, WindowNumber number) |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2013 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2014 |
Window* const *wz; |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2015 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2016 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2017 |
Window *w = *wz; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2018 |
if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w); |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2019 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2020 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2021 |
|
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2022 |
void InvalidateWindowClassesData(WindowClass cls) |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2023 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2024 |
Window* const *wz; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2025 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2026 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2027 |
if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz); |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2028 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2029 |
} |
0 | 2030 |
|
6573 | 2031 |
void CallWindowTickEvent() |
0 | 2032 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2033 |
Window* const *wz; |
2639 | 2034 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2035 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2036 |
CallWindowEventNP(*--wz, WE_TICK); |
0 | 2037 |
} |
2038 |
} |
|
2039 |
||
6573 | 2040 |
void DeleteNonVitalWindows() |
0 | 2041 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2042 |
Window* const *wz; |
2639 | 2043 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2044 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2045 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2046 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2047 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2048 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2049 |
Window *w = *wz; |
0 | 2050 |
if (w->window_class != WC_MAIN_WINDOW && |
2051 |
w->window_class != WC_SELECT_GAME && |
|
2052 |
w->window_class != WC_MAIN_TOOLBAR && |
|
2053 |
w->window_class != WC_STATUS_BAR && |
|
2054 |
w->window_class != WC_TOOLBAR_MENU && |
|
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
2055 |
w->window_class != WC_TOOLTIPS && |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
2056 |
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned' |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2057 |
|
0 | 2058 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2059 |
goto restart_search; |
0 | 2060 |
} |
2061 |
} |
|
2062 |
} |
|
2063 |
||
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
2064 |
/** It is possible that a stickied window gets to a position where the |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2065 |
* 'close' button is outside the gaming area. You cannot close it then; except |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2066 |
* with this function. It closes all windows calling the standard function, |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2067 |
* then, does a little hacked loop of closing all stickied windows. Note |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2068 |
* that standard windows (status bar, etc.) are not stickied, so these aren't affected */ |
6573 | 2069 |
void DeleteAllNonVitalWindows() |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2070 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2071 |
Window* const *wz; |
2639 | 2072 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2073 |
/* Delete every window except for stickied ones, then sticky ones as well */ |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2074 |
DeleteNonVitalWindows(); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2075 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2076 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2077 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2078 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2079 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2080 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2081 |
if ((*wz)->flags4 & WF_STICKY) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2082 |
DeleteWindow(*wz); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2083 |
goto restart_search; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2084 |
} |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2085 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2086 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2087 |
|
6939
50b3cf596ce2
(svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents:
6928
diff
changeset
|
2088 |
/** Delete all always on-top windows to get an empty screen */ |
6573 | 2089 |
void HideVitalWindows() |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2090 |
{ |
6158
ca1471170695
(svn r8533) -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar.
rubidium
parents:
5893
diff
changeset
|
2091 |
DeleteWindowById(WC_TOOLBAR_MENU, 0); |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2092 |
DeleteWindowById(WC_MAIN_TOOLBAR, 0); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2093 |
DeleteWindowById(WC_STATUS_BAR, 0); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2094 |
} |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2095 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
2096 |
int PositionMainToolbar(Window *w) |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2097 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
2098 |
DEBUG(misc, 5, "Repositioning Main Toolbar..."); |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2099 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2100 |
if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) { |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2101 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2102 |
} |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2103 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2104 |
switch (_patches.toolbar_pos) { |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
2105 |
case 1: w->left = (_screen.width - w->width) / 2; break; |
2026 | 2106 |
case 2: w->left = _screen.width - w->width; break; |
2107 |
default: w->left = 0; |
|
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2108 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2109 |
SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2110 |
return w->left; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2111 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2112 |
|
0 | 2113 |
void RelocateAllWindows(int neww, int newh) |
2114 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2115 |
Window* const *wz; |
0 | 2116 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2117 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2118 |
Window *w = *wz; |
0 | 2119 |
int left, top; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
2120 |
|
0 | 2121 |
if (w->window_class == WC_MAIN_WINDOW) { |
2122 |
ViewPort *vp = w->viewport; |
|
2123 |
vp->width = w->width = neww; |
|
2124 |
vp->height = w->height = newh; |
|
7122
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
2125 |
vp->virtual_width = ScaleByZoom(neww, vp->zoom); |
0607a15aedc0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents:
7120
diff
changeset
|
2126 |
vp->virtual_height = ScaleByZoom(newh, vp->zoom); |
0 | 2127 |
continue; // don't modify top,left |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
2128 |
} |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
2129 |
|
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2130 |
/* XXX - this probably needs something more sane. For example specying |
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2131 |
* in a 'backup'-desc that the window should always be centred. */ |
2989 | 2132 |
switch (w->window_class) { |
2133 |
case WC_MAIN_TOOLBAR: |
|
7858
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2134 |
if (neww - w->width != 0) { |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2135 |
ResizeWindow(w, min(neww, 640) - w->width, 0); |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2136 |
|
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2137 |
WindowEvent e; |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2138 |
e.event = WE_RESIZE; |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2139 |
e.we.sizing.size.x = w->width; |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2140 |
e.we.sizing.size.y = w->height; |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2141 |
e.we.sizing.diff.x = neww - w->width; |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2142 |
e.we.sizing.diff.y = 0; |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2143 |
w->wndproc(w, &e); |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2144 |
} |
eece91cb3472
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7850
diff
changeset
|
2145 |
|
2989 | 2146 |
top = w->top; |
2147 |
left = PositionMainToolbar(w); // changes toolbar orientation |
|
2148 |
break; |
|
2149 |
||
2150 |
case WC_SELECT_GAME: |
|
2151 |
case WC_GAME_OPTIONS: |
|
2152 |
case WC_NETWORK_WINDOW: |
|
2153 |
top = (newh - w->height) >> 1; |
|
2154 |
left = (neww - w->width) >> 1; |
|
2155 |
break; |
|
2156 |
||
2157 |
case WC_NEWS_WINDOW: |
|
2158 |
top = newh - w->height; |
|
2159 |
left = (neww - w->width) >> 1; |
|
2160 |
break; |
|
2161 |
||
2162 |
case WC_STATUS_BAR: |
|
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8414
diff
changeset
|
2163 |
ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0); |
2989 | 2164 |
top = newh - w->height; |
2165 |
left = (neww - w->width) >> 1; |
|
2166 |
break; |
|
2167 |
||
2168 |
case WC_SEND_NETWORK_MSG: |
|
8418
b49fc6be1ab9
(svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents:
8414
diff
changeset
|
2169 |
ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0); |
2989 | 2170 |
top = (newh - 26); // 26 = height of status bar + height of chat bar |
2171 |
left = (neww - w->width) >> 1; |
|
2172 |
break; |
|
2173 |
||
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2174 |
case WC_CONSOLE: |
5143
a78072872bff
(svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents:
5137
diff
changeset
|
2175 |
IConsoleResize(w); |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
2176 |
continue; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2177 |
|
9194
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2178 |
default: { |
2989 | 2179 |
left = w->left; |
2180 |
if (left + (w->width >> 1) >= neww) left = neww - w->width; |
|
8519
7a9d047a184e
(svn r11583) -Fix [FS#1484]: windows could get completely missing when one resized the window to something very small.
rubidium
parents:
8515
diff
changeset
|
2181 |
if (left < 0) left = 0; |
7a9d047a184e
(svn r11583) -Fix [FS#1484]: windows could get completely missing when one resized the window to something very small.
rubidium
parents:
8515
diff
changeset
|
2182 |
|
2989 | 2183 |
top = w->top; |
2184 |
if (top + (w->height >> 1) >= newh) top = newh - w->height; |
|
9194
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2185 |
|
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2186 |
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2187 |
if (wt != NULL) { |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2188 |
if (top < wt->height) top = wt->height; |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2189 |
if (top >= newh) top = newh - 1; |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2190 |
} else { |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2191 |
if (top < 0) top = 0; |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2192 |
} |
685d482d1e6c
(svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents:
9082
diff
changeset
|
2193 |
} break; |
0 | 2194 |
} |
2195 |
||
2639 | 2196 |
if (w->viewport != NULL) { |
0 | 2197 |
w->viewport->left += left - w->left; |
2198 |
w->viewport->top += top - w->top; |
|
2199 |
} |
|
2200 |
||
2201 |
w->left = left; |
|
2202 |
w->top = top; |
|
2203 |
} |
|
2204 |
} |