… | |
… | |
269 | $self->emit ("destroy"); |
269 | $self->emit ("destroy"); |
270 | %$self = (); |
270 | %$self = (); |
271 | } |
271 | } |
272 | |
272 | |
273 | sub TO_JSON { |
273 | sub TO_JSON { |
274 | { __w_ => $_[0]{s_id} } |
274 | { "\fw" => $_[0]{s_id} } |
275 | } |
275 | } |
276 | |
276 | |
277 | sub show { |
277 | sub show { |
278 | my ($self) = @_; |
278 | my ($self) = @_; |
279 | |
279 | |
… | |
… | |
358 | |
358 | |
359 | $self->{force_w} = $w; |
359 | $self->{force_w} = $w; |
360 | $self->{force_h} = $h; |
360 | $self->{force_h} = $h; |
361 | |
361 | |
362 | $self->realloc; |
362 | $self->realloc; |
|
|
363 | } |
|
|
364 | |
|
|
365 | # travsle the widget chain up to find the maximum "physical" size constraints |
|
|
366 | sub get_max_wh { |
|
|
367 | my ($self) = @_; |
|
|
368 | |
|
|
369 | return ($self->{alloc_w}, $self->{alloc_h}) |
|
|
370 | if $self->{alloc_w} && !$self->{root}{realloc}{$self+0}; |
|
|
371 | |
|
|
372 | return $self->{parent}->get_max_wh |
|
|
373 | if $self->{parent}; |
|
|
374 | |
|
|
375 | ($::WIDTH, $::HEIGHT) |
363 | } |
376 | } |
364 | |
377 | |
365 | sub size_request { |
378 | sub size_request { |
366 | require Carp; |
379 | require Carp; |
367 | Carp::confess "size_request is abstract"; |
380 | Carp::confess "size_request is abstract"; |
… | |
… | |
817 | |
830 | |
818 | 1 |
831 | 1 |
819 | } |
832 | } |
820 | |
833 | |
821 | ############################################################################# |
834 | ############################################################################# |
822 | |
|
|
823 | # back-buffered drawing area |
835 | # back-buffered drawing area |
824 | |
836 | |
825 | package CFPlus::UI::Window; |
837 | package CFPlus::UI::Window; |
826 | |
838 | |
827 | our @ISA = CFPlus::UI::Bin::; |
839 | our @ISA = CFPlus::UI::Bin::; |
… | |
… | |
1942 | |
1954 | |
1943 | sub size_request { |
1955 | sub size_request { |
1944 | my ($self) = @_; |
1956 | my ($self) = @_; |
1945 | |
1957 | |
1946 | $self->{size_req} ||= do { |
1958 | $self->{size_req} ||= do { |
|
|
1959 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1960 | |
1947 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1961 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1948 | $self->{layout}->set_width ($self->{max_w} || -1); |
1962 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1949 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1963 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1950 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1964 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1951 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1965 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1952 | |
1966 | |
1953 | my ($w, $h) = $self->{layout}->size; |
1967 | my ($w, $h) = $self->{layout}->size; |
… | |
… | |
2233 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2247 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2234 | } |
2248 | } |
2235 | |
2249 | |
2236 | glColor_premultiply @{$self->{active_fg}}; |
2250 | glColor_premultiply @{$self->{active_fg}}; |
2237 | glBegin GL_LINES; |
2251 | glBegin GL_LINES; |
2238 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2252 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy}; |
2239 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2253 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2240 | glEnd; |
2254 | glEnd; |
2241 | |
2255 | |
2242 | glLineWidth 3; |
2256 | glLineWidth 3; |
2243 | glColor @{$self->{active_outline}}; |
2257 | glColor @{$self->{active_outline}}; |
2244 | glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; |
2258 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2245 | glLineWidth 1; |
2259 | glLineWidth 1; |
2246 | |
2260 | |
2247 | } else { |
2261 | } else { |
2248 | glColor @{$self->{outline}}; |
2262 | glColor @{$self->{outline}}; |
2249 | glTranslate .375, .375; |
|
|
2250 | glBegin GL_LINE_STRIP; |
2263 | glBegin GL_LINE_STRIP; |
2251 | glVertex 0, $self->{h} * .5; |
2264 | glVertex .5, $self->{h} * .5; |
2252 | glVertex 0, $self->{h} - 3; |
2265 | glVertex .5, $self->{h} - 2.5; |
2253 | glVertex $self->{w} - 1, $self->{h} - 3; |
2266 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2254 | glVertex $self->{w} - 1, $self->{h} * .5; |
2267 | glVertex $self->{w} - .5, $self->{h} * .5; |
2255 | glEnd; |
2268 | glEnd; |
2256 | } |
2269 | } |
2257 | } |
2270 | } |
2258 | |
2271 | |
2259 | ############################################################################# |
2272 | ############################################################################# |
… | |
… | |
2508 | sub _draw { |
2521 | sub _draw { |
2509 | my ($self) = @_; |
2522 | my ($self) = @_; |
2510 | |
2523 | |
2511 | $self->SUPER::_draw; |
2524 | $self->SUPER::_draw; |
2512 | |
2525 | |
2513 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2526 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2514 | |
2527 | |
2515 | my ($w, $h) = @$self{qw(w h)}; |
2528 | my ($w, $h) = @$self{qw(w h)}; |
2516 | |
2529 | |
2517 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2530 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2518 | |
2531 | |
… | |
… | |
2837 | |
2850 | |
2838 | glEnable GL_BLEND; |
2851 | glEnable GL_BLEND; |
2839 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2852 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2840 | |
2853 | |
2841 | if ($self->{value} >= 0) { |
2854 | if ($self->{value} >= 0) { |
2842 | my $s = 3 + ($self->{w} - 6) * $self->{value}; |
2855 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
2843 | |
2856 | |
2844 | glColor_premultiply @{$self->{bar}}; |
2857 | glColor_premultiply @{$self->{bar}}; |
2845 | glRect 2, 2, $s, $self->{h} - 2; |
2858 | glRect 2, 2, $s, $self->{h} - 2; |
2846 | glColor_premultiply @{$self->{bg}}; |
2859 | glColor_premultiply @{$self->{bg}}; |
2847 | glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; |
2860 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
2848 | } |
2861 | } |
2849 | |
2862 | |
2850 | glColor_premultiply @{$self->{outline}}; |
2863 | glColor_premultiply @{$self->{outline}}; |
2851 | glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; |
2864 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2852 | |
2865 | |
2853 | glDisable GL_BLEND; |
2866 | glDisable GL_BLEND; |
2854 | |
2867 | |
2855 | { |
2868 | { |
2856 | local $self->{bg}; # do not draw background |
2869 | local $self->{bg}; # do not draw background |
… | |
… | |
2896 | } |
2909 | } |
2897 | |
2910 | |
2898 | sub set_value { |
2911 | sub set_value { |
2899 | my ($self, $lvl, $exp) = @_; |
2912 | my ($self, $lvl, $exp) = @_; |
2900 | |
2913 | |
2901 | <<<<<<< UI.pm |
|
|
2902 | $self->{lvl} = $lvl; |
2914 | $self->{lvl} = $lvl; |
2903 | $self->{exp} = $exp; |
2915 | $self->{exp} = $exp; |
2904 | |
2916 | |
2905 | ======= |
|
|
2906 | $self->{lvl} = $exp; |
|
|
2907 | $self->{exp} = $exp; |
|
|
2908 | |
|
|
2909 | >>>>>>> 1.434 |
|
|
2910 | my $v = -1; |
2917 | my $v = -1; |
2911 | |
2918 | |
2912 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
2919 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
2913 | my $l0 = $table->[$lvl - 1]; |
2920 | my $l0 = $table->[$lvl - 1]; |
2914 | my $l1 = $table->[$lvl]; |
2921 | my $l1 = $table->[$lvl]; |
… | |
… | |
3624 | } |
3631 | } |
3625 | |
3632 | |
3626 | sub _draw { |
3633 | sub _draw { |
3627 | my ($self) = @_; |
3634 | my ($self) = @_; |
3628 | |
3635 | |
3629 | glTranslate 0.375, 0.375; |
|
|
3630 | |
|
|
3631 | my ($w, $h) = @$self{qw(w h)}; |
3636 | my ($w, $h) = @$self{qw(w h)}; |
3632 | |
3637 | |
3633 | glColor 1, 0.8, 0.4; |
3638 | glColor 1, 0.8, 0.4; |
3634 | glRect 0, 0, $w, $h; |
3639 | glRect 0, 0, $w, $h; |
3635 | |
3640 | |
3636 | glColor 0, 0, 0; |
3641 | glColor 0, 0, 0; |
3637 | glRect_lineloop 0, 0, $w, $h; |
3642 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3638 | |
3643 | |
3639 | glTranslate 2 - 0.375, 2 - 0.375; |
3644 | glTranslate 2, 2; |
3640 | |
3645 | |
3641 | $self->SUPER::_draw; |
3646 | $self->SUPER::_draw; |
3642 | } |
3647 | } |
3643 | |
3648 | |
3644 | ############################################################################# |
3649 | ############################################################################# |
… | |
… | |
3971 | my $class = shift; |
3976 | my $class = shift; |
3972 | |
3977 | |
3973 | my $self = $class->SUPER::new ( |
3978 | my $self = $class->SUPER::new ( |
3974 | buttonbar => (new CFPlus::UI::Buttonbar), |
3979 | buttonbar => (new CFPlus::UI::Buttonbar), |
3975 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3980 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3976 | active_outline => [1, 1, 0], |
3981 | active_outline => [.7, .7, 0.2], |
3977 | # filter => # will be put between multiplexer and $self |
3982 | # filter => # will be put between multiplexer and $self |
3978 | @_, |
3983 | @_, |
3979 | ); |
3984 | ); |
3980 | |
3985 | |
3981 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3986 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
4062 | |
4067 | |
4063 | $self->SUPER::_draw (); |
4068 | $self->SUPER::_draw (); |
4064 | |
4069 | |
4065 | if (my $cur = $self->{multiplexer}{current}) { |
4070 | if (my $cur = $self->{multiplexer}{current}) { |
4066 | if ($cur = $cur->{c_tab_}) { |
4071 | if ($cur = $cur->{c_tab_}) { |
4067 | glTranslate $cur->{x}, $cur->{y}; |
4072 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4073 | $self->{buttonbar}{y} + $cur->{y}; |
4068 | glLineWidth 3; |
4074 | glLineWidth 3; |
|
|
4075 | #glEnable GL_BLEND; |
|
|
4076 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
4069 | glColor @{$self->{active_outline}}; |
4077 | glColor @{$self->{active_outline}}; |
4070 | glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; |
4078 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
4071 | glLineWidth 1; |
4079 | glLineWidth 1; |
|
|
4080 | #glDisable GL_BLEND; |
4072 | } |
4081 | } |
4073 | } |
4082 | } |
4074 | } |
4083 | } |
4075 | |
4084 | |
4076 | ############################################################################# |
4085 | ############################################################################# |