forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_frame.cc
159 lines (134 loc) · 4.05 KB
/
gui_frame.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (c) 1997 - 2001 Hansjörg Malthaner
*
* This file is part of the Simutrans project under the artistic licence.
* (see licence.txt)
*/
/*
* The window frame all dialogs are based
* [Mathew Hounsell] Min Size Button On Map Window 20030313
*/
#include <stdio.h>
#include "gui_frame.h"
#include "../simcolor.h"
#include "../display/simgraph.h"
#include "../gui/simwin.h"
#include "../simworld.h"
#include "../player/simplay.h"
#include "../besch/reader/obj_reader.h"
#include "../besch/skin_besch.h"
#include "../simskin.h"
karte_ptr_t gui_frame_t::welt;
// Insert the container
gui_frame_t::gui_frame_t(char const* const name, player_t const* const player)
{
this->name = name;
size = scr_size(200, 100);
min_windowsize = scr_size(0,0);
owner = player;
container.set_pos(scr_coord(0,D_TITLEBAR_HEIGHT));
set_resizemode(no_resize); //25-may-02 markus weber added
opaque = true;
dirty = true;
}
/**
* Set the window size
* @author Hj. Malthaner
*/
void gui_frame_t::set_windowsize(scr_size size)
{
if( size != this->size ) {
// mark old size dirty
scr_coord const& pos = win_get_pos(this);
mark_rect_dirty_wc( pos.x, pos.y, pos.x+this->size.w, pos.y+this->size.h );
// minimum size //25-may-02 markus weber added
size.clip_lefttop(min_windowsize);
this->size = size;
dirty = true;
}
}
/**
* get color information for the window title
* -borders and -body background
* @author Hj. Malthaner
*/
PLAYER_COLOR_VAL gui_frame_t::get_titlecolor() const
{
return owner ? PLAYER_FLAG|(owner->get_player_color1()+1) : WIN_TITLE;
}
/**
* Events werden hiermit an die GUI-Komponenten
* gemeldet
* @author Hj. Malthaner
*/
bool gui_frame_t::infowin_event(const event_t *ev)
{
// %DB0 printf( "\nMessage: gui_frame_t::infowin_event( event_t const * ev ) : Fenster|Window %p : Event is %d", (void*)this, ev->ev_class );
if(IS_WINDOW_RESIZE(ev)) {
scr_coord delta ( resize_mode & horizonal_resize ? ev->mx - ev->cx : 0,
resize_mode & vertical_resize ? ev->my - ev->cy : 0);
resize(delta);
return true; // don't pass to children!
}
else if(IS_WINDOW_MAKE_MIN_SIZE(ev)) {
set_windowsize( get_min_windowsize() ) ;
resize( scr_coord(0,0) ) ;
return true; // don't pass to children!
}
else if(ev->ev_class==INFOWIN && (ev->ev_code==WIN_CLOSE || ev->ev_code==WIN_OPEN || ev->ev_code==WIN_TOP)) {
dirty = true;
container.clear_dirty();
}
event_t ev2 = *ev;
translate_event(&ev2, 0, -D_TITLEBAR_HEIGHT);
return container.infowin_event(&ev2);
}
/**
* resize window in response to a resize event
* @author Markus Weber, Hj. Malthaner
* @date 11-may-02
*/
void gui_frame_t::resize(const scr_coord delta)
{
dirty = true;
scr_size new_size = size + delta;
// resize window to the minimum size
new_size.clip_lefttop(min_windowsize);
scr_coord size_change = new_size - size;
// resize window
set_windowsize(new_size);
// change drag start
change_drag_start(size_change.x, size_change.y);
}
/**
* Draw new component. The values to be passed refer to the window
* i.e. It's the screen coordinates of the window where the
* component is displayed.
*
* @author Hj. Malthaner
*/
void gui_frame_t::draw(scr_coord pos, scr_size size)
{
// draw background
if( opaque ) {
display_img_stretch( gui_theme_t::windowback, scr_rect( pos + scr_coord(0,D_TITLEBAR_HEIGHT), size - scr_size(0,D_TITLEBAR_HEIGHT) ) );
if( dirty ) {
mark_rect_dirty_wc(pos.x, pos.y, pos.x + size.w, pos.y + D_TITLEBAR_HEIGHT );
}
}
else {
if( dirty ) {
mark_rect_dirty_wc(pos.x, pos.y, pos.x + size.w, pos.y + size.h + D_TITLEBAR_HEIGHT );
}
display_blend_wh( pos.x+1, pos.y+D_TITLEBAR_HEIGHT, size.w-2, size.h-D_TITLEBAR_HEIGHT, color_transparent, percent_transparent );
}
dirty = false;
PUSH_CLIP(pos.x+1, pos.y+D_TITLEBAR_HEIGHT, size.w-2, size.h-D_TITLEBAR_HEIGHT);
container.draw(pos);
POP_CLIP();
// for shadows of the windows
if( gui_theme_t::gui_drop_shadows ) {
display_blend_wh( pos.x+size.w, pos.y+1, 2, size.h, COL_BLACK, 50 );
display_blend_wh( pos.x+1, pos.y+size.h, size.w, 2, COL_BLACK, 50 );
}
}