… | |
… | |
44 | our $ALT_ENTER_MESSAGE; |
44 | our $ALT_ENTER_MESSAGE; |
45 | |
45 | |
46 | our $TOPLEVEL; |
46 | our $TOPLEVEL; |
47 | |
47 | |
48 | our $tw; # Test widget #d# |
48 | our $tw; # Test widget #d# |
|
|
49 | |
|
|
50 | my $last_refresh; |
49 | |
51 | |
50 | sub init_screen { |
52 | sub init_screen { |
51 | $SDL_APP = new SDL::App |
53 | $SDL_APP = new SDL::App |
52 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
54 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
53 | -title => "Crossfire+ Client", |
55 | -title => "Crossfire+ Client", |
… | |
… | |
59 | -blue_size => 8, |
61 | -blue_size => 8, |
60 | -double_buffer => 1, |
62 | -double_buffer => 1, |
61 | -fullscreen => $FULLSCREEN, |
63 | -fullscreen => $FULLSCREEN, |
62 | -resizeable => 0; |
64 | -resizeable => 0; |
63 | |
65 | |
|
|
66 | $last_refresh = SDL::GetTicks; |
|
|
67 | |
64 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
68 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
65 | |
69 | |
66 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
70 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
67 | or warn "WARNING: non-power-of-two opengl extension required"; |
71 | or warn "WARNING: non-power-of-two opengl extension required"; |
68 | |
72 | |
… | |
… | |
74 | $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]); |
75 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
79 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
76 | |
80 | |
77 | # Test code #d# |
81 | # Test code #d# |
78 | unless ($tw) { # haha... |
82 | unless ($tw) { # haha... |
|
|
83 | $tw = new Crossfire::Client::Widget::Animator; |
79 | $tw = new Crossfire::Client::Widget::FancyFrame; |
84 | $tw->add (my $f = new Crossfire::Client::Widget::FancyFrame); |
80 | $tw->add ( |
85 | $f->add ( |
81 | my $te = new Crossfire::Client::Widget::Label |
86 | my $te = new Crossfire::Client::Widget::Label |
82 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!" |
87 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!" |
83 | ); |
88 | ); |
84 | |
89 | |
85 | $tw->move ($WIDTH - 200, 0); |
90 | $tw->move ($WIDTH - 200, 0); |
|
|
91 | $tw->moveto (0, 0); |
86 | $TOPLEVEL->add ($tw); |
92 | $TOPLEVEL->add ($tw); |
87 | } |
93 | } |
88 | |
94 | |
89 | glClearColor 0, 0, 0, 0; |
95 | glClearColor 0, 0, 0, 0; |
90 | |
96 | |
… | |
… | |
117 | user => $CFG->{user}, |
123 | user => $CFG->{user}, |
118 | pass => $CFG->{password}, |
124 | pass => $CFG->{password}, |
119 | mapw => 50, |
125 | mapw => 50, |
120 | maph => 37, |
126 | maph => 37, |
121 | ; |
127 | ; |
|
|
128 | |
|
|
129 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
122 | } |
130 | } |
123 | |
131 | |
124 | sub stop_game { |
132 | sub stop_game { |
125 | remove Glib::Source $SDL_TIMER; |
133 | remove Glib::Source $SDL_TIMER; |
126 | |
134 | |
… | |
… | |
132 | sub force_refresh { |
140 | sub force_refresh { |
133 | glViewport 0, 0, $WIDTH, $HEIGHT; |
141 | glViewport 0, 0, $WIDTH, $HEIGHT; |
134 | |
142 | |
135 | glMatrixMode GL_PROJECTION; |
143 | glMatrixMode GL_PROJECTION; |
136 | glLoadIdentity; |
144 | glLoadIdentity; |
137 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
145 | glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; |
138 | glMatrixMode GL_MODELVIEW; |
146 | glMatrixMode GL_MODELVIEW; |
139 | |
147 | |
140 | glClear GL_COLOR_BUFFER_BIT; |
148 | glClear GL_COLOR_BUFFER_BIT; |
141 | |
149 | |
142 | $TOPLEVEL->draw; |
150 | $TOPLEVEL->draw; |
143 | |
151 | |
144 | SDL::GLSwapBuffers; |
152 | SDL::GLSwapBuffers; |
145 | } |
153 | } |
|
|
154 | |
|
|
155 | my %ANIMATE; |
146 | |
156 | |
147 | my $refresh_handler; |
157 | my $refresh_handler; |
148 | |
158 | |
149 | sub refresh { |
159 | sub refresh { |
150 | $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 | |
151 | force_refresh; |
165 | force_refresh; |
|
|
166 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
167 | |
|
|
168 | if (%ANIMATE) { |
|
|
169 | 1 |
|
|
170 | } else { |
152 | undef $refresh_handler; |
171 | undef $refresh_handler; |
|
|
172 | 0 |
153 | 0 |
173 | } |
154 | }; |
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}; |
155 | } |
188 | } |
156 | |
189 | |
157 | %SDL_CB = ( |
190 | %SDL_CB = ( |
158 | SDL_QUIT() => sub { |
191 | SDL_QUIT() => sub { |
159 | main_quit Gtk2; |
192 | main_quit Gtk2; |
… | |
… | |
198 | } |
231 | } |
199 | |
232 | |
200 | sub conn::map_scroll { |
233 | sub conn::map_scroll { |
201 | my ($self, $dx, $dy) = @_; |
234 | my ($self, $dx, $dy) = @_; |
202 | |
235 | |
203 | refresh; |
236 | # refresh; |
204 | } |
237 | } |
205 | |
238 | |
206 | sub conn::map_clear { |
239 | sub conn::map_clear { |
207 | my ($self) = @_; |
240 | my ($self) = @_; |
208 | |
241 | |
209 | refresh; |
242 | # refresh; |
210 | } |
243 | } |
211 | |
244 | |
212 | sub conn::face_find { |
245 | sub conn::face_find { |
213 | my ($self, $face) = @_; |
246 | my ($self, $face) = @_; |
214 | |
247 | |