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.97 by root, Fri Apr 14 02:03:11 2006 UTC vs.
Revision 1.102 by elmex, Fri Apr 14 12:17:06 2006 UTC

116} 116}
117 117
118sub _size_allocate { 118sub _size_allocate {
119 my ($self, $x, $y, $w, $h) = @_; 119 my ($self, $x, $y, $w, $h) = @_;
120 120
121 $self->{x} = int $x; 121 $self->{x} = $x;
122 $self->{y} = int $y; 122 $self->{y} = $y;
123 123
124 return unless $self->{w} != $w || $self->{h} != $h; 124 return unless $self->{w} != $w || $self->{h} != $h;
125 125
126 $self->{w} = int $w; 126 $self->{w} = $w;
127 $self->{h} = int $h; 127 $self->{h} = $h;
128 128
129 1 129 1
130} 130}
131 131
132sub size_allocate { 132sub size_allocate {
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::;
1222 1255
1223package CFClient::UI::CheckBox; 1256package CFClient::UI::CheckBox;
1224 1257
1225our @ISA = CFClient::UI::DrawBG::; 1258our @ISA = CFClient::UI::DrawBG::;
1226 1259
1260my @tex =
1261 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1262 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1263
1227use SDL; 1264use SDL;
1228use SDL::OpenGL; 1265use SDL::OpenGL;
1229 1266
1230sub new { 1267sub new {
1231 my $class = shift; 1268 my $class = shift;
1268 $self->SUPER::_draw; 1305 $self->SUPER::_draw;
1269 1306
1270 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; 1307 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0;
1271 1308
1272 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1309 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1273 1310
1274 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1311 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1275 1312
1276 glBegin GL_LINE_LOOP; 1313 glEnable GL_BLEND;
1277 glVertex 0 , 0; 1314 glEnable GL_TEXTURE_2D;
1278 glVertex 0 , $s; 1315 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1279 glVertex $s, $s;
1280 glVertex $s, 0;
1281 glEnd;
1282 1316
1283 if ($self->{state}) { 1317 my $tex = $self->{state} ? $tex[1] : $tex[0];
1284 glBegin GL_LINES; 1318
1285 glVertex 0 , 0; 1319 $tex->draw_quad (0, 0, $s, $s);
1286 glVertex $s, $s; 1320
1287 glVertex $s, 0; 1321 glDisable GL_TEXTURE_2D;
1288 glVertex 0 , $s; 1322 glDisable GL_BLEND;
1289 glEnd;
1290 }
1291} 1323}
1292 1324
1293############################################################################# 1325#############################################################################
1294 1326
1295package CFClient::UI::Slider; 1327package CFClient::UI::Slider;
1297use strict; 1329use strict;
1298 1330
1299use SDL::OpenGL; 1331use SDL::OpenGL;
1300 1332
1301our @ISA = CFClient::UI::DrawBG::; 1333our @ISA = CFClient::UI::DrawBG::;
1334
1335my @tex =
1336 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1337 qw(s1_slider.png s1_slider_bg.png);
1302 1338
1303sub new { 1339sub new {
1304 my $class = shift; 1340 my $class = shift;
1305 1341
1306 # range [value, low, high, page] 1342 # range [value, low, high, page]
1375 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1411 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1376 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1412 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1377 1413
1378 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1414 my ($value, $lo, $hi, $page) = @{$self->{range}};
1379 1415
1416 # the inner_* stuff is for generating a padding for the slider handle,
1417 # so that the handle doesn't leave the texture. This calculation isn't 100%
1418 # correct propably, but it does the job for now
1419 my $inner_pad = 5; # 5% of width for slider bg texture border
1420 my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels
1421 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1422
1380 $page = int $page * $w / ($hi - $lo); 1423 $page = int $page * $inner_w / ($hi - $lo);
1381 $value = int +($value - $lo) * $w / ($hi - $lo); 1424 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1382 1425
1383 $w -= $page; 1426 $w -= $page;
1384 $page &= ~1; 1427 $page &= ~1;
1385 glTranslate $page * 0.5, 0, 0; 1428 glTranslate $page * 0.5, 0, 0;
1386 $page ||= 2; 1429 $page ||= 2;
1387 1430
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; 1431 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
1396 my $knob_b = $value + $page * 0.5; 1432 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
1397 1433
1398 glBegin GL_QUADS; 1434 glEnable GL_BLEND;
1399 glColor @$fg; 1435 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1400 glVertex $knob_a, 0; 1436 glEnable GL_TEXTURE_2D;
1401 glVertex $knob_a, $h; 1437 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1402 glVertex $knob_b, $h;
1403 glVertex $knob_b, 0;
1404 1438
1405 if ($knob_a < $knob_b - 2) { 1439 # draw background
1406 glColor @$bg; 1440 $tex[1]->draw_quad (0, 0, $w, $h);
1407 glVertex $knob_a + 1, 1; 1441
1408 glVertex $knob_a + 1, $h - 1; 1442 # draw handle
1409 glVertex $knob_b - 1, $h - 1; 1443 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h);
1410 glVertex $knob_b - 1, 1; 1444
1411 } 1445 glDisable GL_BLEND;
1412 glEnd; 1446 glDisable GL_TEXTURE_2D;
1413} 1447}
1414 1448
1415############################################################################# 1449#############################################################################
1416 1450
1417package CFClient::UI::TextView; 1451package CFClient::UI::TextView;
1617 1651
1618 if ($sym == SDLK_KP5) { 1652 if ($sym == SDLK_KP5) {
1619 $::CONN->user_send ("command stay fire"); 1653 $::CONN->user_send ("command stay fire");
1620 } elsif ($sym == SDLK_a) { 1654 } elsif ($sym == SDLK_a) {
1621 $::CONN->user_send ("command apply"); 1655 $::CONN->user_send ("command apply");
1656 } elsif ($sym == SDLK_QUOTE) {
1657 $self->emit ('activate_console');
1622 } elsif (exists $DIR{$sym}) { 1658 } elsif (exists $DIR{$sym}) {
1623 if ($mod & KMOD_SHIFT) { 1659 if ($mod & KMOD_SHIFT) {
1624 $self->{shft}++; 1660 $self->{shft}++;
1625 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1661 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1626 } elsif ($mod & KMOD_CTRL) { 1662 } elsif ($mod & KMOD_CTRL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines