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.14 by root, Fri Apr 7 21:07:29 2006 UTC vs.
Revision 1.15 by elmex, Fri Apr 7 23:05:21 2006 UTC

57 57
58sub button_up { 58sub button_up {
59 my ($widget, $sdlev) = @_; 59 my ($widget, $sdlev) = @_;
60} 60}
61 61
62sub w { $_[0]->{w} }
63sub h { $_[0]->{h} }
62sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 64sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} }
63sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 65sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} }
64sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } 66sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} }
65 67
66sub draw { 68sub draw {
78 80
79sub bbox { 81sub bbox {
80 my ($widget) = @_; 82 my ($widget) = @_;
81} 83}
82 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
83package Crossfire::Client::Widget::Label; 247package Crossfire::Client::Widget::Label;
84 248
85our @ISA = Crossfire::Client::Widget::; 249our @ISA = Crossfire::Client::Widget::;
86 250
87use SDL::OpenGL; 251use SDL::OpenGL;
88 252
89sub new { 253sub new {
90 my ($class, $x, $y, $z, $ttf, $text) = @_; 254 my ($class, $x, $y, $z, $ttf, $text) = @_;
91 255
92 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);
93 257
94 $self->{texture} = new_from_ttf Crossfire::Client::Texture $ttf, $text; 258 $self->set_text ($text);
95 259
96 $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}
97} 271}
98 272
99sub size_request { 273sub size_request {
100 my ($self) = @_; 274 my ($self) = @_;
101 275

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines