ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.13 by elmex, Fri Apr 7 20:57:29 2006 UTC vs.
Revision 1.15 by elmex, Fri Apr 7 23:05:21 2006 UTC

28 sort { $a->{z} <=> $b->{z} } 28 sort { $a->{z} <=> $b->{z} }
29 grep { $_ != $_[0] } 29 grep { $_ != $_[0] }
30 @ACTIVE_WIDGETS; 30 @ACTIVE_WIDGETS;
31} 31}
32 32
33sub size_request {
34 die "size_request is abtract";
35}
36
33sub focus_in { 37sub focus_in {
34 my ($widget) = @_; 38 my ($widget) = @_;
35 $FOCUS = $widget; 39 $FOCUS = $widget;
36} 40}
37 41
53 57
54sub button_up { 58sub button_up {
55 my ($widget, $sdlev) = @_; 59 my ($widget, $sdlev) = @_;
56} 60}
57 61
62sub w { $_[0]->{w} }
63sub h { $_[0]->{h} }
58sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 64sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
59sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 65sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
60sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } 66sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} }
61 67
62sub draw { 68sub draw {
74 80
75sub bbox { 81sub bbox {
76 my ($widget) = @_; 82 my ($widget) = @_;
77} 83}
78 84
85package Crossfire::Client::Widget::Container;
86
87our @ISA = Crossfire::Client::Widget::;
88
89use SDL::OpenGL;
90
91sub add { $_[0]->{child} = $_[1] }
92sub get { $_[0]->{child} }
93
94sub size_request { $_[0]->{child}->size_request if $_[0]->{child} }
95
96sub _draw { die "Containers can't be drawn!" }
97
98package Crossfire::Client::Widget::Frame;
99
100our @ISA = Crossfire::Client::Widget::Container::;
101
102use SDL::OpenGL;
103
104sub size_request {
105 my ($self) = @_;
106 my $chld = $self->get
107 or return (0, 0);
108 map { $_ + 4 } $chld->size_request;
109}
110
111sub _draw {
112 my ($self) = @_;
113
114 my $chld = $self->get;
115
116 my ($w, $h) = $chld->size_request;
117
118 glColor 1, 0, 0;
119 glBegin GL_QUADS;
120 glTexCoord 0, 0; glVertex 0 , 0;
121 glTexCoord 0, 1; glVertex 0 , $h + 4;
122 glTexCoord 1, 1; glVertex $w + 4 , $h + 4;
123 glTexCoord 1, 0; glVertex $w + 4 , 0;
124 glEnd;
125
126 glPushMatrix;
127 glTranslate (2, 2, 0);
128 $chld->_draw;
129 glPopMatrix;
130}
131
132package Crossfire::Client::Widget::Table;
133
134our @ISA = Crossfire::Client::Widget::Container::;
135
136use SDL::OpenGL;
137
138sub add {
139 my ($self, $x, $y, $chld) = @_;
140 $self->{childs}[$y][$x] = $chld;
141}
142
143sub max_row_height {
144 my ($self, $row) = @_;
145
146 my $hs = 0;
147 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) {
148 my $c = $self->{childs}->[$row]->[$xi];
149 my ($w, $h) = $c->size_request if $c;
150 if ($hs < $h) { $hs = $h }
151 }
152 return $hs;
153}
154
155sub max_col_width {
156 my ($self, $col) = @_;
157
158 my $ws = 0;
159 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) {
160 my $c = ($self->{childs}->[$yi] || [])->[$col];
161 my ($w, $h) = $c->size_request if $c;
162 if ($ws < $w) { $ws = $w }
163 }
164 return $ws;
165}
166
167sub size_request {
168 my ($self) = @_;
169
170 my ($hs, $ws) = (0, 0);
171
172 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
173 $hs += $self->max_row_height ($yi);
174 }
175
176 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
177 my $wm = 0;
178 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
179 $wm += $self->max_col_width ($xi)
180 }
181 if ($ws < $wm) { $ws = $wm }
182 }
183
184 return ($ws, $hs);
185}
186
187sub _draw {
188 my ($self) = @_;
189
190 my $y = 0;
191 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) {
192 my $x = 0;
193
194 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) {
195
196 glPushMatrix;
197 glTranslate ($x, $y, 0);
198 my $c = $self->{childs}->[$yi]->[$xi];
199 $c->_draw if $c;
200 glPopMatrix;
201
202 $x += $self->max_col_width ($xi);
203 }
204
205 $y += $self->max_row_height ($yi);
206 }
207}
208
209package Crossfire::Client::Widget::VBox;
210
211our @ISA = Crossfire::Client::Widget::Container::;
212
213use SDL::OpenGL;
214
215sub add {
216 my ($self, $chld) = @_;
217 push @{$self->{childs}}, $chld;
218}
219
220sub size_request {
221 my ($self) = @_;
222
223 my ($hs, $ws) = (0, 0);
224 for (@{$self->{childs} || []}) {
225 my ($w, $h) = $_->size_request;
226 $hs += $h;
227 if ($ws < $w) { $ws = $w }
228 }
229
230 return ($ws, $hs);
231}
232
233sub _draw {
234 my ($self) = @_;
235
236 my ($x, $y);
237 for (@{$self->{childs} || []}) {
238 glPushMatrix;
239 glTranslate (0, $y, 0);
240 $_->_draw;
241 glPopMatrix;
242 my ($w, $h) = $_->size_request;
243 $y += $h;
244 }
245}
246
79package Crossfire::Client::Widget::Label; 247package Crossfire::Client::Widget::Label;
80 248
81our @ISA = Crossfire::Client::Widget::; 249our @ISA = Crossfire::Client::Widget::;
82 250
83use SDL::OpenGL; 251use SDL::OpenGL;
84 252
85sub new { 253sub new {
86 my ($class, $x, $y, $z, $ttf, $text) = @_; 254 my ($class, $x, $y, $z, $ttf, $text) = @_;
87 255
88 my $self = $class->SUPER::new (x => $x, y => $y, z => $z); 256 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, ttf => $ttf);
89 257
90 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; 258 $self->set_text ($text);
91 259
92 $self 260 $self
261}
262
263sub set_text {
264 my ($self, $text) = @_;
265 $self->{texture} = new_from_ttf Crossfire::Client::Texture $self->{ttf}, $self->{text} = $text;
266}
267
268sub get_text {
269 my ($self, $text) = @_;
270 $self->{text}
271}
272
273sub size_request {
274 my ($self) = @_;
275
276 (
277 $self->{texture}{width},
278 $self->{texture}{height},
279 )
93} 280}
94 281
95sub _draw { 282sub _draw {
96 my ($self) = @_; 283 my ($self) = @_;
97 284

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines