… | |
… | |
2074 | my $class = shift; |
2074 | my $class = shift; |
2075 | |
2075 | |
2076 | $class->SUPER::new ( |
2076 | $class->SUPER::new ( |
2077 | fg => [1, 1, 1], |
2077 | fg => [1, 1, 1], |
2078 | bg => [0, 0, 0, 0.2], |
2078 | bg => [0, 0, 0, 0.2], |
2079 | active_bg => [1, 1, 1, 0.5], |
2079 | active_bg => [0, 0, 1, .2], |
2080 | active_fg => [0, 0, 0], |
2080 | active_fg => [1, 1, 1], |
|
|
2081 | active_outline => [1, 1, 0], |
2081 | can_hover => 1, |
2082 | can_hover => 1, |
2082 | can_focus => 1, |
2083 | can_focus => 1, |
2083 | valign => 0, |
2084 | valign => 0, |
2084 | can_events => 1, |
2085 | can_events => 1, |
2085 | ellipsise => 0, |
2086 | ellipsise => 0, |
… | |
… | |
2242 | |
2243 | |
2243 | unless (exists $self->{cur_h}) { |
2244 | unless (exists $self->{cur_h}) { |
2244 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2245 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2245 | utf8::encode $text; |
2246 | utf8::encode $text; |
2246 | |
2247 | |
2247 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2248 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2248 | } |
2249 | } |
2249 | |
2250 | |
|
|
2251 | glColor_premultiply @{$self->{active_fg}}; |
2250 | glBegin GL_LINES; |
2252 | glBegin GL_LINES; |
2251 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2253 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2252 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2254 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2253 | glEnd; |
2255 | glEnd; |
|
|
2256 | |
|
|
2257 | glLineWidth 3; |
|
|
2258 | glColor @{$self->{active_outline}}; |
|
|
2259 | glTranslate -.375, -.375; |
|
|
2260 | glBegin GL_LINE_LOOP; |
|
|
2261 | glVertex 0, 0; |
|
|
2262 | glVertex $self->{w}, 0; |
|
|
2263 | glVertex $self->{w}, $self->{h}; |
|
|
2264 | glVertex 0, $self->{h}; |
|
|
2265 | glEnd; |
|
|
2266 | glLineWidth 1; |
2254 | } |
2267 | } |
2255 | } |
2268 | } |
2256 | |
2269 | |
2257 | ############################################################################# |
2270 | ############################################################################# |
2258 | |
2271 | |
… | |
… | |
2344 | 1 |
2357 | 1 |
2345 | } |
2358 | } |
2346 | |
2359 | |
2347 | ############################################################################# |
2360 | ############################################################################# |
2348 | |
2361 | |
|
|
2362 | package CFPlus::UI::ButtonBin; |
|
|
2363 | |
|
|
2364 | our @ISA = CFPlus::UI::Bin::; |
|
|
2365 | |
|
|
2366 | use CFPlus::OpenGL; |
|
|
2367 | |
|
|
2368 | my @tex = |
|
|
2369 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2370 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2371 | |
|
|
2372 | sub new { |
|
|
2373 | my $class = shift; |
|
|
2374 | |
|
|
2375 | $class->SUPER::new ( |
|
|
2376 | can_hover => 1, |
|
|
2377 | align => 0, |
|
|
2378 | valign => 0, |
|
|
2379 | can_events => 1, |
|
|
2380 | @_ |
|
|
2381 | ) |
|
|
2382 | } |
|
|
2383 | |
|
|
2384 | sub invoke_button_up { |
|
|
2385 | my ($self, $ev, $x, $y) = @_; |
|
|
2386 | |
|
|
2387 | $self->emit ("activate") |
|
|
2388 | if $x >= 0 && $x < $self->{w} |
|
|
2389 | && $y >= 0 && $y < $self->{h}; |
|
|
2390 | |
|
|
2391 | 1 |
|
|
2392 | } |
|
|
2393 | |
|
|
2394 | sub _draw { |
|
|
2395 | my ($self) = @_; |
|
|
2396 | |
|
|
2397 | glEnable GL_TEXTURE_2D; |
|
|
2398 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2399 | glColor 0, 0, 0, 1; |
|
|
2400 | |
|
|
2401 | my $tex = $tex[$GRAB == $self]; |
|
|
2402 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2403 | |
|
|
2404 | glDisable GL_TEXTURE_2D; |
|
|
2405 | |
|
|
2406 | $self->SUPER::_draw; |
|
|
2407 | } |
|
|
2408 | |
|
|
2409 | ############################################################################# |
|
|
2410 | |
2349 | package CFPlus::UI::Button; |
2411 | package CFPlus::UI::Button; |
2350 | |
2412 | |
2351 | our @ISA = CFPlus::UI::Label::; |
2413 | our @ISA = CFPlus::UI::Label::; |
2352 | |
2414 | |
2353 | use CFPlus::OpenGL; |
2415 | use CFPlus::OpenGL; |
… | |
… | |
2487 | sub new { |
2549 | sub new { |
2488 | my $class = shift; |
2550 | my $class = shift; |
2489 | |
2551 | |
2490 | my $self = $class->SUPER::new ( |
2552 | my $self = $class->SUPER::new ( |
2491 | can_events => 0, |
2553 | can_events => 0, |
|
|
2554 | scale => 1, |
2492 | @_, |
2555 | @_, |
2493 | ); |
2556 | ); |
2494 | |
2557 | |
2495 | $self->{path} || $self->{tex} |
2558 | $self->{path} || $self->{tex} |
2496 | or Carp::croak "'path' or 'tex' attributes required"; |
2559 | or Carp::croak "'path' or 'tex' attributes required"; |
… | |
… | |
2521 | } |
2584 | } |
2522 | |
2585 | |
2523 | sub size_request { |
2586 | sub size_request { |
2524 | my ($self) = @_; |
2587 | my ($self) = @_; |
2525 | |
2588 | |
2526 | ($self->{tex}{w}, $self->{tex}{h}) |
2589 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2527 | } |
2590 | } |
2528 | |
2591 | |
2529 | sub _draw { |
2592 | sub _draw { |
2530 | my ($self) = @_; |
2593 | my ($self) = @_; |
2531 | |
2594 | |
… | |
… | |
2541 | } |
2604 | } |
2542 | |
2605 | |
2543 | glEnable GL_TEXTURE_2D; |
2606 | glEnable GL_TEXTURE_2D; |
2544 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2607 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2545 | |
2608 | |
2546 | $tex->draw_quad (0, 0, $w, $h); |
2609 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2547 | |
2610 | |
2548 | glDisable GL_TEXTURE_2D; |
2611 | glDisable GL_TEXTURE_2D; |
2549 | } |
2612 | } |
2550 | |
2613 | |
2551 | ############################################################################# |
2614 | ############################################################################# |
… | |
… | |
3622 | children => [ |
3685 | children => [ |
3623 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3686 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3624 | (new CFPlus::UI::Label markup => $right, align => +1), |
3687 | (new CFPlus::UI::Label markup => $right, align => +1), |
3625 | ], |
3688 | ], |
3626 | ; |
3689 | ; |
3627 | |
3690 | |
3628 | } else { |
3691 | } else { |
3629 | $widget = new CFPlus::UI::Label |
3692 | $widget = new CFPlus::UI::Label |
3630 | can_hover => 1, |
3693 | can_hover => 1, |
3631 | can_events => 1, |
3694 | can_events => 1, |
3632 | markup => $widget, |
3695 | markup => $widget, |