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 |
|
|
glTranslate ($self->{x} || 0, $self->{y} || 0, 0); |
63 |
|
|
$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 |
|
|
use SDL::OpenGL; |
78 |
|
|
|
79 |
|
|
sub new { |
80 |
|
|
my ($class, $ttf, $text) = @_; |
81 |
|
|
|
82 |
|
|
my $self = $class->SUPER::new; |
83 |
|
|
|
84 |
|
|
$self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; |
85 |
|
|
|
86 |
|
|
$self |
87 |
|
|
} |
88 |
|
|
|
89 |
elmex |
1.11 |
sub _draw { |
90 |
root |
1.10 |
my ($self) = @_; |
91 |
|
|
|
92 |
|
|
my $tex = $self->{texture}; |
93 |
|
|
|
94 |
|
|
glEnable GL_TEXTURE_2D; |
95 |
|
|
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
96 |
|
|
|
97 |
|
|
glBegin GL_QUADS; |
98 |
|
|
glTexCoord 0, 0; glVertex 0 , 0; |
99 |
|
|
glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
100 |
|
|
glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
101 |
|
|
glTexCoord 1, 0; glVertex $tex->{width}, 0; |
102 |
|
|
glEnd; |
103 |
|
|
|
104 |
|
|
glDisable GL_TEXTURE_2D; |
105 |
|
|
} |
106 |
|
|
|
107 |
elmex |
1.9 |
package Crossfire::Client::Widget::TextView; |
108 |
root |
1.4 |
|
109 |
elmex |
1.3 |
use strict; |
110 |
root |
1.10 |
|
111 |
elmex |
1.9 |
our @ISA = qw/Crossfire::Client::Widget/; |
112 |
elmex |
1.3 |
|
113 |
|
|
use SDL::OpenGL; |
114 |
|
|
use SDL::OpenGL::Constants; |
115 |
|
|
|
116 |
|
|
sub add_line { |
117 |
|
|
my ($self, $line) = @_; |
118 |
|
|
push @{$self->{lines}}, $line; |
119 |
|
|
} |
120 |
|
|
|
121 |
elmex |
1.11 |
sub _draw { |
122 |
elmex |
1.3 |
my ($self) = @_; |
123 |
|
|
|
124 |
|
|
} |
125 |
|
|
|
126 |
elmex |
1.9 |
package Crossfire::Client::Widget::MapWidget; |
127 |
root |
1.4 |
|
128 |
elmex |
1.2 |
use strict; |
129 |
elmex |
1.7 |
|
130 |
elmex |
1.9 |
our @ISA = qw/Crossfire::Client::Widget/; |
131 |
elmex |
1.2 |
|
132 |
|
|
use SDL::OpenGL; |
133 |
|
|
use SDL::OpenGL::Constants; |
134 |
|
|
|
135 |
|
|
sub key_down { |
136 |
|
|
print "MAPKEYDOWN\n"; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
sub key_up { |
140 |
|
|
} |
141 |
|
|
|
142 |
elmex |
1.11 |
sub _draw { |
143 |
elmex |
1.2 |
glEnable GL_TEXTURE_2D; |
144 |
|
|
glEnable GL_BLEND; |
145 |
|
|
|
146 |
|
|
my $map = $::CONN->{map}; |
147 |
|
|
|
148 |
|
|
for my $x (0 .. $::CONN->{mapw} - 1) { |
149 |
|
|
for my $y (0 .. $::CONN->{maph} - 1) { |
150 |
|
|
|
151 |
|
|
my $cell = $map->[$x][$y] |
152 |
|
|
or next; |
153 |
|
|
|
154 |
|
|
my $darkness = $cell->[3] * (1 / 255); |
155 |
|
|
glColor $darkness, $darkness, $darkness; |
156 |
|
|
|
157 |
|
|
for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
158 |
root |
1.4 |
my $tex = $::CONN->{face}[$num]{texture} || next; |
159 |
elmex |
1.2 |
|
160 |
root |
1.4 |
glBindTexture GL_TEXTURE_2D, $tex->{name}; |
161 |
elmex |
1.2 |
|
162 |
|
|
glBegin GL_QUADS; |
163 |
root |
1.10 |
glTexCoord 0, 0; glVertex $x * 32 , $y * 32; |
164 |
|
|
glTexCoord 0, 1; glVertex $x * 32 , $y * 32 + 32; |
165 |
|
|
glTexCoord 1, 1; glVertex $x * 32 + 32, $y * 32 + 32; |
166 |
|
|
glTexCoord 1, 0; glVertex $x * 32 + 32, $y * 32; |
167 |
elmex |
1.2 |
glEnd; |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
glDisable GL_TEXTURE_2D; |
173 |
|
|
glDisable GL_BLEND; |
174 |
|
|
} |
175 |
|
|
|
176 |
elmex |
1.1 |
1; |
177 |
root |
1.5 |
|