--- deliantra/Deliantra-Client/DC/UI.pm 2007/07/23 18:13:33 1.415 +++ deliantra/Deliantra-Client/DC/UI.pm 2007/08/21 00:59:34 1.429 @@ -275,7 +275,7 @@ } sub TO_JSON { - { __widget_ref__ => $_[0]{s_id} } + { __w_ => $_[0]{s_id} } } sub show { @@ -1029,8 +1029,8 @@ my $self; my $hslider = new CFPlus::UI::Slider - col => 0, - row => 1, + c_col => 0, + c_row => 1, vertical => 0, range => [0, 0, 1, 0.01], # HACK fix on_changed => sub { @@ -1040,8 +1040,8 @@ ; my $vslider = new CFPlus::UI::Slider - col => 1, - row => 0, + c_col => 1, + c_row => 0, vertical => 1, range => [0, 0, 1, 0.01], # HACK fix on_changed => sub { @@ -1062,8 +1062,8 @@ ); $self->{vp} = new CFPlus::UI::ViewPort - col => 0, - row => 0, + c_col => 0, + c_row => 0, expand => 1, scroll_x => $self->{scroll_x}, scroll_y => $self->{scroll_y}, @@ -1600,8 +1600,8 @@ my ($self, @widgets) = @_; for my $child (@widgets) { - $child->{rowspan} ||= 1; - $child->{colspan} ||= 1; + $child->{c_rowspan} ||= 1; + $child->{c_colspan} ||= 1; } $self->SUPER::add (@widgets); @@ -1615,8 +1615,8 @@ while (@_) { my ($col, $row, $child) = splice @_, 0, 3, (); - $child->{row} = $row; - $child->{col} = $col; + $child->{c_row} = $row; + $child->{c_col} = $col; push @widgets, $child; } @@ -1632,8 +1632,8 @@ my @children = $self->children; # first pass, columns - for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { - my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; + for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) { + my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; my $sw = sum @w[$c .. $c + $cs - 1]; @@ -1643,8 +1643,8 @@ } # second pass, rows - for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { - my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; + for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { + my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; my $sh = sum @h[$r .. $r + $rs - 1]; @@ -1696,7 +1696,7 @@ my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } for my $widget ($self->children) { - my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; + my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)}; $widget->configure ( $x[$c], $y[$r], @@ -1925,6 +1925,12 @@ $self->SUPER::realloc; } +sub clear { + my ($self) = @_; + + $self->set_text (""); +} + sub set_text { my ($self, $text) = @_; @@ -2040,6 +2046,8 @@ $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} : ($self->{h} - $size->[1]) * 0.5); + + $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); }; # unless ($self->{list}) { @@ -2051,7 +2059,7 @@ # # CFPlus::OpenGL::glCallList $self->{list}; - $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); + $self->{layout}->draw; } #sub destroy { @@ -2076,8 +2084,10 @@ $class->SUPER::new ( fg => [1, 1, 1], bg => [0, 0, 0, 0.2], - active_bg => [1, 1, 1, 0.5], - active_fg => [0, 0, 0], + outline => [0.6, 0.3, 0.1], + active_bg => [0, 0, 1, .2], + active_fg => [1, 1, 1], + active_outline => [1, 1, 0], can_hover => 1, can_focus => 1, valign => 0, @@ -2244,13 +2254,34 @@ my $text = substr $self->{text}, 0, $self->{cursor}; utf8::encode $text; - @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) + @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); } + glColor_premultiply @{$self->{active_fg}}; glBegin GL_LINES; glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; glEnd; + + glLineWidth 3; + glColor @{$self->{active_outline}}; + glBegin GL_LINE_LOOP; + glVertex 0, 0; + glVertex $self->{w} - 1, 0; + glVertex $self->{w} - 1, $self->{h} - 1; + glVertex 0, $self->{h} - 1; + glEnd; + glLineWidth 1; + + } else { + glColor @{$self->{outline}}; + glTranslate .375, .375; + glBegin GL_LINE_STRIP; + glVertex 0, $self->{h} * .5; + glVertex 0, $self->{h} - 3; + glVertex $self->{w} - 1, $self->{h} - 3; + glVertex $self->{w} - 1, $self->{h} * .5; + glEnd; } } @@ -2346,6 +2377,55 @@ ############################################################################# +package CFPlus::UI::ButtonBin; + +our @ISA = CFPlus::UI::Bin::; + +use CFPlus::OpenGL; + +my @tex = + map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } + qw(b1_button_inactive.png b1_button_active.png); + +sub new { + my $class = shift; + + $class->SUPER::new ( + can_hover => 1, + align => 0, + valign => 0, + can_events => 1, + @_ + ) +} + +sub invoke_button_up { + my ($self, $ev, $x, $y) = @_; + + $self->emit ("activate") + if $x >= 0 && $x < $self->{w} + && $y >= 0 && $y < $self->{h}; + + 1 +} + +sub _draw { + my ($self) = @_; + + glEnable GL_TEXTURE_2D; + glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; + glColor 0, 0, 0, 1; + + my $tex = $tex[$GRAB == $self]; + $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); + + glDisable GL_TEXTURE_2D; + + $self->SUPER::_draw; +} + +############################################################################# + package CFPlus::UI::Button; our @ISA = CFPlus::UI::Label::; @@ -2489,6 +2569,7 @@ my $self = $class->SUPER::new ( can_events => 0, + scale => 1, @_, ); @@ -2523,7 +2604,7 @@ sub size_request { my ($self) = @_; - ($self->{tex}{w}, $self->{tex}{h}) + (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) } sub _draw { @@ -2543,7 +2624,7 @@ glEnable GL_TEXTURE_2D; glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; - $tex->draw_quad (0, 0, $w, $h); + $tex->draw_quad_alpha (0, 0, $w, $h); glDisable GL_TEXTURE_2D; } @@ -2574,6 +2655,12 @@ ); } +sub invoke_button_down { + my ($self, $ev, $x, $y) = @_; + + 1 +} + sub invoke_button_up { my ($self, $ev, $x, $y) = @_; @@ -3227,6 +3314,7 @@ my $layout = $self->get_layout ($para); $layout->render ($para->{indent}, $y - $y0); + $layout->draw; if (my @w = @{ $para->{widget} }) { my @s = $layout->get_shapes; @@ -3427,12 +3515,7 @@ my ($w, $h) = @$self{qw(w h)}; glColor 1, 0.8, 0.4; - glBegin GL_QUADS; - glVertex 0 , 0; - glVertex 0 , $h; - glVertex $w, $h; - glVertex $w, 0; - glEnd; + glRect 0, 0, $w, $h; glColor 0, 0, 0; glBegin GL_LINE_LOOP; @@ -3474,13 +3557,17 @@ $self->{timer} = Event->timer ( parked => 1, cb => sub { - return unless $::CONN && $widget; + return unless $::CONN; - ++$widget->{frame}; - $widget->update_face; - $widget->update; + my $w = $widget + or return; - $widget->update_timer; + ++$w->{frame}; + $w->update_face; + + # somehow, $widget can go away + $w->update; + $w->update_timer; }, ); @@ -3511,13 +3598,18 @@ sub update_face { my ($self) = @_; - return unless $::CONN; - - if (my $anim = $::CONN->{anim}[$self->{anim}]) { - if ($anim && @$anim) { - delete $self->{wait_face}; - $self->{face} = $anim->[ $self->{frame} % @$anim ]; - $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; + if ($::CONN) { + if (my $anim = $::CONN->{anim}[$self->{anim}]) { + if ($anim && @$anim) { + $self->{face} = $anim->[ $self->{frame} % @$anim ]; + delete $self->{face_change_cb}; + + if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { + unless ($tex->{name} || $tex->{loading}) { + $tex->upload (sub { $self->reconfigure }); + } + } + } } } } @@ -3526,15 +3618,16 @@ my ($self) = @_; if ($::CONN) { - if (my $faceid = $::CONN->{faceid}[$self->{face}]) { - if (my $tex = $::CONN->{texture}[$faceid]) { - $self->{tex} = $tex; - return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); - } else { - $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { - $self->realloc; - }); + if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { + if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { + if ($tex->{name}) { + return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); + } elsif (!$tex->{loading}) { + $tex->upload (sub { $self->reconfigure }); + } } + + $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); } } @@ -3624,7 +3717,7 @@ (new CFPlus::UI::Label markup => $right, align => +1), ], ; - + } else { $widget = new CFPlus::UI::Label can_hover => 1, @@ -4127,7 +4220,7 @@ sub update { my ($self) = @_; - $::WANT_REFRESH++; + $::WANT_REFRESH->start; } sub add {