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.98 by root, Fri Apr 14 02:06:22 2006 UTC vs.
Revision 1.101 by elmex, Fri Apr 14 11:43:51 2006 UTC

639 # TODO: repeat texture not scale 639 # TODO: repeat texture not scale
640 my $rep_x = $cw / $bg->{w}; 640 my $rep_x = $cw / $bg->{w};
641 my $rep_y = $ch / $bg->{h}; 641 my $rep_y = $ch / $bg->{h};
642 642
643 glColor @{ $self->{bg} }; 643 glColor @{ $self->{bg} };
644
645 $bg->{s} = $rep_x;
646 $bg->{t} = $rep_y;
647 $bg->{wrap_mode} = 1;
644 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 648 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch);
645 649
646 glDisable GL_TEXTURE_2D; 650 glDisable GL_TEXTURE_2D;
647 glDisable GL_BLEND; 651 glDisable GL_BLEND;
648 652
1023} 1027}
1024 1028
1025sub _set_text { 1029sub _set_text {
1026 my ($self, $text) = @_; 1030 my ($self, $text) = @_;
1027 1031
1032 my $old_text = $self->{text};
1033
1028 $self->{last_activity} = $::NOW; 1034 $self->{last_activity} = $::NOW;
1029 1035
1030 $self->{text} = $text; 1036 $self->{text} = $text;
1031 $self->{layout}->set_width ($self->{w}); 1037 $self->{layout}->set_width ($self->{w});
1032 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 1038 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height});
1037 1043
1038 $text = substr $text, 0, $self->{cursor}; 1044 $text = substr $text, 0, $self->{cursor};
1039 utf8::encode $text; 1045 utf8::encode $text;
1040 1046
1041 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 1047 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1048
1049 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1050 if $old_text ne $self->{text};
1042} 1051}
1043 1052
1044sub size_request { 1053sub size_request {
1045 my ($self) = @_; 1054 my ($self) = @_;
1046 1055
1085 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1094 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1086 } elsif ($sym == SDLK_HOME) { 1095 } elsif ($sym == SDLK_HOME) {
1087 $self->{cursor} = 0; 1096 $self->{cursor} = 0;
1088 } elsif ($sym == SDLK_END) { 1097 } elsif ($sym == SDLK_END) {
1089 $self->{cursor} = length $text; 1098 $self->{cursor} = length $text;
1099 } elsif ($sym == SDLK_ESCAPE) {
1100 $self->emit ('escape');
1090 } elsif ($uni) { 1101 } elsif ($uni) {
1091 substr $text, $self->{cursor}++, 0, chr $uni; 1102 substr $text, $self->{cursor}++, 0, chr $uni;
1092 } 1103 }
1093 1104
1094 $self->_set_text ($text); 1105 $self->_set_text ($text);
1156 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1167 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h};
1157 glEnd; 1168 glEnd;
1158 } 1169 }
1159} 1170}
1160 1171
1172package CFClient::UI::LineEntry;
1173
1174our @ISA = CFClient::UI::Entry::;
1175
1176use SDL;
1177use SDL::OpenGL;
1178
1179sub key_down {
1180 my ($self, $ev) = @_;
1181
1182 my $sym = $ev->key_sym;
1183
1184 if ($sym == SDLK_RETURN) {
1185 $self->emit (activate => $self->get_text);
1186 $self->update;
1187
1188 } else {
1189 $self->SUPER::key_down ($ev);
1190 }
1191
1192}
1193
1161############################################################################# 1194#############################################################################
1162 1195
1163package CFClient::UI::Button; 1196package CFClient::UI::Button;
1164 1197
1165our @ISA = CFClient::UI::Label::; 1198our @ISA = CFClient::UI::Label::;
1297use strict; 1330use strict;
1298 1331
1299use SDL::OpenGL; 1332use SDL::OpenGL;
1300 1333
1301our @ISA = CFClient::UI::DrawBG::; 1334our @ISA = CFClient::UI::DrawBG::;
1335
1336my @tex =
1337 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1338 qw(s1_slider.png s1_slider_bg.png);
1302 1339
1303sub new { 1340sub new {
1304 my $class = shift; 1341 my $class = shift;
1305 1342
1306 # range [value, low, high, page] 1343 # range [value, low, high, page]
1375 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1412 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1376 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1413 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1377 1414
1378 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1415 my ($value, $lo, $hi, $page) = @{$self->{range}};
1379 1416
1417 # the inner_* stuff is for generating a padding for the slider handle,
1418 # so that the handle doesn't leave the texture. This calculation isn't 100%
1419 # correct propably, but it does the job for now
1420 my $inner_pad = 5; # 5% of width for slider bg texture border
1421 my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels
1422 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1423
1380 $page = int $page * $w / ($hi - $lo); 1424 $page = int $page * $inner_w / ($hi - $lo);
1381 $value = int +($value - $lo) * $w / ($hi - $lo); 1425 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1382 1426
1383 $w -= $page; 1427 $w -= $page;
1384 $page &= ~1; 1428 $page &= ~1;
1385 glTranslate $page * 0.5, 0, 0; 1429 glTranslate $page * 0.5, 0, 0;
1386 $page ||= 2; 1430 $page ||= 2;
1387 1431
1388 glColor @$fg;
1389 glBegin GL_LINES;
1390 glVertex 0, 0; glVertex 0, $h;
1391 glVertex $w - 1, 0; glVertex $w - 1, $h;
1392 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5;
1393 glEnd;
1394
1395 my $knob_a = $value - $page * 0.5; 1432 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
1396 my $knob_b = $value + $page * 0.5; 1433 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
1397 1434
1398 glBegin GL_QUADS; 1435 glEnable GL_BLEND;
1399 glColor @$fg; 1436 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1400 glVertex $knob_a, 0; 1437 glEnable GL_TEXTURE_2D;
1401 glVertex $knob_a, $h; 1438 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1402 glVertex $knob_b, $h;
1403 glVertex $knob_b, 0;
1404 1439
1405 if ($knob_a < $knob_b - 2) { 1440 # draw background
1406 glColor @$bg; 1441 $tex[1]->draw_quad (0, 0, $w, $h);
1407 glVertex $knob_a + 1, 1; 1442
1408 glVertex $knob_a + 1, $h - 1; 1443 # draw handle
1409 glVertex $knob_b - 1, $h - 1; 1444 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h);
1410 glVertex $knob_b - 1, 1; 1445
1411 } 1446 glDisable GL_BLEND;
1412 glEnd; 1447 glDisable GL_TEXTURE_2D;
1413} 1448}
1414 1449
1415############################################################################# 1450#############################################################################
1416 1451
1417package CFClient::UI::TextView; 1452package CFClient::UI::TextView;
1617 1652
1618 if ($sym == SDLK_KP5) { 1653 if ($sym == SDLK_KP5) {
1619 $::CONN->user_send ("command stay fire"); 1654 $::CONN->user_send ("command stay fire");
1620 } elsif ($sym == SDLK_a) { 1655 } elsif ($sym == SDLK_a) {
1621 $::CONN->user_send ("command apply"); 1656 $::CONN->user_send ("command apply");
1657 } elsif ($sym == SDLK_QUOTE) {
1658 $self->emit ('activate_console');
1622 } elsif (exists $DIR{$sym}) { 1659 } elsif (exists $DIR{$sym}) {
1623 if ($mod & KMOD_SHIFT) { 1660 if ($mod & KMOD_SHIFT) {
1624 $self->{shft}++; 1661 $self->{shft}++;
1625 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1662 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1626 } elsif ($mod & KMOD_CTRL) { 1663 } elsif ($mod & KMOD_CTRL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines