… | |
… | |
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 | outline => [0.6, 0.3, 0.1], |
2079 | active_bg => [0, 0, 1, .2], |
2080 | active_bg => [0, 0, 1, .2], |
2080 | active_fg => [1, 1, 1], |
2081 | active_fg => [1, 1, 1], |
2081 | active_outline => [1, 1, 0], |
2082 | active_outline => [1, 1, 0], |
2082 | can_hover => 1, |
2083 | can_hover => 1, |
2083 | can_focus => 1, |
2084 | can_focus => 1, |
… | |
… | |
2254 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2255 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2255 | glEnd; |
2256 | glEnd; |
2256 | |
2257 | |
2257 | glLineWidth 3; |
2258 | glLineWidth 3; |
2258 | glColor @{$self->{active_outline}}; |
2259 | glColor @{$self->{active_outline}}; |
2259 | glTranslate -.375, -.375; |
|
|
2260 | glBegin GL_LINE_LOOP; |
2260 | glBegin GL_LINE_LOOP; |
2261 | glVertex 0, 0; |
2261 | glVertex 0, 0; |
2262 | glVertex $self->{w}, 0; |
2262 | glVertex $self->{w} - 1, 0; |
2263 | glVertex $self->{w}, $self->{h}; |
2263 | glVertex $self->{w} - 1, $self->{h} - 1; |
2264 | glVertex 0, $self->{h}; |
2264 | glVertex 0, $self->{h} - 1; |
2265 | glEnd; |
2265 | glEnd; |
2266 | glLineWidth 1; |
2266 | glLineWidth 1; |
|
|
2267 | |
|
|
2268 | } else { |
|
|
2269 | glColor @{$self->{outline}}; |
|
|
2270 | glTranslate .375, .375; |
|
|
2271 | glBegin GL_LINE_STRIP; |
|
|
2272 | glVertex 0, $self->{h} * .5; |
|
|
2273 | glVertex 0, $self->{h} - 3; |
|
|
2274 | glVertex $self->{w} - 1, $self->{h} - 3; |
|
|
2275 | glVertex $self->{w} - 1, $self->{h} * .5; |
|
|
2276 | glEnd; |
2267 | } |
2277 | } |
2268 | } |
2278 | } |
2269 | |
2279 | |
2270 | ############################################################################# |
2280 | ############################################################################# |
2271 | |
2281 | |
… | |
… | |
2357 | 1 |
2367 | 1 |
2358 | } |
2368 | } |
2359 | |
2369 | |
2360 | ############################################################################# |
2370 | ############################################################################# |
2361 | |
2371 | |
|
|
2372 | package CFPlus::UI::ButtonBin; |
|
|
2373 | |
|
|
2374 | our @ISA = CFPlus::UI::Bin::; |
|
|
2375 | |
|
|
2376 | use CFPlus::OpenGL; |
|
|
2377 | |
|
|
2378 | my @tex = |
|
|
2379 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2380 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2381 | |
|
|
2382 | sub new { |
|
|
2383 | my $class = shift; |
|
|
2384 | |
|
|
2385 | $class->SUPER::new ( |
|
|
2386 | can_hover => 1, |
|
|
2387 | align => 0, |
|
|
2388 | valign => 0, |
|
|
2389 | can_events => 1, |
|
|
2390 | @_ |
|
|
2391 | ) |
|
|
2392 | } |
|
|
2393 | |
|
|
2394 | sub invoke_button_up { |
|
|
2395 | my ($self, $ev, $x, $y) = @_; |
|
|
2396 | |
|
|
2397 | $self->emit ("activate") |
|
|
2398 | if $x >= 0 && $x < $self->{w} |
|
|
2399 | && $y >= 0 && $y < $self->{h}; |
|
|
2400 | |
|
|
2401 | 1 |
|
|
2402 | } |
|
|
2403 | |
|
|
2404 | sub _draw { |
|
|
2405 | my ($self) = @_; |
|
|
2406 | |
|
|
2407 | glEnable GL_TEXTURE_2D; |
|
|
2408 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2409 | glColor 0, 0, 0, 1; |
|
|
2410 | |
|
|
2411 | my $tex = $tex[$GRAB == $self]; |
|
|
2412 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2413 | |
|
|
2414 | glDisable GL_TEXTURE_2D; |
|
|
2415 | |
|
|
2416 | $self->SUPER::_draw; |
|
|
2417 | } |
|
|
2418 | |
|
|
2419 | ############################################################################# |
|
|
2420 | |
2362 | package CFPlus::UI::Button; |
2421 | package CFPlus::UI::Button; |
2363 | |
2422 | |
2364 | our @ISA = CFPlus::UI::Label::; |
2423 | our @ISA = CFPlus::UI::Label::; |
2365 | |
2424 | |
2366 | use CFPlus::OpenGL; |
2425 | use CFPlus::OpenGL; |
… | |
… | |
2500 | sub new { |
2559 | sub new { |
2501 | my $class = shift; |
2560 | my $class = shift; |
2502 | |
2561 | |
2503 | my $self = $class->SUPER::new ( |
2562 | my $self = $class->SUPER::new ( |
2504 | can_events => 0, |
2563 | can_events => 0, |
|
|
2564 | scale => 1, |
2505 | @_, |
2565 | @_, |
2506 | ); |
2566 | ); |
2507 | |
2567 | |
2508 | $self->{path} || $self->{tex} |
2568 | $self->{path} || $self->{tex} |
2509 | or Carp::croak "'path' or 'tex' attributes required"; |
2569 | or Carp::croak "'path' or 'tex' attributes required"; |
… | |
… | |
2534 | } |
2594 | } |
2535 | |
2595 | |
2536 | sub size_request { |
2596 | sub size_request { |
2537 | my ($self) = @_; |
2597 | my ($self) = @_; |
2538 | |
2598 | |
2539 | ($self->{tex}{w}, $self->{tex}{h}) |
2599 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2540 | } |
2600 | } |
2541 | |
2601 | |
2542 | sub _draw { |
2602 | sub _draw { |
2543 | my ($self) = @_; |
2603 | my ($self) = @_; |
2544 | |
2604 | |
… | |
… | |
2554 | } |
2614 | } |
2555 | |
2615 | |
2556 | glEnable GL_TEXTURE_2D; |
2616 | glEnable GL_TEXTURE_2D; |
2557 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2617 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2558 | |
2618 | |
2559 | $tex->draw_quad (0, 0, $w, $h); |
2619 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2560 | |
2620 | |
2561 | glDisable GL_TEXTURE_2D; |
2621 | glDisable GL_TEXTURE_2D; |
2562 | } |
2622 | } |
2563 | |
2623 | |
2564 | ############################################################################# |
2624 | ############################################################################# |
… | |
… | |
3438 | glTranslate 0.375, 0.375; |
3498 | glTranslate 0.375, 0.375; |
3439 | |
3499 | |
3440 | my ($w, $h) = @$self{qw(w h)}; |
3500 | my ($w, $h) = @$self{qw(w h)}; |
3441 | |
3501 | |
3442 | glColor 1, 0.8, 0.4; |
3502 | glColor 1, 0.8, 0.4; |
3443 | glBegin GL_QUADS; |
3503 | glRect 0, 0, $w, $h; |
3444 | glVertex 0 , 0; |
|
|
3445 | glVertex 0 , $h; |
|
|
3446 | glVertex $w, $h; |
|
|
3447 | glVertex $w, 0; |
|
|
3448 | glEnd; |
|
|
3449 | |
3504 | |
3450 | glColor 0, 0, 0; |
3505 | glColor 0, 0, 0; |
3451 | glBegin GL_LINE_LOOP; |
3506 | glBegin GL_LINE_LOOP; |
3452 | glVertex 0 , 0; |
3507 | glVertex 0 , 0; |
3453 | glVertex 0 , $h; |
3508 | glVertex 0 , $h; |
… | |
… | |
3635 | children => [ |
3690 | children => [ |
3636 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3691 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3637 | (new CFPlus::UI::Label markup => $right, align => +1), |
3692 | (new CFPlus::UI::Label markup => $right, align => +1), |
3638 | ], |
3693 | ], |
3639 | ; |
3694 | ; |
3640 | |
3695 | |
3641 | } else { |
3696 | } else { |
3642 | $widget = new CFPlus::UI::Label |
3697 | $widget = new CFPlus::UI::Label |
3643 | can_hover => 1, |
3698 | can_hover => 1, |
3644 | can_events => 1, |
3699 | can_events => 1, |
3645 | markup => $widget, |
3700 | markup => $widget, |