… | |
… | |
41 | |
41 | |
42 | our @GL_INIT; # hooks called on every gl init |
42 | our @GL_INIT; # hooks called on every gl init |
43 | |
43 | |
44 | our $ALT_ENTER_MESSAGE; |
44 | our $ALT_ENTER_MESSAGE; |
45 | |
45 | |
|
|
46 | our $TOPLEVEL; |
|
|
47 | |
46 | our $tw; # Test widget #d# |
48 | our $tw; # Test widget #d# |
|
|
49 | |
|
|
50 | my $last_refresh; |
47 | |
51 | |
48 | sub init_screen { |
52 | sub init_screen { |
49 | $SDL_APP = new SDL::App |
53 | $SDL_APP = new SDL::App |
50 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
54 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
51 | -title => "Crossfire+ Client", |
55 | -title => "Crossfire+ Client", |
… | |
… | |
57 | -blue_size => 8, |
61 | -blue_size => 8, |
58 | -double_buffer => 1, |
62 | -double_buffer => 1, |
59 | -fullscreen => $FULLSCREEN, |
63 | -fullscreen => $FULLSCREEN, |
60 | -resizeable => 0; |
64 | -resizeable => 0; |
61 | |
65 | |
|
|
66 | $last_refresh = SDL::GetTicks; |
|
|
67 | |
62 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
68 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
63 | |
69 | |
64 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
70 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
65 | or warn "WARNING: non-power-of-two opengl extension required"; |
71 | or warn "WARNING: non-power-of-two opengl extension required"; |
66 | |
72 | |
67 | $FONTSIZE = int $HEIGHT / 40; |
73 | $FONTSIZE = int $HEIGHT / 50; |
68 | |
74 | |
69 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, "Alt-Enter toggles fullscreen mode"; |
75 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
|
|
76 | 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, |
|
|
77 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
70 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
78 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
71 | $ALT_ENTER_MESSAGE->activate; |
79 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
72 | |
80 | |
73 | # Test code #d# |
81 | # Test code #d# |
74 | { |
82 | unless ($tw) { # haha... |
75 | my $frm = new Crossfire::Client::Widget::Frame; |
|
|
76 | $tw = new Crossfire::Client::Widget::Window; |
83 | $tw = new Crossfire::Client::Widget::Animator; |
77 | $frm->add (new Crossfire::Client::Widget::Label 0, 0, 10, $FONTSIZE, "Foo in the garden!"); |
84 | $tw->add (my $f = new Crossfire::Client::Widget::FancyFrame); |
78 | $tw->add ($frm); |
85 | $f->add ( |
|
|
86 | my $te = new Crossfire::Client::Widget::Label |
|
|
87 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!" |
|
|
88 | ); |
79 | |
89 | |
|
|
90 | $tw->move ($WIDTH - 200, 0); |
80 | $tw->move (0, $HEIGHT - 120); |
91 | $tw->moveto (0, 0); |
81 | $tw->activate; |
92 | $TOPLEVEL->add ($tw); |
82 | } |
93 | } |
83 | |
94 | |
84 | glClearColor 0, 0, 0, 0; |
95 | glClearColor 0, 0, 0, 0; |
85 | |
96 | |
86 | glEnable GL_TEXTURE_2D; |
97 | glEnable GL_TEXTURE_2D; |
… | |
… | |
112 | user => $CFG->{user}, |
123 | user => $CFG->{user}, |
113 | pass => $CFG->{password}, |
124 | pass => $CFG->{password}, |
114 | mapw => 50, |
125 | mapw => 50, |
115 | maph => 37, |
126 | maph => 37, |
116 | ; |
127 | ; |
|
|
128 | |
|
|
129 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
117 | } |
130 | } |
118 | |
131 | |
119 | sub stop_game { |
132 | sub stop_game { |
120 | remove Glib::Source $SDL_TIMER; |
133 | remove Glib::Source $SDL_TIMER; |
121 | |
134 | |
… | |
… | |
127 | sub force_refresh { |
140 | sub force_refresh { |
128 | glViewport 0, 0, $WIDTH, $HEIGHT; |
141 | glViewport 0, 0, $WIDTH, $HEIGHT; |
129 | |
142 | |
130 | glMatrixMode GL_PROJECTION; |
143 | glMatrixMode GL_PROJECTION; |
131 | glLoadIdentity; |
144 | glLoadIdentity; |
132 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
145 | glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; |
133 | glMatrixMode GL_MODELVIEW; |
146 | glMatrixMode GL_MODELVIEW; |
134 | |
147 | |
135 | glClear GL_COLOR_BUFFER_BIT; |
148 | glClear GL_COLOR_BUFFER_BIT; |
136 | |
149 | |
137 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
150 | $TOPLEVEL->draw; |
138 | |
151 | |
139 | SDL::GLSwapBuffers; |
152 | SDL::GLSwapBuffers; |
140 | } |
153 | } |
|
|
154 | |
|
|
155 | my %ANIMATE; |
141 | |
156 | |
142 | my $refresh_handler; |
157 | my $refresh_handler; |
143 | |
158 | |
144 | sub refresh { |
159 | sub refresh { |
145 | $refresh_handler ||= add Glib::Idle sub { |
160 | $refresh_handler ||= add Glib::Idle sub { |
|
|
161 | my $next_refresh = SDL::GetTicks; |
|
|
162 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
|
|
163 | $last_refresh = $next_refresh; |
|
|
164 | |
146 | force_refresh; |
165 | force_refresh; |
|
|
166 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
167 | |
|
|
168 | if (%ANIMATE) { |
|
|
169 | 1 |
|
|
170 | } else { |
147 | undef $refresh_handler; |
171 | undef $refresh_handler; |
|
|
172 | 0 |
148 | 0 |
173 | } |
149 | }; |
174 | }; |
|
|
175 | } |
|
|
176 | |
|
|
177 | sub animation_start { |
|
|
178 | my ($widget) = @_; |
|
|
179 | $ANIMATE{$widget} = $widget; |
|
|
180 | Scalar::Util::weaken $ANIMATE{$widget}; |
|
|
181 | |
|
|
182 | refresh; |
|
|
183 | } |
|
|
184 | |
|
|
185 | sub animation_stop { |
|
|
186 | my ($widget) = @_; |
|
|
187 | delete $ANIMATE{$widget}; |
150 | } |
188 | } |
151 | |
189 | |
152 | %SDL_CB = ( |
190 | %SDL_CB = ( |
153 | SDL_QUIT() => sub { |
191 | SDL_QUIT() => sub { |
154 | main_quit Gtk2; |
192 | main_quit Gtk2; |
… | |
… | |
193 | } |
231 | } |
194 | |
232 | |
195 | sub conn::map_scroll { |
233 | sub conn::map_scroll { |
196 | my ($self, $dx, $dy) = @_; |
234 | my ($self, $dx, $dy) = @_; |
197 | |
235 | |
198 | refresh; |
236 | # refresh; |
199 | } |
237 | } |
200 | |
238 | |
201 | sub conn::map_clear { |
239 | sub conn::map_clear { |
202 | my ($self) = @_; |
240 | my ($self) = @_; |
203 | |
241 | |
204 | refresh; |
242 | # refresh; |
205 | } |
243 | } |
206 | |
244 | |
207 | sub conn::face_find { |
245 | sub conn::face_find { |
208 | my ($self, $face) = @_; |
246 | my ($self, $face) = @_; |
209 | |
247 | |
… | |
… | |
318 | |
356 | |
319 | ############################################################################# |
357 | ############################################################################# |
320 | |
358 | |
321 | SDL::Init SDL_INIT_EVERYTHING; |
359 | SDL::Init SDL_INIT_EVERYTHING; |
322 | |
360 | |
|
|
361 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
|
|
362 | |
323 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
363 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
324 | |
364 | |
325 | $mapwidget->activate; |
365 | $TOPLEVEL->add ($mapwidget); |
326 | $mapwidget->focus_in; |
366 | $mapwidget->focus_in; |
327 | |
367 | |
328 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
368 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
329 | |
369 | |
330 | $CFG ||= { |
370 | $CFG ||= { |
… | |
… | |
333 | fullscreen => 0, |
373 | fullscreen => 0, |
334 | host => "crossfire.schmorp.de", |
374 | host => "crossfire.schmorp.de", |
335 | port => 13327, |
375 | port => 13327, |
336 | }; |
376 | }; |
337 | |
377 | |
|
|
378 | Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf"; |
|
|
379 | |
338 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
380 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
339 | |
381 | |
340 | run_config_dialog |
382 | run_config_dialog |
341 | login => sub { start_game }, |
383 | login => sub { start_game }, |
342 | logout => sub { stop_game }; |
384 | logout => sub { stop_game }; |