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.211 by elmex, Wed May 17 10:33:03 2006 UTC vs.
Revision 1.216 by root, Fri May 19 16:43:57 2006 UTC

140 140
141# call when resolution changes etc. 141# call when resolution changes etc.
142sub rescale_widgets { 142sub rescale_widgets {
143 my ($sx, $sy) = @_; 143 my ($sx, $sy) = @_;
144 144
145 # make a copy, otherwise for complains about freed values.
145 for my $widget (values %WIDGET) { 146 my @widgets = values %WIDGET;
147
148 for my $widget (@widgets) {
146 if ($widget->{toplevel}) { 149 if ($widget->{toplevel}) {
147 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; 150 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
148 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 151 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
149 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; 152 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
150 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; 153 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
688 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 691 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
689 glClearColor 0, 0, 0, 0; 692 glClearColor 0, 0, 0, 0;
690 glClear GL_COLOR_BUFFER_BIT; 693 glClear GL_COLOR_BUFFER_BIT;
691 694
692 $self->_render; 695 $self->_render;
693# glColorMask 1, 1, 1, 0;
694# glEnable GL_BLEND;
695# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
696# glRasterPos 0, 0;
697# glCopyPixels 0, 0, $self->{w}, $self->{h};
698# glDisable GL_BLEND;
699# glColorMask 1, 1, 1, 1;
700 }; 696 };
701} 697}
702 698
703sub _draw { 699sub _draw {
704 my ($self) = @_; 700 my ($self) = @_;
708 my $tex = $self->{texture} 704 my $tex = $self->{texture}
709 or return; 705 or return;
710 706
711 glEnable GL_TEXTURE_2D; 707 glEnable GL_TEXTURE_2D;
712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 708 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
713 glColor 0, 0, 0, 1; 709 glColor 1, 1, 1, 1;
714 710
715 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 711 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
716 712
717 glDisable GL_TEXTURE_2D; 713 glDisable GL_TEXTURE_2D;
718} 714}
1297 #bg => none 1293 #bg => none
1298 #active_bg => none 1294 #active_bg => none
1299 #font => default_font 1295 #font => default_font
1300 #text => initial text 1296 #text => initial text
1301 #markup => initial narkup 1297 #markup => initial narkup
1298 #max_w => maximum pixel width
1299 ellipsise => 3, # end
1302 layout => (new CFClient::Layout), 1300 layout => (new CFClient::Layout),
1303 fontsize => 1, 1301 fontsize => 1,
1304 align => -1, 1302 align => -1,
1305 valign => -1, 1303 valign => -1,
1306 padding => 2, 1304 padding => 2,
1371sub size_request { 1369sub size_request {
1372 my ($self) = @_; 1370 my ($self) = @_;
1373 1371
1374 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1372 $self->{layout}->set_font ($self->{font}) if $self->{font};
1375 $self->{layout}->set_width ($self->{max_w} || -1); 1373 $self->{layout}->set_width ($self->{max_w} || -1);
1374 $self->{layout}->set_ellipsise ($self->{ellipsise});
1375 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1376 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1377 1377
1378 my ($w, $h) = $self->{layout}->size; 1378 my ($w, $h) = $self->{layout}->size;
1379 1379
1380 if (exists $self->{template}) { 1380 if (exists $self->{template}) {
1416 1416
1417 my $tex = $self->{texture} ||= do { 1417 my $tex = $self->{texture} ||= do {
1418 $self->{layout}->set_foreground (@{$self->{fg}}); 1418 $self->{layout}->set_foreground (@{$self->{fg}});
1419 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1419 $self->{layout}->set_font ($self->{font}) if $self->{font};
1420 $self->{layout}->set_width ($self->{w}); 1420 $self->{layout}->set_width ($self->{w});
1421 $self->{layout}->set_ellipsise ($self->{ellipsise});
1422 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1421 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1423 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1422 1424
1423 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1425 my $tex = new_from_layout CFClient::Texture $self->{layout};
1424 1426
1425 $self->{ox} = int ($self->{align} < 0 ? $self->{padding} 1427 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1426 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1428 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
2148 glScale $self->{w}, $self->{h}; 2150 glScale $self->{w}, $self->{h};
2149 2151
2150 if ($self->{vertical}) { 2152 if ($self->{vertical}) {
2151 # draw a vertical slider like a rotated horizontal slider 2153 # draw a vertical slider like a rotated horizontal slider
2152 2154
2155 glTranslate 1, 0, 0;
2153 glRotate 90, 0, 0, 1; 2156 glRotate 90, 0, 0, 1;
2154 glTranslate 0, 1, 0;
2155 } 2157 }
2156 2158
2157 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2159 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2158 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2160 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2159 2161
2275 2277
2276 delete $self->{texture}; 2278 delete $self->{texture};
2277 } 2279 }
2278 2280
2279 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2281 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
2280 glClearColor 0, 0, 0, 0; 2282 glClearColor 0.5, 0.5, 0.5, 0;
2281 glClear GL_COLOR_BUFFER_BIT; 2283 glClear GL_COLOR_BUFFER_BIT;
2282 2284
2283 glEnable GL_TEXTURE_2D; 2285 glEnable GL_TEXTURE_2D;
2284 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2286 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2285 2287
2317 my ($self) = @_; 2319 my ($self) = @_;
2318 2320
2319 glEnable GL_TEXTURE_2D; 2321 glEnable GL_TEXTURE_2D;
2320 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2322 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2321 glColor 1, 1, 1, 1; 2323 glColor 1, 1, 1, 1;
2322 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2324 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2323 glDisable GL_TEXTURE_2D; 2325 glDisable GL_TEXTURE_2D;
2324 2326
2325 $self->{children}[1]->draw; 2327 $self->{children}[1]->draw;
2326 2328
2327} 2329}
2426 2428
2427sub set_tooltip_from { 2429sub set_tooltip_from {
2428 my ($self, $widget) = @_; 2430 my ($self, $widget) = @_;
2429 2431
2430 $self->add (new CFClient::UI::Label 2432 $self->add (new CFClient::UI::Label
2431 markup => $widget->{tooltip}, 2433 markup => $widget->{tooltip},
2432 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2434 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2433 fontsize => 0.8, 2435 fontsize => 0.8,
2434 fg => [0, 0, 0, 1], 2436 fg => [0, 0, 0, 1],
2437 ellipsise => 0,
2435 font => ($widget->{tooltip_font} || $::FONT_PROP), 2438 font => ($widget->{tooltip_font} || $::FONT_PROP),
2436 ); 2439 );
2437} 2440}
2438 2441
2439sub size_request { 2442sub size_request {
2440 my ($self) = @_; 2443 my ($self) = @_;
2518 2521
2519package CFClient::UI::InventoryItem; 2522package CFClient::UI::InventoryItem;
2520 2523
2521our @ISA = CFClient::UI::HBox::; 2524our @ISA = CFClient::UI::HBox::;
2522 2525
2523sub new { 2526sub _item_to_desc {
2524 my $class = shift; 2527 my ($item) = @_;
2525 2528
2526 my %args = @_; 2529 my $desc =
2527
2528 my $item = delete $args{item};
2529
2530 my $desc = $item->{nrof} < 2 2530 $item->{nrof} < 2
2531 ? $item->{name} 2531 ? $item->{name}
2532 : "$item->{nrof} $item->{name_pl}"; 2532 : "$item->{nrof} $item->{name_pl}";
2533 2533
2534 $item->{flags} & Crossfire::Protocol::F_OPEN 2534 $item->{flags} & Crossfire::Protocol::F_OPEN
2535 and $desc .= " (open)"; 2535 and $desc .= " (open)";
2536 $item->{flags} & Crossfire::Protocol::F_APPLIED 2536 $item->{flags} & Crossfire::Protocol::F_APPLIED
2537 and $desc .= " (applied)"; 2537 and $desc .= " (applied)";
2544 $item->{flags} & Crossfire::Protocol::F_DAMNED 2544 $item->{flags} & Crossfire::Protocol::F_DAMNED
2545 and $desc .= " (damned)"; 2545 and $desc .= " (damned)";
2546 $item->{flags} & Crossfire::Protocol::F_LOCKED 2546 $item->{flags} & Crossfire::Protocol::F_LOCKED
2547 and $desc .= " *"; 2547 and $desc .= " *";
2548 2548
2549 $desc
2550}
2551
2552sub new {
2553 my $class = shift;
2554
2555 my %args = @_;
2556
2557 my $item = delete $args{item};
2558
2559 my $desc = _item_to_desc ($item);
2560
2549 my $self = $class->SUPER::new ( 2561 my $self = $class->SUPER::new (
2550 can_hover => 1, 2562 can_hover => 1,
2551 can_events => 1, 2563 can_events => 1,
2552 tooltip => ((CFClient::UI::Label::escape $desc) 2564 tooltip => ((CFClient::UI::Label::escape $desc)
2553 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2565 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2583 1 2595 1
2584 }, 2596 },
2585 %args 2597 %args
2586 ); 2598 );
2587 2599
2600
2588 $self->add (new CFClient::UI::Face 2601 $self->add (new CFClient::UI::Face
2589 can_events => 0, 2602 can_events => 0,
2590 face => $item->{face}, 2603 face => $item->{face},
2591 anim => $item->{anim}, 2604 anim => $item->{anim},
2592 animspeed => $item->{animspeed}, 2605 animspeed => $item->{animspeed},
2593 ); 2606 );
2594 2607
2595 $self->add (new CFClient::UI::Label 2608 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2596 can_events => 0, 2609
2597 text => $desc, 2610 $self->{item} = $item;
2598 ); 2611
2612 $self->update_item;
2599 2613
2600 $self 2614 $self
2615}
2616
2617sub update_item {
2618 my ($self) = @_;
2619
2620 my $desc = _item_to_desc ($self->{item});
2621
2622 $self->{name_lbl}->set_text ($desc);
2601} 2623}
2602 2624
2603############################################################################# 2625#############################################################################
2604 2626
2605package CFClient::UI::Inventory; 2627package CFClient::UI::Inventory;
2629 } @$items; 2651 } @$items;
2630 2652
2631 $self->{real_items} = \@items; 2653 $self->{real_items} = \@items;
2632 2654
2633 for my $item (@items) { 2655 for my $item (@items) {
2634 my $desc = $item->{nrof} < 2
2635 ? $item->{name}
2636 : "$item->{nrof} $item->{name_pl}";
2637
2638 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; 2656 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2657 $item->update_item ();
2639 } 2658 }
2640 2659
2641 $self->{scrolled}->add (@items); 2660 $self->{scrolled}->add (@items);
2642 2661
2643# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2662# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2758 # TODO: doesn't handle markup well (read as: at all) 2777 # TODO: doesn't handle markup well (read as: at all)
2759 my $short = $item->{count} > 1 2778 my $short = $item->{count} > 1
2760 ? "<b>$item->{count} ×</b> $item->{text}" 2779 ? "<b>$item->{count} ×</b> $item->{text}"
2761 : $item->{text}; 2780 : $item->{text};
2762 2781
2763 my $fontsize = $item->{fontsize} || $self->{fontsize};
2764
2765 for ($short) { 2782 for ($short) {
2766 s/^\s+//; 2783 s/^\s+//;
2767 s/\s+/ /g; 2784 s/\s+/ /g;
2768 my $len = int 40 / $fontsize;
2769 substr $_, $len, length, "…" if $len < length;
2770 } 2785 }
2771 2786
2772 new CFClient::UI::Label 2787 new CFClient::UI::Label
2773 markup => $short, 2788 markup => $short,
2774 tooltip => $item->{tooltip}, 2789 tooltip => $item->{tooltip},
2775 tooltip_font => $::FONT_PROP, 2790 tooltip_font => $::FONT_PROP,
2776 tooltip_width => 0.67, 2791 tooltip_width => 0.67,
2777 fontsize => $fontsize, 2792 fontsize => $item->{fontsize} || $self->{fontsize},
2793 max_w => $::WIDTH * 0.44,
2778 fg => $item->{fg}, 2794 fg => $item->{fg},
2779 can_events => 1, 2795 can_events => 1,
2780 can_hover => 1 2796 can_hover => 1
2781 }; 2797 };
2782 } 2798 }
2819 } 2835 }
2820 2836
2821 $self->reorder; 2837 $self->reorder;
2822} 2838}
2823 2839
2840sub reconfigure {
2841 my ($self) = @_;
2842
2843 delete $_->{label}
2844 for values %{ $self->{item} || {} };
2845
2846 $self->reorder;
2847 $self->SUPER::reconfigure;
2848}
2849
2824############################################################################# 2850#############################################################################
2825 2851
2826package CFClient::UI::Root; 2852package CFClient::UI::Root;
2827 2853
2828our @ISA = CFClient::UI::Container::; 2854our @ISA = CFClient::UI::Container::;
3001############################################################################# 3027#############################################################################
3002 3028
3003package CFClient::UI; 3029package CFClient::UI;
3004 3030
3005$ROOT = new CFClient::UI::Root; 3031$ROOT = new CFClient::UI::Root;
3006$TOOLTIP = new CFClient::UI::Tooltip; 3032$TOOLTIP = new CFClient::UI::Tooltip z => 900;
3007 3033
30081 30341
3009 3035

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines