1 |
elmex |
1.6 |
package Crossfire::Client::Widget; |
2 |
root |
1.8 |
|
3 |
elmex |
1.1 |
use strict; |
4 |
elmex |
1.11 |
use SDL::OpenGL; |
5 |
|
|
use SDL::OpenGL::Constants; |
6 |
elmex |
1.1 |
|
7 |
|
|
our $FOCUS; # the widget with current focus |
8 |
elmex |
1.2 |
our %ACTIVE_WIDGETS; |
9 |
elmex |
1.1 |
|
10 |
|
|
# class methods for events |
11 |
|
|
sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
12 |
|
|
sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
13 |
|
|
sub feed_sdl_button_down_event { $FOCUS->button_down ($_[0]) if $FOCUS } |
14 |
|
|
sub feed_sdl_button_up_event { $FOCUS->button_up ($_[0]) if $FOCUS } |
15 |
|
|
|
16 |
|
|
sub new { |
17 |
|
|
my $class = shift; |
18 |
root |
1.10 |
|
19 |
|
|
bless { @_ }, $class |
20 |
elmex |
1.1 |
} |
21 |
|
|
|
22 |
elmex |
1.2 |
sub activate { |
23 |
|
|
$ACTIVE_WIDGETS{$_[0]} = $_[0]; |
24 |
|
|
} |
25 |
root |
1.4 |
|
26 |
elmex |
1.2 |
sub deactivate { |
27 |
|
|
delete $ACTIVE_WIDGETS{$_[0]}; |
28 |
|
|
} |
29 |
|
|
|
30 |
elmex |
1.1 |
sub focus_in { |
31 |
|
|
my ($widget) = @_; |
32 |
|
|
$FOCUS = $widget; |
33 |
|
|
} |
34 |
root |
1.4 |
|
35 |
elmex |
1.1 |
sub focus_out { |
36 |
|
|
my ($widget) = @_; |
37 |
|
|
} |
38 |
root |
1.4 |
|
39 |
elmex |
1.1 |
sub key_down { |
40 |
|
|
my ($widget, $sdlev) = @_; |
41 |
|
|
} |
42 |
root |
1.4 |
|
43 |
elmex |
1.1 |
sub key_up { |
44 |
|
|
my ($widget, $sdlev) = @_; |
45 |
|
|
} |
46 |
root |
1.4 |
|
47 |
elmex |
1.1 |
sub button_down { |
48 |
|
|
my ($widget, $sdlev) = @_; |
49 |
|
|
} |
50 |
root |
1.4 |
|
51 |
elmex |
1.1 |
sub button_up { |
52 |
|
|
my ($widget, $sdlev) = @_; |
53 |
|
|
} |
54 |
root |
1.4 |
|
55 |
elmex |
1.11 |
sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } |
56 |
|
|
sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } |
57 |
|
|
|
58 |
elmex |
1.1 |
sub draw { |
59 |
elmex |
1.11 |
my ($self) = @_; |
60 |
|
|
|
61 |
|
|
glPushMatrix; |
62 |
root |
1.12 |
glTranslate $self->{x}, $self->{y}, 0; |
63 |
elmex |
1.11 |
$self->_draw; |
64 |
|
|
glPopMatrix; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
sub _draw { |
68 |
elmex |
1.1 |
my ($widget) = @_; |
69 |
|
|
} |
70 |
root |
1.4 |
|
71 |
elmex |
1.1 |
sub bbox { |
72 |
|
|
my ($widget) = @_; |
73 |
|
|
} |
74 |
elmex |
1.2 |
|
75 |
root |
1.10 |
package Crossfire::Client::Widget::Label; |
76 |
|
|
|
77 |
root |
1.12 |
our @ISA = Crossfire::Client::Widget::; |
78 |
|
|
|
79 |
root |
1.10 |
use SDL::OpenGL; |
80 |
|
|
|
81 |
|
|
sub new { |
82 |
root |
1.12 |
my ($class, $x, $y, $z, $ttf, $text) = @_; |
83 |
root |
1.10 |
|
84 |
root |
1.12 |
my $self = $class->SUPER::new (x => $x, y => $y, z => $z); |
85 |
root |
1.10 |
|
86 |
|
|
$self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; |
87 |
|
|
|
88 |
|
|
$self |
89 |
|
|
} |
90 |
|
|
|
91 |
elmex |
1.11 |
sub _draw { |
92 |
root |
1.10 |
my ($self) = @_; |
93 |
|
|
|
94 |
|
|
my $tex = $self->{texture}; |
95 |
|
|
|
96 |
root |
1.12 |
$self->{x}--; |
97 |
|
|
|
98 |
|
|
glEnable GL_BLEND; |
99 |
root |
1.10 |
glEnable GL_TEXTURE_2D; |
100 |
root |
1.12 |
glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
101 |
root |
1.10 |
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
102 |
|
|
|
103 |
root |
1.12 |
glColor 1, 1, 1; |
104 |
|
|
|
105 |
root |
1.10 |
glBegin GL_QUADS; |
106 |
|
|
glTexCoord 0, 0; glVertex 0 , 0; |
107 |
|
|
glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
108 |
|
|
glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
109 |
|
|
glTexCoord 1, 0; glVertex $tex->{width}, 0; |
110 |
|
|
glEnd; |
111 |
|
|
|
112 |
root |
1.12 |
glDisable GL_BLEND; |
113 |
root |
1.10 |
glDisable GL_TEXTURE_2D; |
114 |
|
|
} |
115 |
|
|
|
116 |
elmex |
1.9 |
package Crossfire::Client::Widget::TextView; |
117 |
root |
1.4 |
|
118 |
elmex |
1.3 |
use strict; |
119 |
root |
1.10 |
|
120 |
elmex |
1.9 |
our @ISA = qw/Crossfire::Client::Widget/; |
121 |
elmex |
1.3 |
|
122 |
|
|
use SDL::OpenGL; |
123 |
|
|
use SDL::OpenGL::Constants; |
124 |
|
|
|
125 |
|
|
sub add_line { |
126 |
|
|
my ($self, $line) = @_; |
127 |
|
|
push @{$self->{lines}}, $line; |
128 |
|
|
} |
129 |
|
|
|
130 |
elmex |
1.11 |
sub _draw { |
131 |
elmex |
1.3 |
my ($self) = @_; |
132 |
|
|
|
133 |
|
|
} |
134 |
|
|
|
135 |
elmex |
1.9 |
package Crossfire::Client::Widget::MapWidget; |
136 |
root |
1.4 |
|
137 |
elmex |
1.2 |
use strict; |
138 |
elmex |
1.7 |
|
139 |
elmex |
1.9 |
our @ISA = qw/Crossfire::Client::Widget/; |
140 |
elmex |
1.2 |
|
141 |
|
|
use SDL::OpenGL; |
142 |
|
|
use SDL::OpenGL::Constants; |
143 |
|
|
|
144 |
|
|
sub key_down { |
145 |
|
|
print "MAPKEYDOWN\n"; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
sub key_up { |
149 |
|
|
} |
150 |
|
|
|
151 |
elmex |
1.11 |
sub _draw { |
152 |
elmex |
1.2 |
glEnable GL_TEXTURE_2D; |
153 |
|
|
glEnable GL_BLEND; |
154 |
root |
1.12 |
glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
155 |
elmex |
1.2 |
|
156 |
|
|
my $map = $::CONN->{map}; |
157 |
|
|
|
158 |
|
|
for my $x (0 .. $::CONN->{mapw} - 1) { |
159 |
|
|
for my $y (0 .. $::CONN->{maph} - 1) { |
160 |
|
|
|
161 |
|
|
my $cell = $map->[$x][$y] |
162 |
|
|
or next; |
163 |
|
|
|
164 |
|
|
my $darkness = $cell->[3] * (1 / 255); |
165 |
|
|
glColor $darkness, $darkness, $darkness; |
166 |
|
|
|
167 |
|
|
for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
168 |
root |
1.4 |
my $tex = $::CONN->{face}[$num]{texture} || next; |
169 |
elmex |
1.2 |
|
170 |
root |
1.4 |
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
171 |
elmex |
1.2 |
|
172 |
|
|
glBegin GL_QUADS; |
173 |
root |
1.10 |
glTexCoord 0, 0; glVertex $x * 32 , $y * 32; |
174 |
|
|
glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; |
175 |
|
|
glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; |
176 |
|
|
glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; |
177 |
elmex |
1.2 |
glEnd; |
178 |
|
|
} |
179 |
|
|
} |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
glDisable GL_TEXTURE_2D; |
183 |
|
|
glDisable GL_BLEND; |
184 |
|
|
} |
185 |
|
|
|
186 |
elmex |
1.1 |
1; |
187 |
root |
1.5 |
|