… | |
… | |
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 |
… | |
… | |
3618 | } |
3631 | } |
3619 | |
3632 | |
3620 | sub _draw { |
3633 | sub _draw { |
3621 | my ($self) = @_; |
3634 | my ($self) = @_; |
3622 | |
3635 | |
3623 | glTranslate 0.375, 0.375; |
|
|
3624 | |
|
|
3625 | my ($w, $h) = @$self{qw(w h)}; |
3636 | my ($w, $h) = @$self{qw(w h)}; |
3626 | |
3637 | |
3627 | glColor 1, 0.8, 0.4; |
3638 | glColor 1, 0.8, 0.4; |
3628 | glRect 0, 0, $w, $h; |
3639 | glRect 0, 0, $w, $h; |
3629 | |
3640 | |
3630 | glColor 0, 0, 0; |
3641 | glColor 0, 0, 0; |
3631 | glRect_lineloop 0, 0, $w, $h; |
3642 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3632 | |
3643 | |
3633 | glTranslate 2 - 0.375, 2 - 0.375; |
3644 | glTranslate 2, 2; |
3634 | |
3645 | |
3635 | $self->SUPER::_draw; |
3646 | $self->SUPER::_draw; |
3636 | } |
3647 | } |
3637 | |
3648 | |
3638 | ############################################################################# |
3649 | ############################################################################# |
… | |
… | |
3965 | my $class = shift; |
3976 | my $class = shift; |
3966 | |
3977 | |
3967 | my $self = $class->SUPER::new ( |
3978 | my $self = $class->SUPER::new ( |
3968 | buttonbar => (new CFPlus::UI::Buttonbar), |
3979 | buttonbar => (new CFPlus::UI::Buttonbar), |
3969 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3980 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3970 | active_outline => [1, 1, 0], |
3981 | active_outline => [.7, .7, 0.2], |
3971 | # filter => # will be put between multiplexer and $self |
3982 | # filter => # will be put between multiplexer and $self |
3972 | @_, |
3983 | @_, |
3973 | ); |
3984 | ); |
3974 | |
3985 | |
3975 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3986 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
4056 | |
4067 | |
4057 | $self->SUPER::_draw (); |
4068 | $self->SUPER::_draw (); |
4058 | |
4069 | |
4059 | if (my $cur = $self->{multiplexer}{current}) { |
4070 | if (my $cur = $self->{multiplexer}{current}) { |
4060 | if ($cur = $cur->{c_tab_}) { |
4071 | if ($cur = $cur->{c_tab_}) { |
4061 | glTranslate $cur->{x}, $cur->{y}; |
4072 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4073 | $self->{buttonbar}{y} + $cur->{y}; |
4062 | glLineWidth 3; |
4074 | glLineWidth 3; |
|
|
4075 | #glEnable GL_BLEND; |
|
|
4076 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
4063 | glColor @{$self->{active_outline}}; |
4077 | glColor @{$self->{active_outline}}; |
4064 | 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; |
4065 | glLineWidth 1; |
4079 | glLineWidth 1; |
|
|
4080 | #glDisable GL_BLEND; |
4066 | } |
4081 | } |
4067 | } |
4082 | } |
4068 | } |
4083 | } |
4069 | |
4084 | |
4070 | ############################################################################# |
4085 | ############################################################################# |