… | |
… | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | use Crossfire::Client; |
10 | use Crossfire::Client; |
11 | |
11 | |
12 | our $FOCUS; # the widget with current focus |
|
|
13 | |
|
|
14 | # class methods for events |
12 | # class methods for events |
15 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
13 | sub feed_sdl_key_down_event { $::FOCUS->key_down ($_[0]) if $::FOCUS } |
16 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
14 | sub feed_sdl_key_up_event { $::FOCUS->key_up ($_[0]) if $::FOCUS } |
17 | sub feed_sdl_button_down_event { } |
15 | sub feed_sdl_button_down_event { } |
18 | sub feed_sdl_button_up_event { } |
16 | sub feed_sdl_button_up_event { } |
19 | |
17 | |
20 | sub new { |
18 | sub new { |
21 | my $class = shift; |
19 | my $class = shift; |
… | |
… | |
46 | $self->{h} = $h; |
44 | $self->{h} = $h; |
47 | } |
45 | } |
48 | |
46 | |
49 | sub focus_in { |
47 | sub focus_in { |
50 | my ($widget) = @_; |
48 | my ($widget) = @_; |
51 | $FOCUS = $widget; |
49 | $::FOCUS = $widget; |
52 | } |
50 | } |
53 | |
51 | |
54 | sub focus_out { |
52 | sub focus_out { |
55 | my ($widget) = @_; |
53 | my ($widget) = @_; |
56 | } |
54 | } |
… | |
… | |
81 | my ($self) = @_; |
79 | my ($self) = @_; |
82 | |
80 | |
83 | glPushMatrix; |
81 | glPushMatrix; |
84 | glTranslate $self->{x}, $self->{y}, 0; |
82 | glTranslate $self->{x}, $self->{y}, 0; |
85 | $self->_draw; |
83 | $self->_draw; |
|
|
84 | if ($self == $::HOVER) { |
|
|
85 | glColor 1, 1, 1, 0.4; |
|
|
86 | glEnable GL_BLEND; |
|
|
87 | glBegin GL_QUADS; |
|
|
88 | glVertex 0, 0; |
|
|
89 | glVertex $self->{w} - 1, 0; |
|
|
90 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
91 | glVertex 0, $self->{h} - 1; |
|
|
92 | glEnd; |
|
|
93 | glDisable GL_BLEND; |
|
|
94 | } |
86 | glPopMatrix; |
95 | glPopMatrix; |
87 | } |
96 | } |
88 | |
97 | |
89 | sub _draw { |
98 | sub _draw { |
90 | my ($self) = @_; |
99 | my ($self) = @_; |
… | |
… | |
177 | } |
186 | } |
178 | |
187 | |
179 | sub find_widget { |
188 | sub find_widget { |
180 | my ($self, $x, $y) = @_; |
189 | my ($self, $x, $y) = @_; |
181 | |
190 | |
|
|
191 | $x -= $self->{x}; |
|
|
192 | $y -= $self->{y}; |
|
|
193 | |
182 | my $res; |
194 | my $res; |
183 | |
195 | |
184 | for (@{ $self->{children} }) { |
196 | for (reverse @{ $self->{children} }) { |
185 | $res = $_->find_widget ($x, $y) |
197 | $res = $_->find_widget ($x, $y) |
186 | and return $res; |
198 | and return $res; |
187 | } |
199 | } |
188 | |
200 | |
189 | () |
201 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
190 | } |
202 | } |
191 | |
203 | |
192 | sub _draw { |
204 | sub _draw { |
193 | my ($self) = @_; |
205 | my ($self) = @_; |
194 | |
206 | |