author | KUDr |
Mon, 12 Feb 2007 23:12:02 +0000 | |
branch | cpp_gui |
changeset 6236 | ec056d324811 |
parent 6235 | 5077e6ed3788 |
child 6237 | bce32e54c993 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#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
|
4 |
#include <stdarg.h> |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1867
diff
changeset
|
5 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1112
diff
changeset
|
6 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
7 |
#include "functions.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
651
diff
changeset
|
8 |
#include "map.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2026
diff
changeset
|
9 |
#include "player.h" |
0 | 10 |
#include "window.h" |
11 |
#include "gfx.h" |
|
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
|
12 |
#include "viewport.h" |
126 | 13 |
#include "console.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
14 |
#include "variables.h" |
2517
b90693227193
(svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents:
2436
diff
changeset
|
15 |
#include "table/sprites.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
16 |
#include "genworld.h" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
17 |
#include "helpers.hpp" |
0 | 18 |
|
350 | 19 |
// delta between mouse cursor and upper left corner of dragged window |
20 |
static Point _drag_delta; |
|
21 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
22 |
/*static*/ WindowList Window::s_list; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
23 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
24 |
//static Window _windows[25]; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
25 |
//Window *_z_windows[lengthof(_windows)]; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
26 |
//Window **_last_z_window; ///< always points to the next free space in the z-array |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
27 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
28 |
int32 CountedObject::AddRef() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
29 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
30 |
return ++m_ref_cnt; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
31 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
32 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
33 |
int32 CountedObject::Release() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
34 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
35 |
int32 res = --m_ref_cnt; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
36 |
assert(res >= 0); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
37 |
if (res == 0) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
38 |
FinalRelease(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
39 |
delete this; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
40 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
41 |
return res; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
42 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
43 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
44 |
void WindowList::Add(Window *w) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
45 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
46 |
/* we will add the new window before first vital window or at the end */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
47 |
Iterator it = w->IsVital() ? m_list.end() : FindFirstVitalWindow(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
48 |
/* it should be now at the proper position where new window should be added */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
49 |
m_list.insert(it, w); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
50 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
51 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
52 |
void WindowList::Remove(Window *w) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
53 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
54 |
Iterator it = Find(w); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
55 |
if (it != m_list.end()) m_list.erase(it); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
56 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
57 |
|
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
58 |
static bool MatchWindow(WindowList::Iterator it, Window *w) |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
59 |
{ |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
60 |
return (*it).w == w; |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
61 |
} |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
62 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
63 |
WindowList::Iterator WindowList::Find(Window *w) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
64 |
{ |
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
65 |
Iterator it = EnumT(&MatchWindow, w); |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
66 |
if (it == m_list.end()) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
67 |
DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls", |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
68 |
w->window_class, w->window_number); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
69 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
70 |
return it; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
71 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
72 |
|
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
73 |
static bool MatchNonVitalWindow(WindowList::Iterator it) |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
74 |
{ |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
75 |
return !(*it).w->IsVital(); |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
76 |
} |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
77 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
78 |
WindowList::Iterator WindowList::FindFirstVitalWindow() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
79 |
{ |
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
80 |
Iterator it = ReverseEnumT(&MatchNonVitalWindow); |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
81 |
/* we have stopped on last non-vital window. Move one step forward to locate first vital window. */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
82 |
if (it != m_list.end()) ++it; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
83 |
return it; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
84 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
85 |
|
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
86 |
static bool MatchClass(WindowList::Iterator it, WindowClass cls) |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
87 |
{ |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
88 |
return (*it).w->window_class == cls; |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
89 |
} |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
90 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
91 |
WindowList::Iterator WindowList::FindByClass(WindowClass cls) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
92 |
{ |
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
93 |
return EnumT(&MatchClass, cls); |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
94 |
} |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
95 |
|
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
96 |
static bool MatchClassAndId(WindowList::Iterator it, WindowClass cls, WindowNumber num) |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
97 |
{ |
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
98 |
return (*it).w->window_class == cls && (*it).w->window_number == num; |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
99 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
100 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
101 |
WindowList::Iterator WindowList::FindById(WindowClass cls, WindowNumber num) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
102 |
{ |
6236
ec056d324811
(svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents:
6235
diff
changeset
|
103 |
return EnumT(&MatchClassAndId, cls, num); |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
104 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
105 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
106 |
/* Open a new window. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
107 |
* This function is called from AllocateWindow() or AllocateWindowDesc() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
108 |
* See descriptions for those functions for usage |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
109 |
* See AllocateWindow() for description of arguments. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
110 |
* Only addition here is window_number, which is the window_number being assigned to the new window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
111 |
*/ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
112 |
Window::Window( |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
113 |
int x, int y, int w, int h, |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
114 |
WindowProc *proc, WindowClass cls, const Widget *widget, int wnd_number) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
115 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
116 |
//Window *w = FindFreeWindow(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
117 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
118 |
///* We have run out of windows, close one and use that as the place for our new one */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
119 |
//if (w == NULL) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
120 |
// w = FindDeletableWindow(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
121 |
// if (w == NULL) w = ForceFindDeletableWindow(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
122 |
// w->Close(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
123 |
//} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
124 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
125 |
// Set up window properties |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
126 |
//memset(w, 0, sizeof(*w)); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
127 |
ZeroInit(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
128 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
129 |
window_class = cls; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
130 |
flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
131 |
caption_color = 0xFF; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
132 |
left = x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
133 |
top = y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
134 |
width = w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
135 |
height = h; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
136 |
wndproc = proc; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
137 |
AssignWidgetToWindow(this, widget); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
138 |
resize.width = width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
139 |
resize.height = height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
140 |
resize.step_width = 1; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
141 |
resize.step_height = 1; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
142 |
window_number = wnd_number; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
143 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
144 |
//{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
145 |
// Window **wz = _last_z_window; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
146 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
147 |
// /* Hacky way of specifying always-on-top windows. These windows are |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
148 |
// * always above other windows because they are moved below them. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
149 |
// * status-bar is above news-window because it has been created earlier. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
150 |
// * Also, as the chat-window is excluded from this, it will always be |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
151 |
// * the last window, thus always on top. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
152 |
// * XXX - Yes, ugly, probably needs something like w->always_on_top flag |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
153 |
// * to implement correctly, but even then you need some kind of distinction |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
154 |
// * between on-top of chat/news and status windows, because these conflict */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
155 |
// if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
156 |
// if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
157 |
// if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
158 |
// if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
159 |
// if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
160 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
161 |
// assert(wz >= _z_windows); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
162 |
// if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
163 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
164 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
165 |
// *wz = w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
166 |
// _last_z_window++; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
167 |
//} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
168 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
169 |
/* add our new window into z-order list */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
170 |
Window::s_list.Add(this); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
171 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
172 |
SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
173 |
CallWindowEventNP(this, WE_CREATE); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
174 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
175 |
//return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
176 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
177 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
178 |
/** Find the Window whose parent pointer points to this window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
179 |
* @parent w Window to find child of |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
180 |
* @return return a Window pointer that is the child of w, or NULL otherwise */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
181 |
Window* Window::FindChild() const |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
182 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
183 |
Window *v; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
184 |
FOR_ALL_WINDOWS(v) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
185 |
if (v->parent == this) return v; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
186 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
187 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
188 |
return NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
189 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
190 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
191 |
void Window::SetDirty() const |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
192 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
193 |
if (this == NULL) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
194 |
SetDirtyBlocks(left, top, left + width, top + height); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
195 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
196 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
197 |
/*virtual*/ void Window::FinalRelease() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
198 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
199 |
/* Delete any children a window might have in a head-recursive manner */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
200 |
Window *v = FindChild(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
201 |
if (v != NULL) v->Close(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
202 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
203 |
if (_thd.place_mode != VHM_NONE && |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
204 |
_thd.window_class == window_class && |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
205 |
_thd.window_number == window_number) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
206 |
ResetObjectToPlace(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
207 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
208 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
209 |
CallWindowEventNP(this, WE_DESTROY); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
210 |
if (viewport != NULL) DeleteWindowViewport(this); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
211 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
212 |
SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
213 |
free(widget); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
214 |
widget = NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
215 |
widget_count = 0; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
216 |
parent = NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
217 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
218 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
219 |
/*virtual*/ void Window::Close() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
220 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
221 |
s_list.Remove(this); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
222 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
223 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
224 |
/*virtual*/ bool Window::IsVital() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
225 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
226 |
WindowClass wc = window_class; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
227 |
return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
228 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
229 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
230 |
/** |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
231 |
* Open a new window. If there is no space for a new window, close an open |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
232 |
* window. Try to avoid stickied windows, but if there is no else, close one of |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
233 |
* those as well. Then make sure all created windows are below some always-on-top |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
234 |
* ones. Finally set all variables and call the WE_CREATE event |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
235 |
* @param x offset in pixels from the left of the screen |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
236 |
* @param y offset in pixels from the top of the screen |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
237 |
* @param width width in pixels of the window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
238 |
* @param height height in pixels of the window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
239 |
* @param *proc @see WindowProc function to call when any messages/updates happen to the window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
240 |
* @param cls @see WindowClass class of the window, used for identification and grouping |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
241 |
* @param *widget @see Widget pointer to the window layout and various elements |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
242 |
* @return @see Window pointer of the newly created window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
243 |
*/ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
244 |
/*static*/ Window* Window::Allocate( |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
245 |
int x, int y, int width, int height, |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
246 |
WindowProc *proc, WindowClass cls, const Widget *widget) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
247 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
248 |
return new Window(x, y, width, height, proc, cls, widget, 0); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
249 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
250 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
251 |
/*static*/ Window* Window::Get(WindowList::Iterator it) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
252 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
253 |
return (it != s_list.m_list.end()) ? (*it).w : NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
254 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
255 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
256 |
/*static*/ Window* Window::FindById(WindowClass cls, WindowNumber num) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
257 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
258 |
return Get(s_list.FindById(cls, num)); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
259 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
260 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
261 |
/*static*/ void Window::SetDirtyById(WindowClass cls, WindowNumber num) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
262 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
263 |
Window *w = FindById(cls, num); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
264 |
if (w != NULL) w->SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
265 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
266 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
267 |
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...) |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
268 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
269 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
270 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
271 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
272 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
273 |
while (widgets != WIDGET_LIST_END) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
274 |
SetWindowWidgetDisabledState(this, widgets, disab_stat); |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
275 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
276 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
277 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
278 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
279 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
280 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
281 |
void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...) |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
282 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
283 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
284 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
285 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
286 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
287 |
while (widgets != WIDGET_LIST_END) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
288 |
SetWindowWidgetHiddenState(this, widgets, hidden_stat); |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
289 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
290 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
291 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
292 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
293 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
294 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
295 |
void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
296 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
297 |
va_list wdg_list; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
298 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
299 |
va_start(wdg_list, widgets); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
300 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
301 |
while (widgets != WIDGET_LIST_END) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
302 |
SetWindowWidgetLoweredState(this, widgets, lowered_stat); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
303 |
widgets = va_arg(wdg_list, int); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
304 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
305 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
306 |
va_end(wdg_list); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
307 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
308 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
309 |
void Window::RaiseButtons() |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
310 |
{ |
5235
3c309f43f0a6
(svn r7355) -Codechange: replace 'for (i = 0; w->widget[i].type != WWT_TYPE; i++)'-type for loops with 'for (i = 0; i < w->widget_count; i++)'-type for loops
rubidium
parents:
5232
diff
changeset
|
311 |
uint i; |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
312 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
313 |
for (i = 0; i < widget_count; i++) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
314 |
if (IsWindowWidgetLowered(this, i)) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
315 |
RaiseWindowWidget(this, i); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
316 |
InvalidateWidget(this, i); |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
317 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
318 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
319 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
320 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
321 |
void Window::HandleButtonClick(byte widget) |
0 | 322 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
323 |
LowerWindowWidget(this, widget); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
324 |
this->flags4 |= 5 << WF_TIMEOUT_SHL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
325 |
InvalidateWidget(this, widget); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
326 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
327 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
328 |
/** On clicking on a window, make it the frontmost window of all. However |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
329 |
* there are certain windows that always need to be on-top; these include |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
330 |
* - Toolbar, Statusbar (always on) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
331 |
* - New window, Chatbar (only if open) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
332 |
* The window is marked dirty for a repaint if the window is actually moved |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
333 |
* @param w window that is put into the foreground |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
334 |
* @return pointer to the window, the same as the input pointer |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
335 |
*/ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
336 |
void Window::BringToFront() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
337 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
338 |
WindowPtr wp = this; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
339 |
WindowList::Iterator it = Window::s_list.Find(this); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
340 |
Window::s_list.Remove(this); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
341 |
Window::s_list.Add(this); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
342 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
343 |
SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
344 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
345 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
346 |
/** Find a window and make it the top-window on the screen. The window |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
347 |
* gets a white border for a brief period of time to visualize its |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
348 |
* "activation" |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
349 |
* @return a pointer to the window thus activated */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
350 |
/*static*/ Window* Window::BringToFrontById(WindowClass cls, WindowNumber num) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
351 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
352 |
Window *w = FindById(cls, num); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
353 |
if (w != NULL) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
354 |
w->flags4 |= WF_WHITE_BORDER_MASK; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
355 |
w->BringToFront(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
356 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
357 |
return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
358 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
359 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
360 |
static bool _dragging_window; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
361 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
362 |
void Window::StartDrag() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
363 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
364 |
flags4 |= WF_DRAGGING; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
365 |
_dragging_window = true; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
366 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
367 |
_drag_delta.x = left - _cursor.pos.x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
368 |
_drag_delta.y = top - _cursor.pos.y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
369 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
370 |
BringToFront(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
371 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
372 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
373 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
374 |
bool Window::ContinueDrag() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
375 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
376 |
const Widget *t = &widget[1]; // the title bar ... ugh |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
377 |
const Window *v; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
378 |
int x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
379 |
int y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
380 |
int nx; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
381 |
int ny; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
382 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
383 |
// Stop the dragging if the left mouse button was released |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
384 |
if (!_left_button_down) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
385 |
flags4 &= ~WF_DRAGGING; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
386 |
_dragging_window = false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
387 |
return false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
388 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
389 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
390 |
SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
391 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
392 |
x = _cursor.pos.x + _drag_delta.x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
393 |
y = _cursor.pos.y + _drag_delta.y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
394 |
nx = x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
395 |
ny = y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
396 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
397 |
if (_patches.window_snap_radius != 0) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
398 |
Window *v; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
399 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
400 |
int hsnap = _patches.window_snap_radius; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
401 |
int vsnap = _patches.window_snap_radius; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
402 |
int delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
403 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
404 |
FOR_ALL_WINDOWS(v) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
405 |
if (v == this) continue; // Don't snap at yourself |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
406 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
407 |
if (y + height > v->top && y < v->top + v->height) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
408 |
// Your left border <-> other right border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
409 |
delta = abs(v->left + v->width - x); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
410 |
if (delta <= hsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
411 |
nx = v->left + v->width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
412 |
hsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
413 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
414 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
415 |
// Your right border <-> other left border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
416 |
delta = abs(v->left - x - width); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
417 |
if (delta <= hsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
418 |
nx = v->left - width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
419 |
hsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
420 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
421 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
422 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
423 |
if (top + height >= v->top && top <= v->top + v->height) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
424 |
// Your left border <-> other left border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
425 |
delta = abs(v->left - x); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
426 |
if (delta <= hsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
427 |
nx = v->left; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
428 |
hsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
429 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
430 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
431 |
// Your right border <-> other right border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
432 |
delta = abs(v->left + v->width - x - width); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
433 |
if (delta <= hsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
434 |
nx = v->left + v->width - width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
435 |
hsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
436 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
437 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
438 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
439 |
if (x + width > v->left && x < v->left + v->width) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
440 |
// Your top border <-> other bottom border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
441 |
delta = abs(v->top + v->height - y); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
442 |
if (delta <= vsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
443 |
ny = v->top + v->height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
444 |
vsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
445 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
446 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
447 |
// Your bottom border <-> other top border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
448 |
delta = abs(v->top - y - height); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
449 |
if (delta <= vsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
450 |
ny = v->top - height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
451 |
vsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
452 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
453 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
454 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
455 |
if (left + width >= v->left && left <= v->left + v->width) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
456 |
// Your top border <-> other top border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
457 |
delta = abs(v->top - y); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
458 |
if (delta <= vsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
459 |
ny = v->top; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
460 |
vsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
461 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
462 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
463 |
// Your bottom border <-> other bottom border |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
464 |
delta = abs(v->top + v->height - y - height); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
465 |
if (delta <= vsnap) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
466 |
ny = v->top + v->height - height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
467 |
vsnap = delta; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
468 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
469 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
470 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
471 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
472 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
473 |
// Make sure the window doesn't leave the screen |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
474 |
// 13 is the height of the title bar |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
475 |
nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
476 |
ny = clamp(ny, 0, _screen.height - 13); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
477 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
478 |
// Make sure the title bar isn't hidden by behind the main tool bar |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
479 |
v = Window::FindById(WC_MAIN_TOOLBAR, 0); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
480 |
if (v != NULL) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
481 |
int v_bottom = v->top + v->height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
482 |
int v_right = v->left + v->width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
483 |
if (ny + t->top >= v->top && ny + t->top < v_bottom) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
484 |
if ((v->left < 13 && nx + t->left < v->left) || |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
485 |
(v_right > _screen.width - 13 && nx + t->right > v_right)) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
486 |
ny = v_bottom; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
487 |
} else { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
488 |
if (nx + t->left > v->left - 13 && |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
489 |
nx + t->right < v_right + 13) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
490 |
if (top >= v_bottom) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
491 |
ny = v_bottom; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
492 |
} else if (left < nx) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
493 |
nx = v->left - 13 - t->left; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
494 |
} else { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
495 |
nx = v_right + 13 - t->right; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
496 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
497 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
498 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
499 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
500 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
501 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
502 |
if (viewport != NULL) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
503 |
viewport->left += nx - left; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
504 |
viewport->top += ny - top; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
505 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
506 |
left = nx; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
507 |
top = ny; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
508 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
509 |
SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
510 |
return false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
511 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
512 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
513 |
void Window::StartSizing() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
514 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
515 |
flags4 |= WF_SIZING; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
516 |
_dragging_window = true; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
517 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
518 |
_drag_delta.x = _cursor.pos.x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
519 |
_drag_delta.y = _cursor.pos.y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
520 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
521 |
BringToFront(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
522 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
523 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
524 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
525 |
bool Window::ContinueSizing() |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
526 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
527 |
WindowEvent e; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
528 |
int x, y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
529 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
530 |
/* Stop the sizing if the left mouse button was released */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
531 |
if (!_left_button_down) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
532 |
flags4 &= ~WF_SIZING; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
533 |
SetDirty(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
534 |
_dragging_window = false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
535 |
return false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
536 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
537 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
538 |
x = _cursor.pos.x - _drag_delta.x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
539 |
y = _cursor.pos.y - _drag_delta.y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
540 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
541 |
/* X and Y has to go by step.. calculate it. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
542 |
* The cast to int is necessary else x/y are implicitly casted to |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
543 |
* unsigned int, which won't work. */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
544 |
if (resize.step_width > 1) x -= x % (int)resize.step_width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
545 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
546 |
if (resize.step_height > 1) y -= y % (int)resize.step_height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
547 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
548 |
/* Check if we don't go below the minimum set size */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
549 |
if ((int)width + x < (int)resize.width) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
550 |
x = resize.width - width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
551 |
if ((int)height + y < (int)resize.height) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
552 |
y = resize.height - height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
553 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
554 |
/* Window already on size */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
555 |
if (x == 0 && y == 0) return false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
556 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
557 |
/* Now find the new cursor pos.. this is NOT _cursor, because |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
558 |
we move in steps. */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
559 |
_drag_delta.x += x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
560 |
_drag_delta.y += y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
561 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
562 |
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
563 |
ResizeWindow(this, x, y); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
564 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
565 |
e.event = WE_RESIZE; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
566 |
e.we.sizing.size.x = x + width; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
567 |
e.we.sizing.size.y = y + height; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
568 |
e.we.sizing.diff.x = x; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
569 |
e.we.sizing.diff.y = y; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
570 |
wndproc(this, &e); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
571 |
return false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
572 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
573 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
574 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
575 |
/*static*/ bool Window::HandleWindowDragging(void) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
576 |
{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
577 |
// Get out immediately if no window is being dragged at all. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
578 |
if (!_dragging_window) return true; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
579 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
580 |
// Otherwise find the window... |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
581 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
582 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
583 |
if (w->flags4 & WF_DRAGGING) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
584 |
return w->ContinueDrag(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
585 |
} else if (w->flags4 & WF_SIZING) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
586 |
return w->ContinueSizing(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
587 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
588 |
} |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
589 |
_dragging_window = false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
590 |
return false; |
0 | 591 |
} |
592 |
||
2817 | 593 |
|
594 |
||
4171 | 595 |
static void DispatchLeftClickEvent(Window *w, int x, int y) |
2596 | 596 |
{ |
0 | 597 |
WindowEvent e; |
598 |
const Widget *wi; |
|
599 |
||
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
600 |
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
|
601 |
e.we.click.pt.y = y; |
0 | 602 |
e.event = WE_CLICK; |
603 |
||
604 |
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
|
605 |
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
|
606 |
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
|
607 |
|
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
|
608 |
/* don't allow any interaction if the button has been disabled */ |
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
|
609 |
if (IsWindowWidgetDisabled(w, 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
|
610 |
|
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
|
611 |
wi = &w->widget[e.we.click.widget]; |
0 | 612 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
613 |
if (wi->type & WWB_MASK) { |
211 | 614 |
/* special widget handling for buttons*/ |
2952 | 615 |
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
|
616 |
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
|
617 |
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
|
618 |
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
619 |
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
|
620 |
break; |
0 | 621 |
} |
842 | 622 |
} 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
|
623 |
ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y); |
0 | 624 |
} |
625 |
||
626 |
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
|
627 |
if (e.we.click.widget == 0) { /* 'X' */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
628 |
w->Close(); |
984
a50e131688d2
(svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents:
983
diff
changeset
|
629 |
return; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
630 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
631 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
632 |
if (e.we.click.widget == 1) { /* 'Title bar' */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
633 |
w->StartDrag(); |
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
|
634 |
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
|
635 |
} |
0 | 636 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
637 |
|
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
|
638 |
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
639 |
w->StartSizing(); |
5272
e27514065ed8
(svn r7414) -Fix: Immediately invalidate the resize widget when clicked, instead of when started to drag
Darkvater
parents:
5268
diff
changeset
|
640 |
InvalidateWidget(w, 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
|
641 |
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
|
642 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
643 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
644 |
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
|
645 |
w->flags4 ^= WF_STICKY; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
646 |
InvalidateWidget(w, 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
|
647 |
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
|
648 |
} |
0 | 649 |
} |
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
|
650 |
|
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
|
651 |
w->wndproc(w, &e); |
0 | 652 |
} |
653 |
||
4171 | 654 |
static void DispatchRightClickEvent(Window *w, int x, int y) |
2596 | 655 |
{ |
0 | 656 |
WindowEvent e; |
657 |
||
658 |
/* default tooltips handler? */ |
|
659 |
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
|
660 |
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
|
661 |
if (e.we.click.widget < 0) |
0 | 662 |
return; /* exit if clicked outside of widgets */ |
663 |
||
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
664 |
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
|
665 |
GuiShowTooltips(w->widget[e.we.click.widget].tooltips); |
0 | 666 |
return; |
667 |
} |
|
668 |
} |
|
669 |
||
670 |
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
|
671 |
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
|
672 |
e.we.click.pt.y = y; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
673 |
w->wndproc(w, &e); |
0 | 674 |
} |
675 |
||
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
|
676 |
/** 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
|
677 |
* 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
|
678 |
* @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
|
679 |
* @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
|
680 |
* @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
|
681 |
*/ |
4171 | 682 |
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel) |
0 | 683 |
{ |
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
|
684 |
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
|
685 |
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
|
686 |
|
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
|
687 |
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
|
688 |
|
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
|
689 |
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
|
690 |
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
|
691 |
|
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
|
692 |
/* 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
|
693 |
* 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
|
694 |
* 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
|
695 |
* not happening until someone rewrites the whole widget-code */ |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
696 |
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
|
697 |
(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
|
698 |
|
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
|
699 |
if (sb->count > sb->cap) { |
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
|
700 |
int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap); |
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
|
701 |
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
|
702 |
sb->pos = pos; |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
703 |
w->SetDirty(); |
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
|
704 |
} |
0 | 705 |
} |
706 |
} |
|
707 |
} |
|
708 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
709 |
static void DrawOverlappedWindow(WindowList::Iterator it, int left, int top, int right, int bottom); |
2817 | 710 |
|
0 | 711 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) |
712 |
{ |
|
713 |
DrawPixelInfo bk; |
|
714 |
_cur_dpi = &bk; |
|
715 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
716 |
const Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
717 |
FOR_ALL_WINDOWS(w) { |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
718 |
if (right > w->left && |
0 | 719 |
bottom > w->top && |
720 |
left < w->left + w->width && |
|
721 |
top < w->top + w->height) { |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
722 |
DrawOverlappedWindow(it, left, top, right, bottom); |
2639 | 723 |
} |
0 | 724 |
} |
725 |
} |
|
726 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
727 |
static void DrawOverlappedWindow(WindowList::Iterator wit, int left, int top, int right, int bottom) |
0 | 728 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
729 |
Window *w = (*wit).w; |
0 | 730 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
731 |
for (WindowList::Iterator vit = wit; ++vit != Window::s_list.m_list.end(); ) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
732 |
const Window *v = (*vit).w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
733 |
int x; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
734 |
|
0 | 735 |
if (right > v->left && |
2026 | 736 |
bottom > v->top && |
0 | 737 |
left < v->left + v->width && |
738 |
top < v->top + v->height) { |
|
739 |
if (left < (x=v->left)) { |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
740 |
DrawOverlappedWindow(wit, left, top, x, bottom); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
741 |
DrawOverlappedWindow(wit, x, top, right, bottom); |
0 | 742 |
return; |
743 |
} |
|
744 |
||
745 |
if (right > (x=v->left + v->width)) { |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
746 |
DrawOverlappedWindow(wit, left, top, x, bottom); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
747 |
DrawOverlappedWindow(wit, x, top, right, bottom); |
0 | 748 |
return; |
749 |
} |
|
750 |
||
751 |
if (top < (x=v->top)) { |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
752 |
DrawOverlappedWindow(wit, left, top, right, x); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
753 |
DrawOverlappedWindow(wit, left, x, right, bottom); |
0 | 754 |
return; |
755 |
} |
|
756 |
||
757 |
if (bottom > (x=v->top + v->height)) { |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
758 |
DrawOverlappedWindow(wit, left, top, right, x); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
759 |
DrawOverlappedWindow(wit, left, x, right, bottom); |
0 | 760 |
return; |
761 |
} |
|
762 |
||
763 |
return; |
|
764 |
} |
|
765 |
} |
|
766 |
||
767 |
{ |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
768 |
DrawPixelInfo *dp = _cur_dpi; |
0 | 769 |
dp->width = right - left; |
770 |
dp->height = bottom - top; |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
771 |
dp->left = left - w->left; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
772 |
dp->top = top - w->top; |
0 | 773 |
dp->pitch = _screen.pitch; |
774 |
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left; |
|
775 |
dp->zoom = 0; |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
776 |
CallWindowEventNP(w, WE_PAINT); |
0 | 777 |
} |
778 |
} |
|
779 |
||
780 |
void CallWindowEventNP(Window *w, int event) |
|
781 |
{ |
|
782 |
WindowEvent e; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
783 |
|
0 | 784 |
e.event = event; |
785 |
w->wndproc(w, &e); |
|
786 |
} |
|
787 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
788 |
/** Find the z-value of a window. A window must already be open |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
789 |
* or the behaviour is undefined but function should never fail */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
790 |
//WindowList::Iterator FindWindowZPosition(const Window *w) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
791 |
//{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
792 |
// Window *wz; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
793 |
// FOR_ALL_WINDOWS(wz) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
794 |
// if (wz == w) return it; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
795 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
796 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
797 |
// DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls", |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
798 |
// w->window_class, w->window_number); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
799 |
// return Window::s_list.m_list.end(); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
800 |
//} |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
801 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
802 |
//Window *FindWindowById(WindowClass cls, WindowNumber number) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
803 |
//{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
804 |
// Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
805 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
806 |
// FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
807 |
// if (w->window_class == cls && w->window_number == number) return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
808 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
809 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
810 |
// return NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
811 |
//} |
0 | 812 |
|
813 |
void DeleteWindowById(WindowClass cls, WindowNumber number) |
|
814 |
{ |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
815 |
Window *w = Window::FindById(cls, number); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
816 |
if (w != NULL) w->Close(); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
817 |
} |
0 | 818 |
|
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
|
819 |
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
|
820 |
{ |
2639 | 821 |
|
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
|
822 |
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
|
823 |
/* 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
|
824 |
* 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
|
825 |
* anywhere in the z-array */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
826 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
827 |
FOR_ALL_WINDOWS(w) { |
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
|
828 |
if (w->window_class == cls) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
829 |
w->Close(); |
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
|
830 |
goto restart_search; |
2639 | 831 |
} |
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
|
832 |
} |
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
|
833 |
} |
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
|
834 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
835 |
/** 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
|
836 |
* 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
|
837 |
* 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
|
838 |
* @param id PlayerID player identifier */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
839 |
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
|
840 |
{ |
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
|
841 |
|
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
|
842 |
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
|
843 |
/* 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
|
844 |
* 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
|
845 |
* anywhere in the z-array */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
846 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
847 |
FOR_ALL_WINDOWS(w) { |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
848 |
if (w->caption_color == id) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
849 |
w->Close(); |
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
|
850 |
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
|
851 |
} |
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
|
852 |
} |
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
|
853 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
854 |
/* 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
|
855 |
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
|
856 |
} |
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
|
857 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
858 |
/** 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
|
859 |
* 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
|
860 |
* 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
|
861 |
* @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
|
862 |
* @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
|
863 |
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
|
864 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
865 |
Window *w; |
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
|
866 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
867 |
FOR_ALL_WINDOWS(w) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
868 |
|
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
|
869 |
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
|
870 |
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
|
871 |
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
|
872 |
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
|
873 |
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
|
874 |
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
|
875 |
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
|
876 |
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
|
877 |
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
|
878 |
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
|
879 |
|
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
|
880 |
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
|
881 |
} |
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
|
882 |
} |
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
|
883 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
884 |
/** 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
|
885 |
* 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
|
886 |
* - 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
|
887 |
* - 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
|
888 |
* - 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
|
889 |
* @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
|
890 |
*/ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
891 |
//static Window *FindDeletableWindow(void) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
892 |
//{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
893 |
// Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
894 |
// FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
895 |
// if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
896 |
// return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
897 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
898 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
899 |
// FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
900 |
// if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
901 |
// return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
902 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
903 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
904 |
// return NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
905 |
//} |
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
|
906 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
907 |
/** 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
|
908 |
* 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
|
909 |
* 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
|
910 |
* 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
|
911 |
* @see FindDeletableWindow() |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
912 |
* @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
|
913 |
*/ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
914 |
//static Window *ForceFindDeletableWindow(void) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
915 |
//{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
916 |
// Window* const *wz; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
917 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
918 |
// for (wz = _z_windows;; wz++) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
919 |
// Window *w = *wz; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
920 |
// assert(wz < _last_z_window); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
921 |
// if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
922 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
923 |
//} |
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
|
924 |
|
4171 | 925 |
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
|
926 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
927 |
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
|
928 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
929 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
930 |
/* Copies 'widget' to 'w->widget' to allow for resizable windows */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
931 |
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
|
932 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
933 |
w->original_widget = widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
934 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
935 |
if (widget != NULL) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
936 |
uint index = 1; |
4171 | 937 |
const Widget *wi; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
938 |
|
2639 | 939 |
for (wi = widget; wi->type != WWT_LAST; wi++) index++; |
940 |
||
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
|
941 |
w->widget = ReallocT(w->widget, index); |
2639 | 942 |
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
|
943 |
w->widget_count = index - 1; |
2639 | 944 |
} else { |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
945 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
946 |
w->widget_count = 0; |
2639 | 947 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
948 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
949 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
950 |
//static Window *FindFreeWindow(void) |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
951 |
//{ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
952 |
// Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
953 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
954 |
// for (w = _windows; w < endof(_windows); w++) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
955 |
// Window* const *wz; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
956 |
// bool window_in_use = false; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
957 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
958 |
// FOR_ALL_WINDOWS(wz) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
959 |
// if (*wz == w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
960 |
// window_in_use = true; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
961 |
// break; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
962 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
963 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
964 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
965 |
// if (!window_in_use) return w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
966 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
967 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
968 |
// assert(_last_z_window == endof(_z_windows)); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
969 |
// return NULL; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
970 |
//} |
0 | 971 |
|
972 |
||
973 |
typedef struct SizeRect { |
|
974 |
int left,top,width,height; |
|
975 |
} SizeRect; |
|
976 |
||
977 |
||
978 |
static SizeRect _awap_r; |
|
979 |
||
980 |
static bool IsGoodAutoPlace1(int left, int top) |
|
981 |
{ |
|
982 |
int right,bottom; |
|
983 |
||
984 |
_awap_r.left= left; |
|
985 |
_awap_r.top = top; |
|
986 |
right = _awap_r.width + left; |
|
987 |
bottom = _awap_r.height + top; |
|
988 |
||
989 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
|
990 |
return false; |
|
991 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
992 |
// Make sure it is not obscured by any window. |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
993 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
994 |
FOR_ALL_WINDOWS(w) { |
2639 | 995 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 996 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
997 |
if (right > w->left && |
2639 | 998 |
w->left + w->width > left && |
0 | 999 |
bottom > w->top && |
2639 | 1000 |
w->top + w->height > top) { |
1001 |
return false; |
|
1002 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1003 |
} |
0 | 1004 |
|
1005 |
return true; |
|
1006 |
} |
|
1007 |
||
1008 |
static bool IsGoodAutoPlace2(int left, int top) |
|
1009 |
{ |
|
1010 |
int width,height; |
|
1011 |
||
1012 |
_awap_r.left= left; |
|
1013 |
_awap_r.top = top; |
|
1014 |
width = _awap_r.width; |
|
1015 |
height = _awap_r.height; |
|
1016 |
||
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1017 |
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
|
1018 |
if (top < 22 || top > _screen.height - (height>>2)) return false; |
0 | 1019 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1020 |
// Make sure it is not obscured by any window. |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1021 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1022 |
FOR_ALL_WINDOWS(w) { |
2639 | 1023 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 1024 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1025 |
if (left + width > w->left && |
2639 | 1026 |
w->left + w->width > left && |
0 | 1027 |
top + height > w->top && |
2639 | 1028 |
w->top + w->height > top) { |
1029 |
return false; |
|
1030 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1031 |
} |
0 | 1032 |
|
1033 |
return true; |
|
1034 |
} |
|
1035 |
||
1095 | 1036 |
static Point GetAutoPlacePosition(int width, int height) |
1037 |
{ |
|
0 | 1038 |
Point pt; |
1039 |
||
1040 |
_awap_r.width = width; |
|
1041 |
_awap_r.height = height; |
|
1042 |
||
1043 |
if (IsGoodAutoPlace1(0, 24)) goto ok_pos; |
|
1044 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1045 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1046 |
FOR_ALL_WINDOWS(w) { |
2639 | 1047 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 1048 |
|
1049 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos; |
|
1050 |
if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos; |
|
1051 |
if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos; |
|
1052 |
if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos; |
|
1053 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos; |
|
1054 |
if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos; |
|
1055 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos; |
|
1056 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1057 |
} |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1058 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1059 |
FOR_ALL_WINDOWS(w) { |
2639 | 1060 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 1061 |
|
1062 |
if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos; |
|
1063 |
if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos; |
|
1064 |
if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos; |
|
1065 |
if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos; |
|
1066 |
} |
|
1067 |
||
1068 |
{ |
|
1069 |
int left=0,top=24; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1070 |
|
0 | 1071 |
restart:; |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1072 |
FOR_ALL_WINDOWS(w) { |
0 | 1073 |
if (w->left == left && w->top == top) { |
1074 |
left += 5; |
|
1075 |
top += 5; |
|
1076 |
goto restart; |
|
1077 |
} |
|
1078 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1079 |
|
0 | 1080 |
pt.x = left; |
1081 |
pt.y = top; |
|
1082 |
return pt; |
|
1083 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1084 |
|
0 | 1085 |
ok_pos:; |
1086 |
pt.x = _awap_r.left; |
|
1087 |
pt.y = _awap_r.top; |
|
1088 |
return pt; |
|
1089 |
} |
|
1090 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1091 |
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number) |
0 | 1092 |
{ |
1093 |
Point pt; |
|
1094 |
Window *w; |
|
1095 |
||
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
1096 |
/* By default position a child window at an offset of 10/10 of its parent. |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
1097 |
* 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
|
1098 |
* 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
|
1099 |
if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ && |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1100 |
(w = Window::FindById(desc->parent_cls, window_number)) != NULL && |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
1101 |
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
|
1102 |
|
0 | 1103 |
pt.x = w->left + 10; |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
1104 |
if (pt.x > _screen.width + 10 - desc->width) { |
0 | 1105 |
pt.x = (_screen.width + 10 - desc->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
|
1106 |
} |
0 | 1107 |
pt.y = w->top + 10; |
1108 |
} else { |
|
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1109 |
switch (desc->left) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1110 |
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1111 |
w = Window::FindById(WC_MAIN_TOOLBAR, 0); |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1112 |
pt.x = (w->left + w->width) - desc->width; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1113 |
} break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1114 |
case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1115 |
pt.x = Window::FindById(WC_MAIN_TOOLBAR, 0)->left; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1116 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1117 |
case WDP_AUTO: /* Find a good automatic position for the window */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1118 |
pt = GetAutoPlacePosition(desc->width, desc->height); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1119 |
goto allocate_window; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1120 |
case WDP_CENTER: /* Centre the window horizontally */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1121 |
pt.x = (_screen.width - desc->width) / 2; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1122 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1123 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1124 |
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
|
1125 |
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
|
1126 |
} |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1127 |
|
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1128 |
switch (desc->top) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1129 |
case WDP_CENTER: /* Centre the window vertically */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1130 |
pt.y = (_screen.height - desc->height) / 2; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1131 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1132 |
/* 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
|
1133 |
* 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
|
1134 |
case WDP_AUTO: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1135 |
NOT_REACHED(); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1136 |
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
|
1137 |
/* fallthrough */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1138 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1139 |
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
|
1140 |
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
|
1141 |
break; |
0 | 1142 |
} |
1143 |
} |
|
1144 |
||
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1145 |
allocate_window: |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1146 |
w = new Window(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets, window_number); |
0 | 1147 |
w->desc_flags = desc->flags; |
1148 |
return w; |
|
1149 |
} |
|
1150 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1151 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1152 |
* 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
|
1153 |
* @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
|
1154 |
* @return @see Window pointer of the newly created window |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1155 |
*/ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1156 |
Window *AllocateWindowDesc(const WindowDesc *desc) |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1157 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1158 |
return LocalAllocateWindowDesc(desc, 0); |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1159 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1160 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1161 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1162 |
* 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
|
1163 |
* @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
|
1164 |
* @param window_number the window number of the 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
|
1165 |
* @return @see Window pointer of the newly created window |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1166 |
*/ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1167 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number) |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1168 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1169 |
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
|
1170 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1171 |
if (Window::BringToFrontById(desc->cls, window_number) != NULL) return NULL; |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1172 |
w = LocalAllocateWindowDesc(desc, window_number); |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1173 |
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
|
1174 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1175 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1176 |
/** 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
|
1177 |
* at the topmost window, obviously and work our way down to the bottom |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1178 |
* @return a pointer to the found window if any, NULL otherwise */ |
0 | 1179 |
Window *FindWindowFromPt(int x, int y) |
1180 |
{ |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1181 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1182 |
REVERSED_FOR_ALL_WINDOWS(w) { |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1183 |
if (IS_INSIDE_1D(x, w->left, w->width) && IS_INSIDE_1D(y, w->top, w->height)) { |
2639 | 1184 |
return w; |
1185 |
} |
|
0 | 1186 |
} |
1187 |
||
1188 |
return NULL; |
|
1189 |
} |
|
1190 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1191 |
void InitWindowSystem(void) |
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
|
1192 |
{ |
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
1193 |
IConsoleClose(); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1194 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1195 |
//memset(&_windows, 0, sizeof(_windows)); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1196 |
//_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
|
1197 |
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
|
1198 |
_no_scroll = 0; |
0 | 1199 |
} |
1200 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1201 |
void UnInitWindowSystem(void) |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1202 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1203 |
Window::s_list.m_list.clear(); |
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
|
1204 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1205 |
// Window **wz; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1206 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1207 |
//restart_search: |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1208 |
// /* Delete all windows, reset z-array. |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1209 |
// *When we find the window to delete, we need to restart the search |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1210 |
// * as deleting this window could cascade in deleting (many) others |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1211 |
// * anywhere in the z-array. We call DeleteWindow() so that it can properly |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1212 |
// * release own alloc'd memory, which otherwise could result in memleaks */ |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1213 |
// FOR_ALL_WINDOWS(wz) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1214 |
// DeleteWindow(*wz); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1215 |
// goto restart_search; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1216 |
// } |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1217 |
// |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1218 |
// assert(_last_z_window == _z_windows); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1219 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1220 |
|
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1221 |
void ResetWindowSystem(void) |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1222 |
{ |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1223 |
UnInitWindowSystem(); |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1224 |
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
|
1225 |
_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
|
1226 |
_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
|
1227 |
_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
|
1228 |
_thd.new_pos.y = 0; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1229 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1230 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1231 |
static void DecreaseWindowCounters(void) |
0 | 1232 |
{ |
1233 |
Window *w; |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1234 |
REVERSED_FOR_ALL_WINDOWS(w) { |
0 | 1235 |
// Unclick scrollbar buttons if they are pressed. |
1236 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { |
|
1237 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1238 |
w->SetDirty(); |
0 | 1239 |
} |
1240 |
CallWindowEventNP(w, WE_MOUSELOOP); |
|
1241 |
} |
|
1242 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1243 |
REVERSED_FOR_ALL_WINDOWS(w) { |
0 | 1244 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { |
1245 |
CallWindowEventNP(w, WE_TIMEOUT); |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1246 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons(); |
0 | 1247 |
} |
1248 |
} |
|
1249 |
} |
|
1250 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1251 |
Window *GetCallbackWnd(void) |
0 | 1252 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1253 |
return Window::FindById(_thd.window_class, _thd.window_number); |
0 | 1254 |
} |
1255 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1256 |
static void HandlePlacePresize(void) |
0 | 1257 |
{ |
1258 |
Window *w; |
|
1259 |
WindowEvent e; |
|
1260 |
||
2639 | 1261 |
if (_special_mouse_mode != WSM_PRESIZE) return; |
0 | 1262 |
|
2639 | 1263 |
w = GetCallbackWnd(); |
1264 |
if (w == NULL) return; |
|
0 | 1265 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1266 |
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
|
1267 |
if (e.we.place.pt.x == -1) { |
0 | 1268 |
_thd.selend.x = -1; |
1269 |
return; |
|
1270 |
} |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1271 |
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y); |
0 | 1272 |
e.event = WE_PLACE_PRESIZE; |
1273 |
w->wndproc(w, &e); |
|
1274 |
} |
|
1275 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1276 |
static bool HandleDragDrop(void) |
0 | 1277 |
{ |
1278 |
Window *w; |
|
1279 |
WindowEvent e; |
|
1280 |
||
2639 | 1281 |
if (_special_mouse_mode != WSM_DRAGDROP) return true; |
0 | 1282 |
|
2639 | 1283 |
if (_left_button_down) return false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1284 |
|
0 | 1285 |
w = GetCallbackWnd(); |
1286 |
||
1287 |
ResetObjectToPlace(); |
|
1288 |
||
2639 | 1289 |
if (w != NULL) { |
0 | 1290 |
// send an event in client coordinates. |
1291 |
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
|
1292 |
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
|
1293 |
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
|
1294 |
e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y); |
0 | 1295 |
w->wndproc(w, &e); |
1296 |
} |
|
1297 |
return false; |
|
1298 |
} |
|
1299 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1300 |
static bool HandlePopupMenu(void) |
0 | 1301 |
{ |
1302 |
Window *w; |
|
1303 |
WindowEvent e; |
|
1304 |
||
2639 | 1305 |
if (!_popup_menu_active) return true; |
0 | 1306 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1307 |
w = Window::FindById(WC_TOOLBAR_MENU, 0); |
0 | 1308 |
if (w == NULL) { |
1309 |
_popup_menu_active = false; |
|
1310 |
return false; |
|
1311 |
} |
|
1312 |
||
1313 |
if (_left_button_down) { |
|
1314 |
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
|
1315 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1316 |
} else { |
1317 |
_popup_menu_active = false; |
|
1318 |
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
|
1319 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1320 |
} |
1321 |
||
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
|
1322 |
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
|
1323 |
|
0 | 1324 |
return false; |
1325 |
} |
|
1326 |
||
1095 | 1327 |
static bool HandleMouseOver(void) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1328 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1329 |
static WindowClass last_cls; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1330 |
static WindowNumber last_num; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1331 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1332 |
Window *w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1333 |
WindowEvent e; |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1334 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1335 |
Window *last_w = Window::FindById(last_cls, last_num); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1336 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1337 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1338 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1339 |
// We changed window, put a MOUSEOVER event to the last window |
2639 | 1340 |
if (last_w != NULL && last_w != w) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1341 |
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
|
1342 |
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
|
1343 |
e.we.mouseover.pt.y = -1; |
2639 | 1344 |
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
|
1345 |
} |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1346 |
|
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1347 |
last_cls = w->window_class; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1348 |
last_num = w->window_number; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1349 |
|
2639 | 1350 |
if (w != NULL) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1351 |
// send an event in client coordinates. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1352 |
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
|
1353 |
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
|
1354 |
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
|
1355 |
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
|
1356 |
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
|
1357 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1358 |
w->wndproc(w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1359 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1360 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1361 |
// Mouseover never stops execution |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1362 |
return true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1363 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1364 |
|
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1365 |
/** 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
|
1366 |
* 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
|
1367 |
* ensuring proper redrawal. |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1368 |
* @param w Window to resize |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1369 |
* @param x delta x-size of changed window (positive if larger, etc.( |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1370 |
* @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
|
1371 |
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
|
1372 |
{ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1373 |
Widget *wi; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1374 |
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
|
1375 |
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
|
1376 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1377 |
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
|
1378 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1379 |
w->SetDirty(); |
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1380 |
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
|
1381 |
/* 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
|
1382 |
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
|
1383 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1384 |
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
|
1385 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1386 |
/* 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
|
1387 |
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
|
1388 |
wi->left += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1389 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1390 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1391 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1392 |
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
|
1393 |
wi->right += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1394 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1395 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1396 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1397 |
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
|
1398 |
wi->top += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1399 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1400 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1401 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1402 |
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
|
1403 |
wi->bottom += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1404 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1405 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1406 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1407 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1408 |
/* 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
|
1409 |
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
|
1410 |
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
|
1411 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1412 |
w->SetDirty(); |
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1413 |
} |
2596 | 1414 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1415 |
static bool HandleScrollbarScrolling(void) |
0 | 1416 |
{ |
1417 |
int i; |
|
1418 |
int pos; |
|
1419 |
Scrollbar *sb; |
|
1420 |
||
1421 |
// Get out quickly if no item is being scrolled |
|
2639 | 1422 |
if (!_scrolling_scrollbar) return true; |
0 | 1423 |
|
1424 |
// Find the scrolling window |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1425 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1426 |
FOR_ALL_WINDOWS(w) { |
0 | 1427 |
if (w->flags4 & WF_SCROLL_MIDDLE) { |
1428 |
// Abort if no button is clicked any more. |
|
1429 |
if (!_left_button_down) { |
|
1430 |
w->flags4 &= ~WF_SCROLL_MIDDLE; |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1431 |
w->SetDirty(); |
0 | 1432 |
break; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1433 |
} |
0 | 1434 |
|
1435 |
if (w->flags4 & WF_HSCROLL) { |
|
1436 |
sb = &w->hscroll; |
|
1437 |
i = _cursor.pos.x - _cursorpos_drag_start.x; |
|
842 | 1438 |
} else if (w->flags4 & WF_SCROLL2){ |
1439 |
sb = &w->vscroll2; |
|
1440 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
0 | 1441 |
} else { |
1442 |
sb = &w->vscroll; |
|
1443 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
1444 |
} |
|
1445 |
||
1446 |
// Find the item we want to move to and make sure it's inside bounds. |
|
1447 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); |
|
1448 |
if (pos != sb->pos) { |
|
1449 |
sb->pos = pos; |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1450 |
w->SetDirty(); |
0 | 1451 |
} |
1452 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1453 |
} |
0 | 1454 |
} |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1455 |
|
0 | 1456 |
_scrolling_scrollbar = false; |
1457 |
return false; |
|
1458 |
} |
|
1459 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1460 |
static bool HandleViewportScroll(void) |
0 | 1461 |
{ |
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
|
1462 |
WindowEvent e; |
0 | 1463 |
Window *w; |
1464 |
||
2639 | 1465 |
if (!_scrolling_viewport) return true; |
0 | 1466 |
|
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
|
1467 |
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
|
1468 |
|
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
|
1469 |
if (!_right_button_down || w == NULL) { |
0 | 1470 |
_cursor.fix_at = false; |
1471 |
_scrolling_viewport = false; |
|
1472 |
return true; |
|
1473 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1474 |
|
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1475 |
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
|
1476 |
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
|
1477 |
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
|
1478 |
} 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
|
1479 |
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
|
1480 |
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
|
1481 |
} |
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1482 |
|
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
|
1483 |
/* 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
|
1484 |
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
|
1485 |
w->wndproc(w, &e); |
0 | 1486 |
|
2989 | 1487 |
_cursor.delta.x = 0; |
1488 |
_cursor.delta.y = 0; |
|
1489 |
return false; |
|
0 | 1490 |
} |
1491 |
||
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1492 |
/** 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
|
1493 |
* 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
|
1494 |
* 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
|
1495 |
* 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
|
1496 |
* 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
|
1497 |
* 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
|
1498 |
* @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
|
1499 |
* @return false if the window has an active modal child, true otherwise */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1500 |
static bool MaybeBringWindowToFront(Window *w) |
0 | 1501 |
{ |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1502 |
bool bring_to_front = false; |
0 | 1503 |
|
2639 | 1504 |
if (w->window_class == WC_MAIN_WINDOW || |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1505 |
w->IsVital() || |
2639 | 1506 |
w->window_class == WC_TOOLTIPS || |
1507 |
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
|
1508 |
return true; |
2639 | 1509 |
} |
0 | 1510 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1511 |
WindowList::Iterator wit = Window::s_list.Find(w); |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1512 |
for (WindowList::Iterator it = wit; it != Window::s_list.m_list.end(); it++) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1513 |
Window *u = (*it).w; |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1514 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1515 |
/* 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
|
1516 |
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
|
1517 |
u->flags4 |= WF_WHITE_BORDER_MASK; |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1518 |
u->SetDirty(); |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1519 |
return false; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1520 |
} |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1521 |
|
2639 | 1522 |
if (u->window_class == WC_MAIN_WINDOW || |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1523 |
u->IsVital() || |
2639 | 1524 |
u->window_class == WC_TOOLTIPS || |
1525 |
u->window_class == WC_DROPDOWN_MENU) { |
|
1526 |
continue; |
|
1527 |
} |
|
0 | 1528 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1529 |
/* Window sizes don't interfere, leave z-order alone */ |
0 | 1530 |
if (w->left + w->width <= u->left || |
1531 |
u->left + u->width <= w->left || |
|
1532 |
w->top + w->height <= u->top || |
|
2639 | 1533 |
u->top + u->height <= w->top) { |
1534 |
continue; |
|
1535 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1536 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1537 |
bring_to_front = true; |
0 | 1538 |
} |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1539 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1540 |
if (bring_to_front) w->BringToFront(); |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1541 |
return true; |
0 | 1542 |
} |
1543 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1544 |
/** Send a message from one window to another. The receiving window is found by |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1545 |
* @param w @see Window pointer pointing to the other window |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1546 |
* @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
|
1547 |
* @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
|
1548 |
* @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
|
1549 |
*/ |
4171 | 1550 |
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
|
1551 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1552 |
WindowEvent e; |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1553 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1554 |
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
|
1555 |
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
|
1556 |
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
|
1557 |
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
|
1558 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1559 |
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
|
1560 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1561 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1562 |
/** Send a message from one window to another. The receiving window is found by |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1563 |
* @param wnd_class @see WindowClass class AND |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1564 |
* @param wnd_num @see WindowNumber number, mostly 0 |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1565 |
* @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
|
1566 |
* @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
|
1567 |
* @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
|
1568 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1569 |
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
|
1570 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1571 |
Window *w = Window::FindById(wnd_class, wnd_num); |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1572 |
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
|
1573 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1574 |
|
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1575 |
/** 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
|
1576 |
* to ALL windows of the windowclass specified in the first parameter |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1577 |
* @param wnd_class @see WindowClass class |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1578 |
* @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
|
1579 |
* @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
|
1580 |
* @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
|
1581 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1582 |
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
|
1583 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1584 |
Window *w; |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1585 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1586 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1587 |
if (w->window_class == wnd_class) SendWindowMessageW(w, 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
|
1588 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1589 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1590 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1591 |
/** Handle keyboard input. |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1592 |
* @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
|
1593 |
* 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
|
1594 |
void HandleKeypress(uint32 key) |
0 | 1595 |
{ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1596 |
WindowEvent e; |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1597 |
/* Stores if a window with a textfield for typing is open |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1598 |
* If this is the case, keypress events are only passed to windows with text fields and |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1599 |
* to thein this main toolbar. */ |
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
|
1600 |
bool query_open = false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1601 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1602 |
/* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1603 |
* 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
|
1604 |
* 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
|
1605 |
* 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
|
1606 |
* 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
|
1607 |
* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1608 |
* 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
|
1609 |
* 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
|
1610 |
*/ |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1611 |
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
|
1612 |
|
0 | 1613 |
// 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
|
1614 |
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
|
1615 |
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
|
1616 |
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
|
1617 |
e.we.keypress.cont = true; |
0 | 1618 |
|
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
|
1619 |
// check if we have a query string window open before allowing hotkeys |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1620 |
if (Window::FindById(WC_QUERY_STRING, 0) != NULL || |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1621 |
Window::FindById(WC_SEND_NETWORK_MSG, 0) != NULL || |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1622 |
Window::FindById(WC_GENERATE_LANDSCAPE, 0) != NULL || |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1623 |
Window::FindById(WC_CONSOLE, 0) != NULL || |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1624 |
Window::FindById(WC_SAVELOAD, 0) != NULL) { |
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
|
1625 |
query_open = true; |
2639 | 1626 |
} |
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
|
1627 |
|
0 | 1628 |
// Call the event, start with the uppermost window. |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1629 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1630 |
REVERSED_FOR_ALL_WINDOWS(w) { |
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
|
1631 |
// if a query window is open, only call the event for certain window types |
2639 | 1632 |
if (query_open && |
1633 |
w->window_class != WC_QUERY_STRING && |
|
1634 |
w->window_class != WC_SEND_NETWORK_MSG && |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1635 |
w->window_class != WC_GENERATE_LANDSCAPE && |
2639 | 1636 |
w->window_class != WC_CONSOLE && |
1637 |
w->window_class != WC_SAVELOAD) { |
|
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
|
1638 |
continue; |
2639 | 1639 |
} |
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 |
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
|
1641 |
if (!e.we.keypress.cont) break; |
0 | 1642 |
} |
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
|
1643 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1644 |
if (e.we.keypress.cont) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1645 |
Window *w = Window::FindById(WC_MAIN_TOOLBAR, 0); |
1642
593a9b750b91
(svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents:
1637
diff
changeset
|
1646 |
// 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
|
1647 |
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
|
1648 |
} |
0 | 1649 |
} |
1650 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1651 |
extern void UpdateTileSelection(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1652 |
extern bool VpHandlePlaceSizingDrag(void); |
0 | 1653 |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1654 |
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
|
1655 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1656 |
static void HandleAutoscroll(void) |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1657 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1658 |
Window *w; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1659 |
ViewPort *vp; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1660 |
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
|
1661 |
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
|
1662 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1663 |
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
|
1664 |
/* 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
|
1665 |
_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
|
1666 |
/* 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
|
1667 |
return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1668 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1669 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1670 |
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
|
1671 |
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
|
1672 |
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
|
1673 |
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
|
1674 |
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
|
1675 |
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
|
1676 |
y -= vp->top; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1677 |
//here allows scrolling in both x and y axis |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1678 |
#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
|
1679 |
if (x - 15 < 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1680 |
WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1681 |
} else if (15 - (vp->width - x) > 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1682 |
WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1683 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1684 |
if (y - 15 < 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1685 |
WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1686 |
} else if (15 - (vp->height - y) > 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1687 |
WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1688 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1689 |
#undef scrollspeed |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1690 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1691 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1692 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1693 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1694 |
void MouseLoop(int click, int mousewheel) |
0 | 1695 |
{ |
1696 |
int x,y; |
|
1697 |
Window *w; |
|
1698 |
ViewPort *vp; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1699 |
|
0 | 1700 |
DecreaseWindowCounters(); |
1701 |
HandlePlacePresize(); |
|
1702 |
UpdateTileSelection(); |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1703 |
if (!VpHandlePlaceSizingDrag()) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1704 |
if (!HandleDragDrop()) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1705 |
if (!HandlePopupMenu()) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1706 |
if (!Window::HandleWindowDragging()) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1707 |
if (!HandleScrollbarScrolling()) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1708 |
if (!HandleViewportScroll()) return; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1709 |
if (!HandleMouseOver()) return; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1710 |
|
0 | 1711 |
x = _cursor.pos.x; |
1712 |
y = _cursor.pos.y; |
|
1713 |
||
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1714 |
if (click == 0 && mousewheel == 0) return; |
0 | 1715 |
|
1716 |
w = FindWindowFromPt(x, y); |
|
2639 | 1717 |
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
|
1718 |
if (!MaybeBringWindowToFront(w)) return; |
0 | 1719 |
vp = IsPtInWindowViewport(w, x, y); |
1720 |
||
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
|
1721 |
/* 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
|
1722 |
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
|
1723 |
|
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
|
1724 |
if (mousewheel != 0) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1725 |
WindowEvent e; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1726 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1727 |
/* Send WE_MOUSEWHEEL event to window */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1728 |
e.event = WE_MOUSEWHEEL; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1729 |
e.we.wheel.wheel = mousewheel; |
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
|
1730 |
w->wndproc(w, &e); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1731 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1732 |
/* 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
|
1733 |
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
|
1734 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1735 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1736 |
if (vp != NULL) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1737 |
switch (click) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1738 |
case 1: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
1739 |
DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); |
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
|
1740 |
if (_thd.place_mode != 0 && |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1741 |
// query button and place sign button work in pause mode |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1742 |
_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
|
1743 |
_cursor.sprite != SPR_CURSOR_SIGN && |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1744 |
_pause != 0 && |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1745 |
!_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
|
1746 |
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
|
1747 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1748 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1749 |
if (_thd.place_mode == 0) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1750 |
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
|
1751 |
} 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
|
1752 |
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
|
1753 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1754 |
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
|
1755 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1756 |
case 2: |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1757 |
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
|
1758 |
_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
|
1759 |
_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
|
1760 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1761 |
break; |
0 | 1762 |
} |
1763 |
} else { |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1764 |
switch (click) { |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1765 |
case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top); break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1766 |
case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break; |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1767 |
} |
0 | 1768 |
} |
1769 |
} |
|
1770 |
||
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1771 |
void HandleMouseEvents(void) |
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
|
1772 |
{ |
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
|
1773 |
int click; |
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
|
1774 |
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
|
1775 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1776 |
/* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1777 |
* 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
|
1778 |
* 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
|
1779 |
* 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
|
1780 |
* NOT change the _current_player here. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1781 |
* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1782 |
* 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
|
1783 |
* 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
|
1784 |
*/ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1785 |
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
|
1786 |
|
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
|
1787 |
// Mouse event? |
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
|
1788 |
click = 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
|
1789 |
if (_left_button_down && !_left_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
|
1790 |
_left_button_clicked = true; |
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
|
1791 |
click = 1; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1792 |
_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
|
1793 |
} 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
|
1794 |
_right_button_clicked = false; |
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
|
1795 |
click = 2; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1796 |
_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
|
1797 |
} |
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
|
1798 |
|
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
|
1799 |
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
|
1800 |
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
|
1801 |
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
|
1802 |
_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
|
1803 |
_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
|
1804 |
} |
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
|
1805 |
|
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
|
1806 |
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
|
1807 |
} |
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
|
1808 |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1809 |
void InputLoop(void) |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1810 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1811 |
HandleMouseEvents(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1812 |
HandleAutoscroll(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1813 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1814 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1815 |
void UpdateWindows(void) |
0 | 1816 |
{ |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1817 |
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
|
1818 |
int t = we4_timer + 1; |
0 | 1819 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1820 |
Window *w; |
2639 | 1821 |
if (t >= 100) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1822 |
REVERSED_FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1823 |
CallWindowEventNP(w, WE_4); |
0 | 1824 |
} |
1825 |
t = 0; |
|
1826 |
} |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1827 |
we4_timer = t; |
0 | 1828 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1829 |
REVERSED_FOR_ALL_WINDOWS(w) { |
0 | 1830 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
1831 |
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
|
1832 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1833 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) w->SetDirty(); |
0 | 1834 |
} |
1835 |
} |
|
1836 |
||
1837 |
DrawDirtyBlocks(); |
|
1838 |
||
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1839 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1840 |
if (w->viewport != NULL) UpdateViewportPosition(w); |
0 | 1841 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1842 |
DrawTextMessage(); |
0 | 1843 |
// Redraw mouse cursor in case it was hidden |
1844 |
DrawMouseCursor(); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1845 |
} |
0 | 1846 |
|
1847 |
||
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
|
1848 |
int GetMenuItemIndex(const Window *w, int x, int y) |
0 | 1849 |
{ |
1850 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { |
|
1851 |
y /= 10; |
|
1852 |
||
2639 | 1853 |
if (y < WP(w, const menu_d).item_count && |
1854 |
!HASBIT(WP(w, const menu_d).disabled_items, y)) { |
|
0 | 1855 |
return y; |
2639 | 1856 |
} |
0 | 1857 |
} |
1858 |
return -1; |
|
1859 |
} |
|
1860 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1861 |
void InvalidateWindow(WindowClass cls, WindowNumber number) |
0 | 1862 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1863 |
Window *w; |
0 | 1864 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1865 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1866 |
if (w->window_class == cls && w->window_number == number) w->SetDirty(); |
0 | 1867 |
} |
1868 |
} |
|
1869 |
||
4171 | 1870 |
void InvalidateWidget(const Window *w, byte widget_index) |
0 | 1871 |
{ |
1872 |
const Widget *wi = &w->widget[widget_index]; |
|
1867
8de1958719fe
(svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents:
1744
diff
changeset
|
1873 |
|
8de1958719fe
(svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents:
1744
diff
changeset
|
1874 |
/* Don't redraw the window if the widget is invisible or of no-type */ |
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
|
1875 |
if (wi->type == WWT_EMPTY || IsWindowWidgetHidden(w, widget_index)) return; |
1867
8de1958719fe
(svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents:
1744
diff
changeset
|
1876 |
|
8de1958719fe
(svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents:
1744
diff
changeset
|
1877 |
SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1); |
0 | 1878 |
} |
1879 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1880 |
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index) |
0 | 1881 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1882 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1883 |
FOR_ALL_WINDOWS(w) { |
2639 | 1884 |
if (w->window_class == cls && w->window_number == number) { |
0 | 1885 |
InvalidateWidget(w, widget_index); |
1886 |
} |
|
1887 |
} |
|
1888 |
} |
|
1889 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1890 |
void InvalidateWindowClasses(WindowClass cls) |
0 | 1891 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1892 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1893 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1894 |
if (w->window_class == cls) w->SetDirty(); |
0 | 1895 |
} |
1896 |
} |
|
1897 |
||
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
|
1898 |
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
|
1899 |
{ |
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
|
1900 |
CallWindowEventNP(w, WE_INVALIDATE_DATA); |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1901 |
w->SetDirty(); |
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
|
1902 |
} |
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
|
1903 |
|
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1904 |
void InvalidateWindowData(WindowClass cls, WindowNumber number) |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1905 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1906 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1907 |
FOR_ALL_WINDOWS(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
|
1908 |
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
|
1909 |
} |
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
|
1910 |
} |
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
|
1911 |
|
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
|
1912 |
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
|
1913 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1914 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1915 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1916 |
if (w->window_class == cls) InvalidateThisWindowData(w); |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1917 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1918 |
} |
0 | 1919 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1920 |
void CallWindowTickEvent(void) |
0 | 1921 |
{ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1922 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1923 |
REVERSED_FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1924 |
CallWindowEventNP(w, WE_TICK); |
0 | 1925 |
} |
1926 |
} |
|
1927 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1928 |
void DeleteNonVitalWindows(void) |
0 | 1929 |
{ |
2639 | 1930 |
|
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
|
1931 |
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
|
1932 |
/* 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
|
1933 |
* 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
|
1934 |
* anywhere in the z-array */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1935 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1936 |
FOR_ALL_WINDOWS(w) { |
0 | 1937 |
if (w->window_class != WC_MAIN_WINDOW && |
1938 |
w->window_class != WC_SELECT_GAME && |
|
1939 |
w->window_class != WC_MAIN_TOOLBAR && |
|
1940 |
w->window_class != WC_STATUS_BAR && |
|
1941 |
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
|
1942 |
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
|
1943 |
(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
|
1944 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1945 |
w->Close(); |
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
|
1946 |
goto restart_search; |
0 | 1947 |
} |
1948 |
} |
|
1949 |
} |
|
1950 |
||
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1951 |
/* 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
|
1952 |
* '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
|
1953 |
* 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
|
1954 |
* 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
|
1955 |
* that standard windows (status bar, etc.) are not stickied, so these aren't affected */ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1956 |
void DeleteAllNonVitalWindows(void) |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1957 |
{ |
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
|
1958 |
/* 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
|
1959 |
DeleteNonVitalWindows(); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1960 |
|
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
|
1961 |
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
|
1962 |
/* 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
|
1963 |
* 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
|
1964 |
* anywhere in the z-array */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1965 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1966 |
FOR_ALL_WINDOWS(w) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1967 |
if (w->flags4 & WF_STICKY) { |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1968 |
w->Close(); |
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
|
1969 |
goto restart_search; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1970 |
} |
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
|
1971 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1972 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1973 |
|
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
|
1974 |
/* Delete all always on-top windows to get an empty screen */ |
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
|
1975 |
void HideVitalWindows(void) |
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
|
1976 |
{ |
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
|
1977 |
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
|
1978 |
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
|
1979 |
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
|
1980 |
} |
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
|
1981 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1982 |
int PositionMainToolbar(Window *w) |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1983 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
1984 |
DEBUG(misc, 5, "Repositioning Main Toolbar..."); |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1985 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1986 |
if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) { |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
1987 |
w = Window::FindById(WC_MAIN_TOOLBAR, 0); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1988 |
} |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1989 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1990 |
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
|
1991 |
case 1: w->left = (_screen.width - w->width) / 2; break; |
2026 | 1992 |
case 2: w->left = _screen.width - w->width; break; |
1993 |
default: w->left = 0; |
|
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1994 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1995 |
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
|
1996 |
return w->left; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1997 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1998 |
|
0 | 1999 |
void RelocateAllWindows(int neww, int newh) |
2000 |
{ |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
2001 |
Window *w; |
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
6158
diff
changeset
|
2002 |
FOR_ALL_WINDOWS(w) { |
0 | 2003 |
int left, top; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
2004 |
|
0 | 2005 |
if (w->window_class == WC_MAIN_WINDOW) { |
2006 |
ViewPort *vp = w->viewport; |
|
2007 |
vp->width = w->width = neww; |
|
2008 |
vp->height = w->height = newh; |
|
2009 |
vp->virtual_width = neww << vp->zoom; |
|
2010 |
vp->virtual_height = newh << vp->zoom; |
|
2011 |
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
|
2012 |
} |
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
|
2013 |
|
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2014 |
/* 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
|
2015 |
* in a 'backup'-desc that the window should always be centred. */ |
2989 | 2016 |
switch (w->window_class) { |
2017 |
case WC_MAIN_TOOLBAR: |
|
2018 |
top = w->top; |
|
2019 |
left = PositionMainToolbar(w); // changes toolbar orientation |
|
2020 |
break; |
|
2021 |
||
2022 |
case WC_SELECT_GAME: |
|
2023 |
case WC_GAME_OPTIONS: |
|
2024 |
case WC_NETWORK_WINDOW: |
|
2025 |
top = (newh - w->height) >> 1; |
|
2026 |
left = (neww - w->width) >> 1; |
|
2027 |
break; |
|
2028 |
||
2029 |
case WC_NEWS_WINDOW: |
|
2030 |
top = newh - w->height; |
|
2031 |
left = (neww - w->width) >> 1; |
|
2032 |
break; |
|
2033 |
||
2034 |
case WC_STATUS_BAR: |
|
2035 |
top = newh - w->height; |
|
2036 |
left = (neww - w->width) >> 1; |
|
2037 |
break; |
|
2038 |
||
2039 |
case WC_SEND_NETWORK_MSG: |
|
2040 |
top = (newh - 26); // 26 = height of status bar + height of chat bar |
|
2041 |
left = (neww - w->width) >> 1; |
|
2042 |
break; |
|
2043 |
||
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2044 |
case WC_CONSOLE: |
5143
a78072872bff
(svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents:
5137
diff
changeset
|
2045 |
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
|
2046 |
continue; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2047 |
|
2989 | 2048 |
default: |
2049 |
left = w->left; |
|
2050 |
if (left + (w->width >> 1) >= neww) left = neww - w->width; |
|
2051 |
top = w->top; |
|
2052 |
if (top + (w->height >> 1) >= newh) top = newh - w->height; |
|
2053 |
break; |
|
0 | 2054 |
} |
2055 |
||
2639 | 2056 |
if (w->viewport != NULL) { |
0 | 2057 |
w->viewport->left += left - w->left; |
2058 |
w->viewport->top += top - w->top; |
|
2059 |
} |
|
2060 |
||
2061 |
w->left = left; |
|
2062 |
w->top = top; |
|
2063 |
} |
|
2064 |
} |