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.176 by root, Tue Apr 25 12:10:58 2006 UTC vs.
Revision 1.178 by root, Tue Apr 25 13:51:48 2006 UTC

904 $tex[1]->draw_quad (0, 0, $w, $border); 904 $tex[1]->draw_quad (0, 0, $w, $border);
905 $tex[3]->draw_quad (0, $border, $border, $ch); 905 $tex[3]->draw_quad (0, $border, $border, $ch);
906 $tex[2]->draw_quad ($w - $border, $border, $border, $ch); 906 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
907 $tex[4]->draw_quad (0, $h - $border, $w, $border); 907 $tex[4]->draw_quad (0, $h - $border, $w, $border);
908 908
909 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
909 my $bg = $tex[0]; 910 my $bg = $tex[0];
910 911
911 # TODO: repeat texture not scale 912 # TODO: repeat texture not scale
912 my $rep_x = $cw / $bg->{w}; 913 my $rep_x = $cw / $bg->{w};
913 my $rep_y = $ch / $bg->{h}; 914 my $rep_y = $ch / $bg->{h};
914 915
915 glColor @{ $self->{bg} }; 916 glColor @{ $self->{bg} };
916 917
917 $bg->{s} = $rep_x; 918 $bg->{s} = $rep_x;
918 $bg->{t} = $rep_y; 919 $bg->{t} = $rep_y;
919 $bg->{wrap_mode} = 1; 920 $bg->{wrap_mode} = 1;
920 $bg->draw_quad ($border, $border, $cw, $ch); 921 $bg->draw_quad ($border, $border, $cw, $ch);
921 922
922 glDisable GL_TEXTURE_2D; 923 glDisable GL_TEXTURE_2D;
923 glDisable GL_BLEND; 924 glDisable GL_BLEND;
925 }
924 926
925 $self->{title}->draw if $self->{title}; 927 $self->{title}->draw if $self->{title};
928
926 $self->child->draw; 929 $self->child->draw;
927} 930}
928 931
929############################################################################# 932#############################################################################
930 933
2404sub draw { 2407sub draw {
2405 my ($self) = @_; 2408 my ($self) = @_;
2406 2409
2407 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2410 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2408 2411
2412 # TODO animation
2409 if ($tex) { 2413 if ($tex) {
2410 glEnable GL_BLEND; 2414 glEnable GL_BLEND;
2411 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2415 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2412 glEnable GL_TEXTURE_2D; 2416 glEnable GL_TEXTURE_2D;
2413 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2417 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2418 } 2422 }
2419} 2423}
2420 2424
2421############################################################################# 2425#############################################################################
2422 2426
2427package CFClient::UI::Menu;
2428
2429our @ISA = CFClient::UI::FancyFrame::;
2430
2431use CFClient::OpenGL;
2432
2433sub new {
2434 my $class = shift;
2435
2436 my $self = $class->SUPER::new (
2437 items => [],
2438 z => 100,
2439 @_,
2440 );
2441
2442 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2443
2444 for my $item (@{ $self->{items} }) {
2445 my ($widget, $cb) = @$item;
2446
2447 # handle various types of items, only text for now
2448 if (!ref $widget) {
2449 $widget = new CFClient::UI::Label
2450 can_hover => 1,
2451 can_events => 1,
2452 text => $widget;
2453 }
2454
2455 $self->{item}{$widget} = $item;
2456
2457 $self->{vbox}->add ($widget);
2458 }
2459
2460 $self
2461}
2462
2463# popup given the event (must be a mouse button down event currently)
2464sub popup {
2465 my ($self, $ev) = @_;
2466
2467 $self->emit ("popdown");
2468
2469 # maybe save $GRAB? must be careful about events...
2470 $GRAB = $self;
2471 $self->{button} = $ev->{button};
2472
2473 $self->show;
2474 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2475}
2476
2477sub mouse_motion {
2478 my ($self, $ev, $x, $y) = @_;
2479
2480 # TODO: should use vbox->fdind_widget or so
2481 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2482 $self->{hover} = $self->{item}{$HOVER};
2483}
2484
2485sub button_up {
2486 my ($self, $ev, $x, $y) = @_;
2487
2488 if ($ev->{button} == $self->{button}) {
2489 undef $GRAB;
2490 $self->hide;
2491
2492 $self->emit ("popdown");
2493 $self->{hover}[1]->() if $self->{hover};
2494 }
2495}
2496
2497#############################################################################
2498
2423package CFClient::UI::Root; 2499package CFClient::UI::Root;
2424 2500
2425our @ISA = CFClient::UI::Container::; 2501our @ISA = CFClient::UI::Container::;
2426 2502
2427use CFClient::OpenGL; 2503use CFClient::OpenGL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines