1 |
elmex |
1.6 |
package Crossfire::Client::Widget; |
2 |
elmex |
1.1 |
use strict; |
3 |
|
|
|
4 |
|
|
our $FOCUS; # the widget with current focus |
5 |
elmex |
1.2 |
our %ACTIVE_WIDGETS; |
6 |
elmex |
1.1 |
|
7 |
|
|
# class methods for events |
8 |
|
|
sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
9 |
|
|
sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
10 |
|
|
sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } |
11 |
|
|
sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } |
12 |
|
|
|
13 |
|
|
sub new { |
14 |
|
|
my $class = shift; |
15 |
|
|
my $self = { @_ }; |
16 |
|
|
bless $self, $class; |
17 |
|
|
return $self; |
18 |
|
|
} |
19 |
|
|
|
20 |
elmex |
1.2 |
sub activate { |
21 |
|
|
$ACTIVE_WIDGETS{$_[0]} = $_[0]; |
22 |
|
|
} |
23 |
root |
1.4 |
|
24 |
elmex |
1.2 |
sub deactivate { |
25 |
|
|
delete $ACTIVE_WIDGETS{$_[0]}; |
26 |
|
|
} |
27 |
|
|
|
28 |
elmex |
1.1 |
sub focus_in { |
29 |
|
|
my ($widget) = @_; |
30 |
|
|
$FOCUS = $widget; |
31 |
|
|
} |
32 |
root |
1.4 |
|
33 |
elmex |
1.1 |
sub focus_out { |
34 |
|
|
my ($widget) = @_; |
35 |
|
|
} |
36 |
root |
1.4 |
|
37 |
elmex |
1.1 |
sub key_down { |
38 |
|
|
my ($widget, $sdlev) = @_; |
39 |
|
|
} |
40 |
root |
1.4 |
|
41 |
elmex |
1.1 |
sub key_up { |
42 |
|
|
my ($widget, $sdlev) = @_; |
43 |
|
|
} |
44 |
root |
1.4 |
|
45 |
elmex |
1.1 |
sub button_down { |
46 |
|
|
my ($widget, $sdlev) = @_; |
47 |
|
|
} |
48 |
root |
1.4 |
|
49 |
elmex |
1.1 |
sub button_up { |
50 |
|
|
my ($widget, $sdlev) = @_; |
51 |
|
|
} |
52 |
root |
1.4 |
|
53 |
elmex |
1.1 |
sub draw { |
54 |
|
|
my ($widget) = @_; |
55 |
|
|
} |
56 |
root |
1.4 |
|
57 |
elmex |
1.1 |
sub bbox { |
58 |
|
|
my ($widget) = @_; |
59 |
|
|
} |
60 |
elmex |
1.2 |
|
61 |
elmex |
1.3 |
package Client::TextView; |
62 |
root |
1.4 |
|
63 |
elmex |
1.3 |
use strict; |
64 |
|
|
our @ISA = qw/Client::Widget/; |
65 |
|
|
|
66 |
|
|
use SDL::OpenGL; |
67 |
|
|
use SDL::OpenGL::Constants; |
68 |
|
|
|
69 |
|
|
sub add_line { |
70 |
|
|
my ($self, $line) = @_; |
71 |
|
|
push @{$self->{lines}}, $line; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
sub draw { |
75 |
|
|
my ($self) = @_; |
76 |
|
|
|
77 |
|
|
} |
78 |
|
|
|
79 |
elmex |
1.2 |
package Client::MapWidget; |
80 |
root |
1.4 |
|
81 |
elmex |
1.2 |
use strict; |
82 |
elmex |
1.7 |
|
83 |
elmex |
1.2 |
our @ISA = qw/Client::Widget/; |
84 |
|
|
|
85 |
|
|
use SDL::OpenGL; |
86 |
|
|
use SDL::OpenGL::Constants; |
87 |
|
|
|
88 |
|
|
sub key_down { |
89 |
|
|
print "MAPKEYDOWN\n"; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
sub key_up { |
93 |
|
|
} |
94 |
|
|
|
95 |
root |
1.5 |
my $x; |
96 |
|
|
|
97 |
elmex |
1.2 |
sub draw { |
98 |
|
|
glEnable GL_TEXTURE_2D; |
99 |
|
|
glEnable GL_BLEND; |
100 |
|
|
|
101 |
root |
1.5 |
glPushMatrix; |
102 |
|
|
|
103 |
elmex |
1.2 |
my $map = $::CONN->{map}; |
104 |
|
|
|
105 |
|
|
for my $x (0 .. $::CONN->{mapw} - 1) { |
106 |
|
|
for my $y (0 .. $::CONN->{maph} - 1) { |
107 |
|
|
|
108 |
|
|
my $cell = $map->[$x][$y] |
109 |
|
|
or next; |
110 |
|
|
|
111 |
|
|
my $darkness = $cell->[3] * (1 / 255); |
112 |
|
|
glColor $darkness, $darkness, $darkness; |
113 |
|
|
|
114 |
|
|
for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
115 |
root |
1.4 |
my $tex = $::CONN->{face}[$num]{texture} || next; |
116 |
elmex |
1.2 |
|
117 |
root |
1.4 |
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
118 |
elmex |
1.2 |
|
119 |
|
|
glBegin GL_QUADS; |
120 |
|
|
glTexCoord 0, 0; glVertex $x, $y; |
121 |
|
|
glTexCoord 0, 1; glVertex $x, $y + 1; |
122 |
|
|
glTexCoord 1, 1; glVertex $x + 1, $y + 1; |
123 |
|
|
glTexCoord 1, 0; glVertex $x + 1, $y; |
124 |
|
|
glEnd; |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
root |
1.5 |
glPopMatrix; |
130 |
|
|
|
131 |
elmex |
1.2 |
glDisable GL_TEXTURE_2D; |
132 |
|
|
glDisable GL_BLEND; |
133 |
|
|
} |
134 |
|
|
|
135 |
elmex |
1.1 |
1; |
136 |
root |
1.5 |
|