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.458 by root, Fri Dec 28 15:05:33 2007 UTC vs.
Revision 1.487 by root, Fri Nov 23 12:14:02 2012 UTC

1package DC::UI; 1package DC::UI;
2 2
3use utf8; 3use common::sense;
4use strict;
5 4
6use List::Util (); 5use List::Util ();
6
7use AnyEvent ();
8use Guard ();
7 9
8use DC; 10use DC;
9use DC::Pod; 11use DC::Pod;
10use DC::Texture; 12use DC::Texture;
11 13
50sub get_layout { 52sub get_layout {
51 my $layout; 53 my $layout;
52 54
53 for (grep { $_->{name} } values %WIDGET) { 55 for (grep { $_->{name} } values %WIDGET) {
54 my $win = $layout->{$_->{name}} = { }; 56 my $win = $layout->{$_->{name}} = { };
55 57
56 $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/; 58 $win->{x} = ($_->{x} + $_->{w} * 0.5) / $::WIDTH if $_->{x} =~ /^[0-9.]+$/;
57 $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/; 59 $win->{y} = ($_->{y} + $_->{h} * 0.5) / $::HEIGHT if $_->{y} =~ /^[0-9.]+$/;
58 $win->{w} = $_->{w} / $::WIDTH if defined $_->{w}; 60 $win->{w} = $_->{w} / $::WIDTH if defined $_->{w};
59 $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h}; 61 $win->{h} = $_->{h} / $::HEIGHT if defined $_->{h};
60 62
69 71
70 $LAYOUT = $layout; 72 $LAYOUT = $layout;
71} 73}
72 74
73# class methods for events 75# class methods for events
74sub feed_sdl_key_down_event { 76sub feed_sdl_key_down_event {
75 $FOCUS->emit (key_down => $_[0]) 77 $FOCUS->emit (key_down => $_[0])
76 if $FOCUS; 78 if $FOCUS;
77} 79}
78 80
79sub feed_sdl_key_up_event { 81sub feed_sdl_key_up_event {
189# call when resolution changes etc. 191# call when resolution changes etc.
190sub rescale_widgets { 192sub rescale_widgets {
191 my ($sx, $sy) = @_; 193 my ($sx, $sy) = @_;
192 194
193 for my $widget (values %WIDGET) { 195 for my $widget (values %WIDGET) {
194 if ($widget->{is_toplevel}) { 196 if ($widget->{is_toplevel} || $widget->{c_rescale}) {
195 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; 197 $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/;
196 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; 198 $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/;
197 199
198 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; 200 $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/;
199 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 201 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
221 223
222############################################################################# 224#############################################################################
223 225
224package DC::UI::Base; 226package DC::UI::Base;
225 227
226use strict; 228use common::sense;
227 229
228use DC::OpenGL; 230use DC::OpenGL;
229 231
230sub new { 232sub new {
231 my $class = shift; 233 my $class = shift;
286sub set_visible { 288sub set_visible {
287 my ($self) = @_; 289 my ($self) = @_;
288 290
289 return if $self->{visible}; 291 return if $self->{visible};
290 292
293 $self->{parent} && $self->{parent}{root}#d#
294 or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1);
295
291 $self->{root} = $self->{parent}{root}; 296 $self->{root} = $self->{parent}{root};
292 $self->{visible} = $self->{parent}{visible} + 1; 297 $self->{visible} = $self->{parent}{visible} + 1;
293 298
294 $self->emit (visibility_change => 1); 299 $self->emit (visibility_change => 1);
295 300
296 $self->realloc if !exists $self->{req_w}; 301 $self->realloc if !exists $self->{req_w};
297 302
298 $_->set_visible for $self->children; 303 $_->set_visible for $self->visible_children;
299} 304}
300 305
301sub set_invisible { 306sub set_invisible {
302 my ($self) = @_; 307 my ($self) = @_;
303 308
358} 363}
359 364
360sub set_size { 365sub set_size {
361 my ($self, $w, $h) = @_; 366 my ($self, $w, $h) = @_;
362 367
363 $self->{force_w} = $w; 368 $self->{force_w} = List::Util::min $w, ($self->{max_w} || $::WIDTH );
364 $self->{force_h} = $h; 369 $self->{force_h} = List::Util::min $h, ($self->{max_h} || $::HEIGHT);
365 370
366 $self->realloc; 371 $self->realloc;
367} 372}
368 373
369# traverse the widget chain up to find the maximum "physical" size constraints 374# traverse the widget chain up to find the maximum "physical" size constraints
370sub get_max_wh { 375sub get_max_wh {
371 my ($self) = @_; 376 my ($self) = @_;
372 377
378 my ($w, $h) = @$self{qw(max_w max_h)};
379
380 if ($w <= 0 || $h <= 0) {
381 my ($mw, $mh) = $self->{parent}
373 return $self->{parent}->get_max_wh 382 ? $self->{parent}->get_max_wh
374 if $self->{parent};
375
376 ($::WIDTH, $::HEIGHT) 383 : ($::WIDTH, $::HEIGHT);
384
385 $w = $mw if $w <= 0;
386 $h = $mh if $h <= 0;
387 }
388
389 ($w, $h)
377} 390}
378 391
379sub size_request { 392sub size_request {
380 require Carp; 393 require Carp;
381 Carp::confess "size_request is abstract"; 394 Carp::confess "size_request is abstract";
519sub connect { 532sub connect {
520 my ($self, $signal, $cb) = @_; 533 my ($self, $signal, $cb) = @_;
521 534
522 push @{ $self->{signal_cb}{$signal} }, $cb; 535 push @{ $self->{signal_cb}{$signal} }, $cb;
523 536
524 defined wantarray and DC::guard { 537 defined wantarray and Guard::guard {
525 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, 538 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
526 @{ $self->{signal_cb}{$signal} }; 539 @{ $self->{signal_cb}{$signal} };
527 } 540 }
528} 541}
529 542
630 643
631package DC::UI::DrawBG; 644package DC::UI::DrawBG;
632 645
633our @ISA = DC::UI::Base::; 646our @ISA = DC::UI::Base::;
634 647
635use strict; 648use common::sense;
649
636use DC::OpenGL; 650use DC::OpenGL;
637 651
638sub new { 652sub new {
639 my $class = shift; 653 my $class = shift;
640 654
643 #active_bg => [1, 1, 1, 0.5], 657 #active_bg => [1, 1, 1, 0.5],
644 @_ 658 @_
645 ) 659 )
646} 660}
647 661
662sub set_bg {
663 my ($self, $bg) = @_;
664
665 $self->{bg} = $bg;
666 $self->update;
667}
668
648sub _draw { 669sub _draw {
649 my ($self) = @_; 670 my ($self) = @_;
650 671
651 my $color = $FOCUS == $self && $self->{active_bg} 672 my $color = $FOCUS == $self
652 ? $self->{active_bg} 673 ? $self->{active_bg} || $self->{bg}
653 : $self->{bg}; 674 : $self->{bg};
654 675
655 if ($color && (@$color < 4 || $color->[3])) { 676 if ($color && (@$color < 4 || $color->[3])) {
656 my ($w, $h) = @$self{qw(w h)}; 677 my ($w, $h) = @$self{qw(w h)};
657 678
1135 1156
1136 $self->grab_focus; 1157 $self->grab_focus;
1137 1158
1138 my $ox = $self->{vp}{view_x}; 1159 my $ox = $self->{vp}{view_x};
1139 my $oy = $self->{vp}{view_y}; 1160 my $oy = $self->{vp}{view_y};
1140 1161
1141 $self->{motion} = sub { 1162 $self->{motion} = sub {
1142 my ($ev, $x, $y) = @_; 1163 my ($ev, $x, $y) = @_;
1143 1164
1144 $ox -= $ev->{xrel}; 1165 $ox -= $ev->{xrel};
1145 $oy -= $ev->{yrel}; 1166 $oy -= $ev->{yrel};
1241 my ($class, %arg) = @_; 1262 my ($class, %arg) = @_;
1242 1263
1243 if ((exists $arg{label}) && !ref $arg{label}) { 1264 if ((exists $arg{label}) && !ref $arg{label}) {
1244 $arg{label} = new DC::UI::Label 1265 $arg{label} = new DC::UI::Label
1245 align => 1, 1266 align => 1,
1246 valign => 0, 1267 valign => 0.5,
1247 text => $arg{label}, 1268 text => $arg{label},
1248 fontsize => ($arg{border} || 0.8) * 0.75; 1269 fontsize => ($arg{border} || 0.8) * 0.75;
1249 } 1270 }
1250 1271
1251 my $self = $class->SUPER::new ( 1272 my $self = $class->SUPER::new (
1252 # label => "", 1273 # label => "",
1253 fg => [0.6, 0.3, 0.1], 1274 fg => undef,
1254 border => 0.8, 1275 border => 0.8,
1255 style => 'single', 1276 style => 'single',
1256 %arg, 1277 %arg,
1257 ); 1278 );
1258 1279
1311 my $border = $self->border; 1332 my $border = $self->border;
1312 my ($w, $h) = ($self->{w}, $self->{h}); 1333 my ($w, $h) = ($self->{w}, $self->{h});
1313 1334
1314 $child->draw; 1335 $child->draw;
1315 1336
1316 glColor @{$self->{fg}}; 1337 glColor @{$self->{fg} || $DC::THEME{fancyframe}};
1317 glBegin GL_LINE_STRIP; 1338 glBegin GL_LINE_STRIP;
1318 glVertex $border * 1.5 , $border * 0.5 + 0.5; 1339 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1319 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; 1340 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1320 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1341 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1321 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; 1342 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1335 1356
1336our @ISA = DC::UI::Bin::; 1357our @ISA = DC::UI::Bin::;
1337 1358
1338use DC::OpenGL; 1359use DC::OpenGL;
1339 1360
1340my $bg = 1361my $bg =
1341 new_from_file DC::Texture DC::find_rcfile "d1_bg.png", 1362 new_from_resource DC::Texture "d1_bg.png",
1342 mipmap => 1, wrap => 1; 1363 mipmap => 1, wrap => 1;
1343 1364
1344my @border = 1365my @border =
1345 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1366 map { new_from_resource DC::Texture $_, mipmap => 1 }
1346 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1367 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1347 1368
1348my @icon = 1369my @icon =
1349 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1370 map { new_from_resource DC::Texture $_, mipmap => 1 }
1350 qw(x1_move.png x1_resize.png); 1371 qw(x1_move.png x1_resize.png);
1351 1372
1352sub new { 1373sub new {
1353 my ($class, %arg) = @_; 1374 my ($class, %arg) = @_;
1354 1375
1355 my $self = $class->SUPER::new ( 1376 my $self = $class->SUPER::new (
1356 bg => [1, 1, 1, 1], 1377 bg => [1, 1, 1, 1],
1357 border_bg => [1, 1, 1, 1], 1378 border_bg => [1, 1, 1, 1],
1358 border => 0.6, 1379 border => 0.8,
1359 can_events => 1, 1380 can_events => 1,
1360 min_w => 64, 1381 min_w => 64,
1361 min_h => 32, 1382 min_h => 32,
1362 %arg, 1383 %arg,
1363 ); 1384 );
1364 1385
1365 $self->{title_widget} = new DC::UI::Label 1386 $self->{title_widget} = new DC::UI::Label
1366 align => 0, 1387 align => 0.5,
1367 valign => 1, 1388 valign => 1,
1368 text => $self->{title}, 1389 text => $self->{title},
1369 fontsize => $self->{border}, 1390 fontsize => $self->{border},
1370 if exists $self->{title}; 1391 if exists $self->{title};
1371 1392
1443 1464
1444sub invoke_delete { 1465sub invoke_delete {
1445 my ($self) = @_; 1466 my ($self) = @_;
1446 1467
1447 $self->hide; 1468 $self->hide;
1448 1469
1449 1 1470 1
1450} 1471}
1451 1472
1452sub invoke_button_down { 1473sub invoke_button_down {
1453 my ($self, $ev, $x, $y) = @_; 1474 my ($self, $ev, $x, $y) = @_;
1454 1475
1455 my ($w, $h) = @$self{qw(w h)}; 1476 my ($w, $h) = @$self{qw(w h)};
1456 my $border = $self->border; 1477 my $border = $self->border;
1457 1478
1458 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); 1479 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w); # left-right
1459 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); 1480 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h); # top-down
1460 1481
1461 if ($lr & $td) { 1482 if ($lr & $td) { # corners
1462 my ($wx, $wy) = ($self->{x}, $self->{y}); 1483 my ($wx, $wy) = ($self->{x}, $self->{y});
1463 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1484 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1464 my ($bw, $bh) = ($self->{w}, $self->{h}); 1485 my ($bw, $bh) = ($self->{w}, $self->{h});
1465 1486
1466 my $mx = $x < $border; 1487 my $mx = $x < $border;
1470 my ($ev, $x, $y) = @_; 1491 my ($ev, $x, $y) = @_;
1471 1492
1472 my $dx = $ev->{x} - $ox; 1493 my $dx = $ev->{x} - $ox;
1473 my $dy = $ev->{y} - $oy; 1494 my $dy = $ev->{y} - $oy;
1474 1495
1496 $self->set_size (
1475 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); 1497 $bw + $dx * ($mx ? -1 : 1),
1476 $self->{force_h} = $bh + $dy * ($my ? -1 : 1); 1498 $bh + $dy * ($my ? -1 : 1),
1499 );
1477 1500
1478 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my); 1501 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1479 $self->realloc; 1502 $self->realloc;
1480 }; 1503 };
1481 1504
1482 } elsif ($lr ^ $td) { 1505 } elsif ($lr ^ $td) { # edges
1483 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1506 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1484 my ($bx, $by) = ($self->{x}, $self->{y}); 1507 my ($bx, $by) = ($self->{x}, $self->{y});
1485 1508
1486 $self->{motion} = sub { 1509 $self->{motion} = sub {
1487 my ($ev, $x, $y) = @_; 1510 my ($ev, $x, $y) = @_;
1532 glEnable GL_TEXTURE_2D; 1555 glEnable GL_TEXTURE_2D;
1533 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1556 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1534 1557
1535 my $border = $self->border; 1558 my $border = $self->border;
1536 1559
1560 if ($border) {
1537 glColor @{ $self->{border_bg} }; 1561 glColor @{ $self->{border_bg} };
1538 $border[0]->draw_quad_alpha ( 0, 0, $w, $border); 1562 $border[0]->draw_quad_alpha ( 0, 0, $w, $border);
1539 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); 1563 $border[1]->draw_quad_alpha ( 0, $border, $border, $ch);
1540 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); 1564 $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
1541 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); 1565 $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border);
1542 1566
1543 # move 1567 # move
1544 my $w2 = ($w - $border) * .5; 1568 my $w2 = ($w - $border) * .5;
1545 my $h2 = ($h - $border) * .5; 1569 my $h2 = ($h - $border) * .5;
1546 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); 1570 $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border);
1547 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); 1571 $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border);
1548 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); 1572 $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border);
1549 1573
1550 # resize 1574 # resize
1551 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); 1575 $icon[1]->draw_quad_alpha ( 0, 0, $border, $border);
1552 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) 1576 $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border)
1553 unless $self->{has_close_button}; 1577 unless $self->{has_close_button};
1554 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); 1578 $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border);
1555 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); 1579 $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border);
1580 }
1556 1581
1557 if (@{$self->{bg}} < 4 || $self->{bg}[3]) { 1582 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
1558 glColor @{ $self->{bg} }; 1583 glColor @{ $self->{bg} };
1559 1584
1560 # TODO: repeat texture not scale 1585 # TODO: repeat texture not scale
1815 if ($req > $space) { 1840 if ($req > $space) {
1816 # ah well, not enough space 1841 # ah well, not enough space
1817 $_ *= $space / $req for @req; 1842 $_ *= $space / $req for @req;
1818 } else { 1843 } else {
1819 my $expand = (List::Util::sum map $_->{expand}, @children) || 1; 1844 my $expand = (List::Util::sum map $_->{expand}, @children) || 1;
1820 1845
1821 $space = ($space - $req) / $expand; # remaining space to give away 1846 $space = ($space - $req) / $expand; # remaining space to give away
1822 1847
1823 $req[$_] += $space * $children[$_]{expand} 1848 $req[$_] += $space * $children[$_]{expand}
1824 for 0 .. $#children; 1849 for 0 .. $#children;
1825 } 1850 }
1889 #max_w => maximum pixel width 1914 #max_w => maximum pixel width
1890 #style => 0, # render flags 1915 #style => 0, # render flags
1891 ellipsise => 3, # end 1916 ellipsise => 3, # end
1892 layout => (new DC::Layout), 1917 layout => (new DC::Layout),
1893 fontsize => 1, 1918 fontsize => 1,
1894 align => -1, 1919 align => 0.5,
1895 valign => -1, 1920 valign => 0.5,
1896 padding_x => 2, 1921 padding_x => 4,
1897 padding_y => 2, 1922 padding_y => 2,
1898 can_events => 0, 1923 can_events => 0,
1899 %arg 1924 %arg
1900 ); 1925 );
1901 1926
1967 1992
1968 $self->{size_req} ||= do { 1993 $self->{size_req} ||= do {
1969 my ($max_w, $max_h) = $self->get_max_wh; 1994 my ($max_w, $max_h) = $self->get_max_wh;
1970 1995
1971 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1996 $self->{layout}->set_font ($self->{font}) if $self->{font};
1972 $self->{layout}->set_width ($self->{max_w} || $max_w || -1); 1997 $self->{layout}->set_width ($max_w);
1973 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1998 $self->{layout}->set_ellipsise ($self->{ellipsise});
1974 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1999 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1975 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2000 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1976 2001
1977 my ($w, $h) = $self->{layout}->size; 2002 my ($w, $h) = $self->{layout}->size;
1978 2003
1979 if (exists $self->{template}) { 2004 if (exists $self->{template}) {
1980 $self->{template}->set_font ($self->{font}) if $self->{font}; 2005 $self->{template}->set_font ($self->{font}) if $self->{font};
1981 $self->{template}->set_width ($self->{max_w} || -1); 2006 $self->{template}->set_width ($max_w);
1982 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 2007 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1983 2008
1984 my ($w2, $h2) = $self->{template}->size; 2009 my ($w2, $h2) = $self->{template}->size;
1985 2010
1986 $w = List::Util::max $w, $w2; 2011 $w = List::Util::max $w, $w2;
2042 2067
2043 [$self->{layout}->size] 2068 [$self->{layout}->size]
2044 }; 2069 };
2045 2070
2046 unless (exists $self->{ox}) { 2071 unless (exists $self->{ox}) {
2047 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 2072 $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2);
2048 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 2073 $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2);
2049 : ($self->{w} - $size->[0]) * 0.5);
2050
2051 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2052 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2053 : ($self->{h} - $size->[1]) * 0.5);
2054 2074
2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2075 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2056 }; 2076 };
2057 2077
2058# unless ($self->{list}) { 2078# unless ($self->{list}) {
2059# $self->{list} = DC::OpenGL::glGenList; 2079# $self->{list} = DC::OpenGL::glGenList;
2060# DC::OpenGL::glNewList $self->{list}; 2080# DC::OpenGL::glNewList $self->{list};
2061# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2081# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2062# DC::OpenGL::glEndList; 2082# DC::OpenGL::glEndList;
2063# } 2083# }
2064# 2084#
2065# DC::OpenGL::glCallList $self->{list}; 2085# DC::OpenGL::glCallList $self->{list};
2066 2086
2067 $self->{layout}->draw; 2087 $self->{layout}->draw;
2068} 2088}
2069 2089
2087 my $class = shift; 2107 my $class = shift;
2088 2108
2089 $class->SUPER::new ( 2109 $class->SUPER::new (
2090 fg => [1, 1, 1], 2110 fg => [1, 1, 1],
2091 bg => [0, 0, 0, 0.2], 2111 bg => [0, 0, 0, 0.2],
2092 outline => [0.6, 0.3, 0.1], 2112 outline => undef,
2093 active_bg => [0, 0, 1, .2], 2113 active_bg => [0, 0, 1, .2],
2094 active_fg => [1, 1, 1], 2114 active_fg => [1, 1, 1],
2095 active_outline => [1, 1, 0], 2115 active_outline => [1, 1, 0],
2096 can_hover => 1, 2116 can_hover => 1,
2097 can_focus => 1, 2117 can_focus => 1,
2118 align => 0,
2098 valign => 0, 2119 valign => 0.5,
2099 can_events => 1, 2120 can_events => 1,
2100 ellipsise => 0, 2121 ellipsise => 0,
2101 padding_x => 4, 2122 padding_x => 4,
2102 padding_y => 2, 2123 padding_y => 2,
2103 #text => ... 2124 #text => ...
2154 2175
2155 my $text = $self->get_text; 2176 my $text = $self->get_text;
2156 2177
2157 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2178 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2158 2179
2159 if ($uni == 8) { 2180 if ($sym == DC::SDLK_BACKSPACE) {
2160 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2181 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2161 } elsif ($uni == 127) { 2182 } elsif ($sym == DC::SDLK_DELETE) {
2162 substr $text, $self->{cursor}, 1, ""; 2183 substr $text, $self->{cursor}, 1, "";
2163 } elsif ($sym == DC::SDLK_LEFT) { 2184 } elsif ($sym == DC::SDLK_LEFT) {
2164 --$self->{cursor} if $self->{cursor}; 2185 --$self->{cursor} if $self->{cursor};
2165 } elsif ($sym == DC::SDLK_RIGHT) { 2186 } elsif ($sym == DC::SDLK_RIGHT) {
2166 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2187 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2217 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text; 2238 utf8::encode $text; $text = substr $text, 0, $idx; utf8::decode $text;
2218 $self->{cursor} = length $text; 2239 $self->{cursor} = length $text;
2219 2240
2220 $self->_set_text ($self->{text}); 2241 $self->_set_text ($self->{text});
2221 $self->update; 2242 $self->update;
2222 2243
2223 1 2244 1
2224} 2245}
2225 2246
2226sub invoke_mouse_motion { 2247sub invoke_mouse_motion {
2227 my ($self, $ev, $x, $y) = @_; 2248 my ($self, $ev, $x, $y) = @_;
2269 glColor @{$self->{active_outline}}; 2290 glColor @{$self->{active_outline}};
2270 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2291 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2271 glLineWidth 1; 2292 glLineWidth 1;
2272 2293
2273 } else { 2294 } else {
2274 glColor @{$self->{outline}}; 2295 glColor @{$self->{outline} || $DC::THEME{entry_outline}};
2275 glBegin GL_LINE_STRIP; 2296 glBegin GL_LINE_STRIP;
2276 glVertex .5, $self->{h} * .5; 2297 glVertex .5, $self->{h} * .5;
2277 glVertex .5, $self->{h} - 2.5; 2298 glVertex .5, $self->{h} - 2.5;
2278 glVertex $self->{w} - .5, $self->{h} - 2.5; 2299 glVertex $self->{w} - .5, $self->{h} - 2.5;
2279 glVertex $self->{w} - .5, $self->{h} * .5; 2300 glVertex $self->{w} - .5, $self->{h} * .5;
2286package DC::UI::Entry; 2307package DC::UI::Entry;
2287 2308
2288our @ISA = DC::UI::EntryBase::; 2309our @ISA = DC::UI::EntryBase::;
2289 2310
2290use DC::OpenGL; 2311use DC::OpenGL;
2312
2313sub new {
2314 my $class = shift;
2315
2316 $class->SUPER::new (
2317 history_pointer => -1,
2318 @_
2319 )
2320}
2321
2291 2322
2292sub invoke_key_down { 2323sub invoke_key_down {
2293 my ($self, $ev) = @_; 2324 my ($self, $ev) = @_;
2294 2325
2295 my $sym = $ev->{sym}; 2326 my $sym = $ev->{sym};
2320 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2351 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2321 2352
2322 if ($self->{history_pointer} >= 0) { 2353 if ($self->{history_pointer} >= 0) {
2323 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2354 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2324 } else { 2355 } else {
2356 if (defined $self->{history_saveback}) {
2325 $self->set_text ($self->{history_saveback}); 2357 $self->set_text ($self->{history_saveback});
2358 $self->{history_saveback} = undef;
2359 }
2326 } 2360 }
2327 2361
2328 } else { 2362 } else {
2329 return $self->SUPER::invoke_key_down ($ev) 2363 return $self->SUPER::invoke_key_down ($ev)
2330 } 2364 }
2388our @ISA = DC::UI::Bin::; 2422our @ISA = DC::UI::Bin::;
2389 2423
2390use DC::OpenGL; 2424use DC::OpenGL;
2391 2425
2392my @tex = 2426my @tex =
2393 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2427 map { new_from_resource DC::Texture $_, mipmap => 1 }
2394 qw(b1_button_inactive.png b1_button_active.png); 2428 qw(b1_button_inactive.png b1_button_active.png);
2395 2429
2396sub new { 2430sub new {
2397 my $class = shift; 2431 my $class = shift;
2398 2432
2399 $class->SUPER::new ( 2433 $class->SUPER::new (
2400 can_hover => 1, 2434 can_hover => 1,
2401 align => 0, 2435 align => 0.5,
2402 valign => 0, 2436 valign => 0.5,
2403 can_events => 1, 2437 can_events => 1,
2404 @_ 2438 @_
2405 ) 2439 )
2406} 2440}
2407 2441
2437our @ISA = DC::UI::Label::; 2471our @ISA = DC::UI::Label::;
2438 2472
2439use DC::OpenGL; 2473use DC::OpenGL;
2440 2474
2441my @tex = 2475my @tex =
2442 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2476 map { new_from_resource DC::Texture $_, mipmap => 1 }
2443 qw(b1_button_inactive.png b1_button_active.png); 2477 qw(b1_button_inactive.png b1_button_active.png);
2444 2478
2445sub new { 2479sub new {
2446 my $class = shift; 2480 my $class = shift;
2447 2481
2449 padding_x => 8, 2483 padding_x => 8,
2450 padding_y => 4, 2484 padding_y => 4,
2451 fg => [1.0, 1.0, 1.0], 2485 fg => [1.0, 1.0, 1.0],
2452 active_fg => [0.8, 0.8, 0.8], 2486 active_fg => [0.8, 0.8, 0.8],
2453 can_hover => 1, 2487 can_hover => 1,
2454 align => 0, 2488 align => 0.5,
2455 valign => 0, 2489 valign => 0.5,
2456 can_events => 1, 2490 can_events => 1,
2457 @_ 2491 @_
2458 ) 2492 )
2459} 2493}
2460 2494
2490package DC::UI::CheckBox; 2524package DC::UI::CheckBox;
2491 2525
2492our @ISA = DC::UI::DrawBG::; 2526our @ISA = DC::UI::DrawBG::;
2493 2527
2494my @tex = 2528my @tex =
2495 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2529 map { new_from_resource DC::Texture $_, mipmap => 1 }
2496 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2530 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2497 2531
2498use DC::OpenGL; 2532use DC::OpenGL;
2499 2533
2500sub new { 2534sub new {
2501 my $class = shift; 2535 my $class = shift;
2502 2536
2503 $class->SUPER::new ( 2537 $class->SUPER::new (
2538 fontsize => 1,
2504 padding_x => 2, 2539 padding_x => 2,
2505 padding_y => 2, 2540 padding_y => 2,
2506 fg => [1, 1, 1], 2541 fg => [1, 1, 1],
2507 active_fg => [1, 1, 0], 2542 active_fg => [1, 1, 0],
2508 bg => [0, 0, 0, 0.2], 2543 bg => [0, 0, 0, 0.2],
2514} 2549}
2515 2550
2516sub size_request { 2551sub size_request {
2517 my ($self) = @_; 2552 my ($self) = @_;
2518 2553
2519 (6) x 2 2554 ($self->{fontsize} * $::FONTSIZE) x 2
2520} 2555}
2521 2556
2522sub toggle { 2557sub toggle {
2523 my ($self) = @_; 2558 my ($self) = @_;
2524 2559
2562 2597
2563############################################################################# 2598#############################################################################
2564 2599
2565package DC::UI::Image; 2600package DC::UI::Image;
2566 2601
2567our @ISA = DC::UI::Base::; 2602our @ISA = DC::UI::DrawBG::;
2568 2603
2569use DC::OpenGL; 2604use DC::OpenGL;
2570 2605
2571our %texture_cache; 2606our %texture_cache;
2572 2607
2581 2616
2582 $self->{path} || $self->{tex} 2617 $self->{path} || $self->{tex}
2583 or Carp::croak "'path' or 'tex' attributes required"; 2618 or Carp::croak "'path' or 'tex' attributes required";
2584 2619
2585 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2620 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2586 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1; 2621 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2587 2622
2588 DC::weaken $texture_cache{$self->{path}}; 2623 DC::weaken $texture_cache{$self->{path}};
2589 2624
2590 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2625 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2591 2626
2605 my ($self, $cloning, $path) = @_; 2640 my ($self, $cloning, $path) = @_;
2606 2641
2607 $self->new (path => $path) 2642 $self->new (path => $path)
2608} 2643}
2609 2644
2645sub set_texture {
2646 my ($self, $tex) = @_;
2647
2648 $self->{tex} = $tex;
2649 $self->update;
2650}
2651
2610sub size_request { 2652sub size_request {
2611 my ($self) = @_; 2653 my ($self) = @_;
2612 2654
2613 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) 2655 (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale})
2614} 2656}
2615 2657
2616sub _draw { 2658sub _draw {
2617 my ($self) = @_; 2659 my ($self) = @_;
2660
2661 $self->SUPER::_draw;
2618 2662
2619 my $tex = $self->{tex}; 2663 my $tex = $self->{tex};
2620 2664
2621 my ($w, $h) = ($self->{w}, $self->{h}); 2665 my ($w, $h) = ($self->{w}, $self->{h});
2622 2666
2640package DC::UI::ImageButton; 2684package DC::UI::ImageButton;
2641 2685
2642our @ISA = DC::UI::Image::; 2686our @ISA = DC::UI::Image::;
2643 2687
2644use DC::OpenGL; 2688use DC::OpenGL;
2645
2646my %textures;
2647 2689
2648sub new { 2690sub new {
2649 my $class = shift; 2691 my $class = shift;
2650 2692
2651 my $self = $class->SUPER::new ( 2693 my $self = $class->SUPER::new (
2652 padding_x => 4, 2694 padding_x => 4,
2653 padding_y => 4, 2695 padding_y => 4,
2654 fg => [1, 1, 1], 2696 fg => [1, 1, 1],
2655 active_fg => [0, 0, 1], 2697 active_fg => [0, 0, 1],
2656 can_hover => 1, 2698 can_hover => 1,
2657 align => 0, 2699 align => 0.5,
2658 valign => 0, 2700 valign => 0.5,
2659 can_events => 1, 2701 can_events => 1,
2660 @_ 2702 @_
2661 ); 2703 );
2662} 2704}
2663 2705
2687 2729
2688use DC::OpenGL; 2730use DC::OpenGL;
2689 2731
2690my %tex = ( 2732my %tex = (
2691 food => [ 2733 food => [
2692 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2734 map { new_from_resource DC::Texture $_, mipmap => 1 }
2693 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2735 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2694 ], 2736 ],
2695 grace => [ 2737 grace => [
2696 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2738 map { new_from_resource DC::Texture $_, mipmap => 1 }
2697 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2739 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2698 ], 2740 ],
2699 hp => [ 2741 hp => [
2700 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2742 map { new_from_resource DC::Texture $_, mipmap => 1 }
2701 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2743 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2702 ], 2744 ],
2703 mana => [ 2745 mana => [
2704 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2746 map { new_from_resource DC::Texture $_, mipmap => 1 }
2705 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2747 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2706 ], 2748 ],
2707); 2749);
2708 2750
2709# eg. VGauge->new (gauge => 'food'), default gauge: food 2751# eg. VGauge->new (gauge => 'food'), default gauge: food
2822 2864
2823sub new { 2865sub new {
2824 my ($class, %arg) = @_; 2866 my ($class, %arg) = @_;
2825 2867
2826 my $self = $class->SUPER::new ( 2868 my $self = $class->SUPER::new (
2869 padding_x => 2,
2870 padding_y => 2,
2827 fg => [1, 1, 1], 2871 fg => [1, 1, 1],
2828 bg => [0, 0, 1, 0.2], 2872 bg => [0, 0, 1, 0.2],
2829 bar => [0.7, 0.5, 0.1, 0.8], 2873 bar => [0.7, 0.5, 0.1, 0.8],
2830 outline => [0.4, 0.3, 0], 2874 outline => [0.4, 0.3, 0],
2831 fontsize => 0.9, 2875 fontsize => 0.9,
2832 valign => 0, 2876 valign => 0.5,
2833 align => 0, 2877 align => 0.5,
2834 can_events => 1, 2878 can_events => 1,
2835 ellipsise => 1, 2879 ellipsise => 1,
2836 label => "%d%%", 2880 label => "%d%%",
2837 %arg, 2881 %arg,
2838 ); 2882 );
2871 my ($self) = @_; 2915 my ($self) = @_;
2872 2916
2873 glEnable GL_BLEND; 2917 glEnable GL_BLEND;
2874 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2918 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2875 2919
2920 my $px = $self->{padding_x};
2921 my $py = $self->{padding_y};
2922
2876 if ($self->{value} >= 0) { 2923 if ($self->{value} >= 0) {
2877 my $s = int 2 + ($self->{w} - 4) * $self->{value}; 2924 my $s = int $px + ($self->{w} - $px * 2) * $self->{value};
2878 2925
2879 glColor_premultiply @{$self->{bar}}; 2926 glColor_premultiply @{$self->{bar}};
2880 glRect 2, 2, $s, $self->{h} - 2; 2927 glRect $px, $py, $s, $self->{h} - $py;
2881 glColor_premultiply @{$self->{bg}}; 2928 glColor_premultiply @{$self->{bg}};
2882 glRect $s, 2, $self->{w} - 2, $self->{h} - 2; 2929 glRect $s , $py, $self->{w} - $px, $self->{h} - $py;
2883 } 2930 }
2884 2931
2885 glColor_premultiply @{$self->{outline}}; 2932 glColor_premultiply @{$self->{outline}};
2933
2934 $px -= .5;
2935 $py -= .5;
2936
2886 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; 2937 glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py;
2887 2938
2888 glDisable GL_BLEND; 2939 glDisable GL_BLEND;
2889 2940
2890 { 2941 {
2891 local $self->{bg}; # do not draw background 2942 local $self->{bg}; # do not draw background
2900our @ISA = DC::UI::Progress::; 2951our @ISA = DC::UI::Progress::;
2901 2952
2902sub new { 2953sub new {
2903 my ($class, %arg) = @_; 2954 my ($class, %arg) = @_;
2904 2955
2956 my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : "";
2957
2905 my $self = $class->SUPER::new ( 2958 my $self = $class->SUPER::new (
2959 %arg,
2906 tooltip => sub { 2960 tooltip => sub {
2907 my ($self) = @_; 2961 my ($self) = @_;
2908 2962
2909 sprintf "level %d\n%s points\n%s next level\n%s to go", 2963 sprintf "%slevel %d\n%s points\n%s next level\n%s to go, %d%% done",
2964 $tt,
2910 $self->{lvl}, 2965 $self->{lvl},
2911 ::formsep ($self->{exp}), 2966 ::formsep ($self->{exp}),
2912 ::formsep ($self->{nxt}), 2967 ::formsep ($self->{nxt}),
2913 ::formsep ($self->{nxt} - $self->{exp}), 2968 ::formsep ($self->{nxt} - $self->{exp}),
2969 $self->_percent * 100,
2914 }, 2970 },
2915 %arg
2916 ); 2971 );
2917 2972
2918 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2973 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2919 if $::CONN; 2974 if $::CONN;
2920 2975
2928 if $::CONN; 2983 if $::CONN;
2929 2984
2930 $self->SUPER::DESTROY; 2985 $self->SUPER::DESTROY;
2931} 2986}
2932 2987
2988sub _percent {
2989 my ($self) = @_;
2990
2991 my $table = $::CONN && $::CONN->{exp_table}
2992 or return -1;
2993
2994 my $l0 = $table->[$self->{lvl} - 1];
2995 my $l1 = $table->[$self->{lvl}];
2996
2997 $self->{nxt} = $l1;
2998
2999 ($self->{exp} - $l0) / ($l1 - $l0)
3000}
3001
2933sub set_value { 3002sub set_value {
2934 my ($self, $lvl, $exp) = @_; 3003 my ($self, $lvl, $exp) = @_;
2935 3004
2936 $self->{lvl} = $lvl; 3005 $self->{lvl} = $lvl;
2937 $self->{exp} = $exp; 3006 $self->{exp} = $exp;
2938 3007
2939 my $v = -1;
2940
2941 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2942 my $l0 = $table->[$lvl - 1];
2943 my $l1 = $table->[$lvl];
2944
2945 $self->{nxt} = $l1;
2946
2947 $v = ($exp - $l0) / ($l1 - $l0);
2948 }
2949
2950 $self->SUPER::set_value ($v); 3008 $self->SUPER::set_value ($self->_percent);
2951} 3009}
2952 3010
2953############################################################################# 3011#############################################################################
2954 3012
2955package DC::UI::Gauge; 3013package DC::UI::Gauge;
2964 can_hover => 1, 3022 can_hover => 1,
2965 can_events => 1, 3023 can_events => 1,
2966 %arg, 3024 %arg,
2967 ); 3025 );
2968 3026
2969 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); 3027 $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999");
2970 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 3028 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2971 $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999"); 3029 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2972 3030
2973 $self 3031 $self
2974} 3032}
2975 3033
2976sub set_fontsize { 3034sub set_fontsize {
2999 3057
3000############################################################################# 3058#############################################################################
3001 3059
3002package DC::UI::Slider; 3060package DC::UI::Slider;
3003 3061
3004use strict; 3062use common::sense;
3005 3063
3006use DC::OpenGL; 3064use DC::OpenGL;
3007 3065
3008our @ISA = DC::UI::DrawBG::; 3066our @ISA = DC::UI::DrawBG::;
3009 3067
3010my @tex = 3068my @tex =
3011 map { new_from_file DC::Texture DC::find_rcfile $_ } 3069 map { new_from_resource DC::Texture $_ }
3012 qw(s1_slider.png s1_slider_bg.png); 3070 qw(s1_slider.png s1_slider_bg.png);
3013 3071
3014sub new { 3072sub new {
3015 my $class = shift; 3073 my $class = shift;
3016 3074
3053sub set_value { 3111sub set_value {
3054 my ($self, $value) = @_; 3112 my ($self, $value) = @_;
3055 3113
3056 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3114 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3057 3115
3058 $hi = $lo + 1 if $hi <= $lo; 3116 $hi = $lo if $hi < $lo;
3059 3117
3060 $page = $hi - $lo if $page > $hi - $lo; 3118 $value = $hi - $page if $value > $hi - $page;
3061
3062 $value = $lo if $value < $lo; 3119 $value = $lo if $value < $lo;
3063 $value = $hi - $page if $value > $hi - $page;
3064 3120
3065 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3121 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3066 if $unit; 3122 if $unit;
3067 3123
3068 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3124 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3083 my ($self, $ev, $x, $y) = @_; 3139 my ($self, $ev, $x, $y) = @_;
3084 3140
3085 $self->SUPER::invoke_button_down ($ev, $x, $y); 3141 $self->SUPER::invoke_button_down ($ev, $x, $y);
3086 3142
3087 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 3143 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
3088 3144
3089 $self->invoke_mouse_motion ($ev, $x, $y); 3145 $self->invoke_mouse_motion ($ev, $x, $y);
3090 3146
3091 1 3147 1
3092} 3148}
3093 3149
3097 if ($GRAB == $self) { 3153 if ($GRAB == $self) {
3098 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 3154 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
3099 3155
3100 my (undef, $lo, $hi, $page) = @{$self->{range}}; 3156 my (undef, $lo, $hi, $page) = @{$self->{range}};
3101 3157
3102 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 3158 $x = ($x - $self->{click}[1]) / ($w * $self->{scale} || 1e999);
3103 3159
3104 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 3160 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
3105 } else { 3161 } else {
3106 return 0; 3162 return 0;
3107 } 3163 }
3132 my ($self) = @_; 3188 my ($self) = @_;
3133 3189
3134 unless ($self->{knob_w}) { 3190 unless ($self->{knob_w}) {
3135 $self->set_value ($self->{range}[0]); 3191 $self->set_value ($self->{range}[0]);
3136 3192
3137 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3193 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3138 my $range = ($hi - $page - $lo) || 1e-100; 3194 my $range = ($hi - $page - $lo) || 1e-10;
3139 3195
3140 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3196 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3141 3197
3142 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3198 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3143 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3199 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3144 3200
3145 $value = ($value - $lo) / $range; 3201 $value = ($value - $lo) / $range;
3153 3209
3154 glScale $self->{w}, $self->{h}; 3210 glScale $self->{w}, $self->{h};
3155 3211
3156 if ($self->{vertical}) { 3212 if ($self->{vertical}) {
3157 # draw a vertical slider like a rotated horizontal slider 3213 # draw a vertical slider like a rotated horizontal slider
3158 3214
3159 glTranslate 1, 0, 0; 3215 glTranslate 1, 0, 0;
3160 glRotate 90, 0, 0, 1; 3216 glRotate 90, 0, 0, 1;
3161 } 3217 }
3162 3218
3163 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 3219 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
3231 fontsize => 1, 3287 fontsize => 1,
3232 can_events => 1, 3288 can_events => 1,
3233 indent => 0, 3289 indent => 0,
3234 #font => default_font 3290 #font => default_font
3235 @_, 3291 @_,
3236 3292
3237 layout => (new DC::Layout), 3293 layout => (new DC::Layout),
3238 par => [],
3239 max_par => 0, 3294 max_par => 0,
3240 height => 0, 3295 height => 0,
3241 children => [ 3296 children => [
3242 (new DC::UI::Empty expand => 1), 3297 (new DC::UI::Empty expand => 1),
3243 (new DC::UI::Slider vertical => 1), 3298 (new DC::UI::Slider vertical => 1),
3244 ], 3299 ],
3245 ); 3300 );
3246 3301
3247 $self->{children}[1]->connect (changed => sub { $self->update }); 3302 $self->{children}[1]->connect (changed => sub { $self->update });
3248 3303
3304 $self->add_paragraph (@{ delete $self->{par} }) if @{ $self->{par} };
3305
3249 $self 3306 $self
3250} 3307}
3251 3308
3252sub set_fontsize { 3309sub set_fontsize {
3253 my ($self, $fontsize) = @_; 3310 my ($self, $fontsize) = @_;
3304 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3361 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3305 $layout->set_markup ($para->{markup}); 3362 $layout->set_markup ($para->{markup});
3306 3363
3307 $layout->set_shapes ( 3364 $layout->set_shapes (
3308 map 3365 map
3309 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3366 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3310 @{$para->{widget}} 3367 @{$para->{widget}}
3311 ); 3368 );
3312 3369
3313 $layout 3370 $layout
3314} 3371}
3516 my ($self, $x, $y) = @_; 3573 my ($self, $x, $y) = @_;
3517 3574
3518 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 3575 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
3519 $self->{speed} = 0.001; 3576 $self->{speed} = 0.001;
3520 $self->{time} = 1; 3577 $self->{time} = 1;
3521 3578
3522 ::animation_start $self; 3579 ::animation_start $self;
3523} 3580}
3524 3581
3525sub animate { 3582sub animate {
3526 my ($self, $interval) = @_; 3583 my ($self, $interval) = @_;
3530 $self->{time} = 0; 3587 $self->{time} = 0;
3531 ::animation_stop $self; 3588 ::animation_stop $self;
3532 } 3589 }
3533 3590
3534 my ($x0, $y0, $x1, $y1) = @{$self->{moveto}}; 3591 my ($x0, $y0, $x1, $y1) = @{$self->{moveto}};
3535 3592
3536 $self->{x} = $x0 * $self->{time} + $x1 * (1 - $self->{time}); 3593 $self->{x} = $x0 * $self->{time} + $x1 * (1 - $self->{time});
3537 $self->{y} = $y0 * $self->{time} + $y1 * (1 - $self->{time}); 3594 $self->{y} = $y0 * $self->{time} + $y1 * (1 - $self->{time});
3538} 3595}
3539 3596
3540sub _draw { 3597sub _draw {
3585 @_, 3642 @_,
3586 can_events => 0, 3643 can_events => 0,
3587 ) 3644 )
3588} 3645}
3589 3646
3647# expand, as good as possible
3648sub _expand_doclets {
3649 my ($tip) = @_;
3650
3651 $tip =~ s{#\(([^)]+)\)}{
3652 if ($::CONN) {
3653 exists $::CONN->{doclet}{$1}
3654 ? $::CONN->{doclet}{$1}
3655 : "(waiting for server to show full text)"
3656 } else {
3657 "(unable to show full text without server connection)"
3658 }
3659 }ge;
3660
3661 $tip =~ s/^\n+//;
3662 $tip =~ s/\n+$//;
3663
3664 $tip
3665}
3666
3667# expands a tooltip, potentially multiple times remotely
3668# and returns a guard. clals the clalback each time the text changes.
3669sub expand_tooltip {
3670 my ($tip, $cb) = @_;
3671
3672 # first expand #name tooltips from local pod
3673 $tip = DC::Pod::section_label tooltip => $1
3674 if $tip =~ /^#([^(].*)$/;
3675
3676 my $active; # true if any remote requests outstanding
3677
3678 if ($::CONN && $::CONN->{addme_success}) {
3679 # now find all doclet references
3680 for my $doclet ($tip =~ /#\(([^)]+)\)/g) {
3681 unless (exists $::CONN->{doclet}{$doclet}) {
3682 # need to ask the server
3683 # we don't try to avoid duplicate requests
3684
3685 $active = 1;
3686 $::CONN->send_exti_req (doclet => (split /\//, $doclet, 2), sub {
3687 $::CONN->{doclet}{$doclet} = DC::sanitise_cfxml $_[0];
3688 $cb->(_expand_doclets $tip) if $active;
3689 });
3690 }
3691 }
3692 }
3693
3694 $cb->(_expand_doclets $tip);
3695
3696 $active and Guard::guard { undef $active }
3697}
3698
3590sub set_tooltip_from { 3699sub set_tooltip_from {
3591 my ($self, $widget) = @_; 3700 my ($self, $widget) = @_;
3592 3701
3593 my $tip = $widget->{tooltip}; 3702 my $tip = $widget->{tooltip};
3594 $tip = $tip->($widget) if "CODE" eq ref $tip; 3703 $tip = $tip->($widget) if "CODE" eq ref $tip;
3595
3596 $tip = DC::Pod::section_label tooltip => $1
3597 if $tip =~ /^#(.*)$/;
3598
3599 if ($ENV{CFPLUS_DEBUG} & 2) {
3600 $tip .= "\n\n" . (ref $widget) . "\n"
3601 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3602 . "req $widget->{req_w} $widget->{req_h}\n"
3603 . "visible $widget->{visible}";
3604 }
3605
3606 $tip =~ s/^\n+//;
3607 $tip =~ s/\n+$//;
3608 3704
3609 $self->add (new DC::UI::Label 3705 $self->add (new DC::UI::Label
3610 markup => $tip, 3706 fg => $DC::THEME{tooltip_fg},
3611 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3707 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3708 align => 0,
3612 fontsize => 0.8, 3709 fontsize => 0.8,
3613 style => 1, # FLAG_INVERSE 3710 style => $DC::THEME{tooltip_style}, # FLAG_INVERSE
3614 ellipsise => 0, 3711 ellipsise => 0,
3615 font => ($widget->{tooltip_font} || $::FONT_PROP), 3712 font => ($widget->{tooltip_font} || $::FONT_PROP),
3616 ); 3713 );
3714
3715 $self->{tooltip_expand} = expand_tooltip $tip, sub {
3716 my ($tip) = @_;
3717
3718 if ($ENV{CFPLUS_DEBUG} & 2) {
3719 $tip .= "\n\n" . (ref $widget) . "\n"
3720 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3721 . "req $widget->{req_w} $widget->{req_h}\n"
3722 . "visible $widget->{visible}";
3723 }
3724
3725 $self->{children}[0]->set_markup ($tip);
3726 };
3617} 3727}
3618 3728
3619sub size_request { 3729sub size_request {
3620 my ($self) = @_; 3730 my ($self) = @_;
3621 3731
3655sub _draw { 3765sub _draw {
3656 my ($self) = @_; 3766 my ($self) = @_;
3657 3767
3658 my ($w, $h) = @$self{qw(w h)}; 3768 my ($w, $h) = @$self{qw(w h)};
3659 3769
3660 glColor 1, 0.8, 0.4; 3770 glColor @{ $DC::THEME{tooltip_bg} };
3661 glRect 0, 0, $w, $h; 3771 glRect 0, 0, $w, $h;
3662 3772
3663 glColor 0, 0, 0; 3773 glColor @{ $DC::THEME{tooltip_border} };
3664 glRect_lineloop .5, .5, $w + .5, $h + .5; 3774 glRect_lineloop .5, .5, $w + .5, $h + .5;
3665 3775
3666 glTranslate 2, 2; 3776 glTranslate 2, 2;
3667 3777
3668 $self->SUPER::_draw; 3778 $self->SUPER::_draw;
3669} 3779}
3670 3780
3685 aspect => 1, 3795 aspect => 1,
3686 can_events => 0, 3796 can_events => 0,
3687 @_, 3797 @_,
3688 ); 3798 );
3689 3799
3690 if ($self->{anim} && $self->{animspeed}) {
3691 DC::weaken (my $widget = $self);
3692
3693 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3694 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3695 return unless $::CONN;
3696
3697 my $w = $widget
3698 or return;
3699
3700 ++$w->{frame};
3701 $w->update_face;
3702
3703 # somehow, $widget can go away
3704 $w->update;
3705 $w->update_timer;
3706 };
3707
3708 $self->update_face;
3709 $self->update_timer; 3800 $self->update_anim;
3710 } 3801
3711
3712 $self 3802 $self
3713} 3803}
3714 3804
3715sub update_timer { 3805sub update_timer {
3716 my ($self) = @_; 3806 my ($self) = @_;
3738 $tex->upload (sub { $self->reconfigure }); 3828 $tex->upload (sub { $self->reconfigure });
3739 } 3829 }
3740 } 3830 }
3741 } 3831 }
3742 } 3832 }
3833 }
3834}
3835
3836sub update_anim {
3837 my ($self) = @_;
3838
3839 if ($self->{anim} && $self->{animspeed}) {
3840 DC::weaken (my $widget = $self);
3841
3842 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3843 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3844 return unless $::CONN;
3845
3846 my $w = $widget
3847 or return;
3848
3849 ++$w->{frame};
3850 $w->update_face;
3851
3852 # somehow, $widget can go away
3853 $w->update;
3854 $w->update_timer;
3855 };
3856
3857 $self->update_face;
3858 $self->update_timer;
3859 } else {
3860 delete $self->{timer};
3743 } 3861 }
3744} 3862}
3745 3863
3746sub size_request { 3864sub size_request {
3747 my ($self) = @_; 3865 my ($self) = @_;
3769 return unless $self->{visible}; 3887 return unless $self->{visible};
3770 3888
3771 $self->SUPER::update; 3889 $self->SUPER::update;
3772} 3890}
3773 3891
3892sub set_face {
3893 my ($self, $face) = @_;
3894
3895 $self->{face} = $face;
3896 $self->reconfigure;
3897}
3898
3899sub set_anim {
3900 my ($self, $anim) = @_;
3901
3902 $self->{anim} = $anim;
3903 $self->update_anim;
3904}
3905
3906sub set_animspeed {
3907 my ($self, $animspeed) = @_;
3908
3909 $self->{animspeed} = $animspeed;
3910 $self->update_anim;
3911}
3912
3774sub invoke_visibility_change { 3913sub invoke_visibility_change {
3775 my ($self) = @_; 3914 my ($self) = @_;
3776 3915
3777 $self->update_timer; 3916 $self->update_timer;
3778 3917
3840 $widget = new DC::UI::HBox 3979 $widget = new DC::UI::HBox
3841 can_hover => 1, 3980 can_hover => 1,
3842 can_events => 1, 3981 can_events => 1,
3843 tooltip => $tooltip, 3982 tooltip => $tooltip,
3844 children => [ 3983 children => [
3845 (new DC::UI::Label markup => $left, expand => 1), 3984 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3846 (new DC::UI::Label markup => $right, align => +1), 3985 (new DC::UI::Label markup => $right, align => 1),
3847 ], 3986 ],
3848 ; 3987 ;
3849 3988
3850 } else { 3989 } else {
3851 $widget = new DC::UI::Label 3990 $widget = new DC::UI::Label
3852 can_hover => 1, 3991 can_hover => 1,
3853 can_events => 1, 3992 can_events => 1,
3993 align => 0,
3854 markup => $widget, 3994 markup => $widget,
3855 tooltip => $tooltip; 3995 tooltip => $tooltip;
3856 } 3996 }
3857 } 3997 }
3858 3998
3873 # maybe save $GRAB? must be careful about events... 4013 # maybe save $GRAB? must be careful about events...
3874 $GRAB = $self; 4014 $GRAB = $self;
3875 $self->{button} = $ev->{button}; 4015 $self->{button} = $ev->{button};
3876 4016
3877 $self->show; 4017 $self->show;
3878 $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); 4018
4019 my $x = $ev->{x};
4020 my $y = $ev->{y};
4021
4022 $self->{root}->on_post_alloc ($self => sub {
4023 $self->move_abs ($x - $self->{w} * 0.25, $y - $self->{border} * $::FONTSIZE * .5);
4024 });
4025
4026 1 # so it can be used inside event handlers
3879} 4027}
3880 4028
3881sub invoke_mouse_motion { 4029sub invoke_mouse_motion {
3882 my ($self, $ev, $x, $y) = @_; 4030 my ($self, $ev, $x, $y) = @_;
3883 4031
3915 4063
3916 my $self = $class->SUPER::new ( 4064 my $self = $class->SUPER::new (
3917 @_, 4065 @_,
3918 ); 4066 );
3919 4067
3920 $self->{current} = $self->{children}[0] 4068 $self->set_current_page (0);
3921 if @{ $self->{children} };
3922 4069
3923 $self 4070 $self
3924} 4071}
3925 4072
3926sub add { 4073sub add {
3927 my ($self, @widgets) = @_; 4074 my ($self, @widgets) = @_;
3928 4075
3929 $self->SUPER::add (@widgets); 4076 $self->SUPER::add (@widgets);
3930 4077
3931 $self->{current} = $self->{children}[0] 4078 $self->set_current_page (0)
3932 if @{ $self->{children} }; 4079 if @widgets == @{ $self->{children} };
3933} 4080}
3934 4081
3935sub get_current_page { 4082sub get_current_page {
3936 my ($self) = @_; 4083 my ($self) = @_;
3937 4084
3943 4090
3944 my $widget = ref $page_or_widget 4091 my $widget = ref $page_or_widget
3945 ? $page_or_widget 4092 ? $page_or_widget
3946 : $self->{children}[$page_or_widget]; 4093 : $self->{children}[$page_or_widget];
3947 4094
4095 $self->{current}->set_invisible if $self->{current} && $self->{visible};
4096
3948 $self->{current} = $widget; 4097 if (($self->{current} = $widget)) {
4098 $self->{current}->set_visible if $self->{current} && $self->{visible};
3949 $self->{current}->configure (0, 0, $self->{w}, $self->{h}); 4099 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3950 4100
3951 $self->emit (page_changed => $self->{current}); 4101 $self->emit (page_changed => $self->{current});
4102 }
3952 4103
3953 $self->realloc; 4104 $self->realloc;
3954} 4105}
3955 4106
3956sub visible_children { 4107sub visible_children {
3957 $_[0]{current} 4108 $_[0]{current} || ()
3958} 4109}
3959 4110
3960sub size_request { 4111sub size_request {
3961 my ($self) = @_; 4112 my ($self) = @_;
3962 4113
4114 $self->{current}
3963 $self->{current}->size_request 4115 ? $self->{current}->size_request
4116 : (0, 0)
3964} 4117}
3965 4118
3966sub invoke_size_allocate { 4119sub invoke_size_allocate {
3967 my ($self, $w, $h) = @_; 4120 my ($self, $w, $h) = @_;
3968 4121
3969 $self->{current}->configure (0, 0, $w, $h); 4122 $self->{current}->configure (0, 0, $w, $h)
4123 if $self->{current};
3970 4124
3971 1 4125 1
3972} 4126}
3973 4127
3974sub _draw { 4128sub _draw {
3975 my ($self) = @_; 4129 my ($self) = @_;
3976 4130
3977 $self->{current}->draw; 4131 $self->{current}->draw
4132 if $self->{current};
3978} 4133}
3979 4134
3980############################################################################# 4135#############################################################################
3981 4136
3982package DC::UI::Notebook; 4137package DC::UI::Notebook;
4049} 4204}
4050 4205
4051sub pages { 4206sub pages {
4052 my ($self) = @_; 4207 my ($self) = @_;
4053 $self->{multiplexer}->children 4208 $self->{multiplexer}->children
4209}
4210
4211sub page_index {
4212 my ($self, $widget) = @_;
4213
4214 my $i = 0;
4215 for ($self->pages) {
4216 if ($_ eq $widget) { return $i };
4217 $i++;
4218 }
4219
4220 undef
4054} 4221}
4055 4222
4056sub add_tab { 4223sub add_tab {
4057 my ($self, $title, $widget, $tooltip) = @_; 4224 my ($self, $title, $widget, $tooltip) = @_;
4058 4225
4180 $self 4347 $self
4181} 4348}
4182 4349
4183sub reorder { 4350sub reorder {
4184 my ($self) = @_; 4351 my ($self) = @_;
4185 my $NOW = Time::HiRes::time; 4352 my $NOW = AE::time;
4186 4353
4187 # freeze display when hovering over any label 4354 # freeze display when hovering over any label
4188 return if $DC::UI::TOOLTIP->{owner} 4355 return if $DC::UI::TOOLTIP->{owner}
4189 && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, 4356 && grep $DC::UI::TOOLTIP->{owner} == $_->{label},
4190 values %{ $self->{item} }; 4357 values %{ $self->{item} };
4222 tooltip => $item->{tooltip}, 4389 tooltip => $item->{tooltip},
4223 tooltip_font => $::FONT_PROP, 4390 tooltip_font => $::FONT_PROP,
4224 tooltip_width => 0.67, 4391 tooltip_width => 0.67,
4225 fontsize => $item->{fontsize} || $self->{fontsize}, 4392 fontsize => $item->{fontsize} || $self->{fontsize},
4226 max_w => $::WIDTH * 0.44, 4393 max_w => $::WIDTH * 0.44,
4394 align => 0,
4227 fg => [@{ $item->{fg} }], 4395 fg => [@{ $item->{fg} }],
4228 can_events => 1, 4396 can_events => 1,
4229 can_hover => 1 4397 can_hover => 1
4230 }; 4398 };
4231 4399
4239 $label->{fg}[3] = $item->{fg}[3] || 1; 4407 $label->{fg}[3] = $item->{fg}[3] || 1;
4240 } 4408 }
4241 4409
4242 push @widgets, $label; 4410 push @widgets, $label;
4243 } 4411 }
4412
4413 my $hash = join ",", @widgets;
4414 return if $hash eq $self->{last_widget_hash};
4415 $self->{last_widget_hash} = $hash;
4244 4416
4245 $self->clear; 4417 $self->clear;
4246 $self->SUPER::add (reverse @widgets); 4418 $self->SUPER::add (reverse @widgets);
4247} 4419}
4248 4420
4284 $ROOT->on_refresh (reorder => sub { 4456 $ROOT->on_refresh (reorder => sub {
4285 $self->reorder; 4457 $self->reorder;
4286 }); 4458 });
4287} 4459}
4288 4460
4461sub clr_group {
4462 my ($self, $group) = @_;
4463
4464 if (delete $self->{item}{$group}) {
4465 $ROOT->on_refresh (reorder => sub {
4466 $self->reorder;
4467 });
4468 }
4469}
4470
4289sub reconfigure { 4471sub reconfigure {
4290 my ($self) = @_; 4472 my ($self) = @_;
4291 4473
4292 delete $_->{label} 4474 delete $_->{label}
4293 for values %{ $self->{item} || {} }; 4475 for values %{ $self->{item} || {} };
4447 while () { 4629 while () {
4448 @queue or last outer; 4630 @queue or last outer;
4449 4631
4450 $widget = pop @{ $queue[-1] || [] } 4632 $widget = pop @{ $queue[-1] || [] }
4451 and last; 4633 and last;
4452 4634
4453 pop @queue; 4635 pop @queue;
4454 } 4636 }
4455 4637
4456 delete $queue{$widget+0}; 4638 delete $queue{$widget+0};
4457 4639
4458 my ($w, $h) = $widget->size_request; 4640 my ($w, $h) = $widget->size_request;
4459 4641
4460 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4642 $w += $widget->{padding_x} * 2;
4461 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4643 $h += $widget->{padding_y} * 2;
4644
4645 $w = max $widget->{min_w}, $w;
4646 $h = max $widget->{min_h}, $h;
4462 4647
4463 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4648 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4464 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4649 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4465 4650
4466 $w = $widget->{force_w} if exists $widget->{force_w}; 4651 $w = $widget->{force_w} if exists $widget->{force_w};
4546 4731
4547############################################################################# 4732#############################################################################
4548 4733
4549package DC::UI; 4734package DC::UI;
4550 4735
4551$ROOT = new DC::UI::Root; 4736$ROOT = new DC::UI::Root;
4552$TOOLTIP = new DC::UI::Tooltip z => 900; 4737$TOOLTIP = new DC::UI::Tooltip z => 900;
4553 4738
45541 47391
4555

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines