… | |
… | |
450 | my ($self, $ev, $x, $y) = @_; |
450 | my ($self, $ev, $x, $y) = @_; |
451 | |
451 | |
452 | $self->focus_in; |
452 | $self->focus_in; |
453 | } |
453 | } |
454 | |
454 | |
455 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
|
|
456 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
|
|
457 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
|
|
458 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
|
|
459 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
|
|
460 | |
|
|
461 | sub find_widget { |
455 | sub find_widget { |
462 | my ($self, $x, $y) = @_; |
456 | my ($self, $x, $y) = @_; |
463 | |
457 | |
464 | return () unless $self->{can_events}; |
458 | return () unless $self->{can_events}; |
465 | |
459 | |
… | |
… | |
526 | |
520 | |
527 | $self->realloc; |
521 | $self->realloc; |
528 | $self->update; |
522 | $self->update; |
529 | } |
523 | } |
530 | |
524 | |
|
|
525 | # using global variables seems a bit hacky, but passing through all drawing |
|
|
526 | # functions seems pointless. |
|
|
527 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
|
|
528 | |
531 | sub draw { |
529 | sub draw { |
532 | my ($self) = @_; |
530 | my ($self) = @_; |
533 | |
531 | |
534 | return unless $self->{h} && $self->{w}; |
532 | return unless $self->{h} && $self->{w}; |
|
|
533 | |
|
|
534 | local $draw_x = $draw_x + $self->{x}; |
|
|
535 | local $draw_y = $draw_y + $self->{y}; |
|
|
536 | |
|
|
537 | return if $draw_x + $self->{w} < 0; |
|
|
538 | return if $draw_x >= $draw_w; |
|
|
539 | return if $draw_y + $self->{h} < 0; |
|
|
540 | return if $draw_y >= $draw_h; |
535 | |
541 | |
536 | glPushMatrix; |
542 | glPushMatrix; |
537 | glTranslate $self->{x}, $self->{y}, 0; |
543 | glTranslate $self->{x}, $self->{y}, 0; |
538 | $self->_draw; |
544 | $self->_draw; |
539 | glPopMatrix; |
545 | glPopMatrix; |
… | |
… | |
804 | $self->SUPER::size_allocate ($w, $h); |
810 | $self->SUPER::size_allocate ($w, $h); |
805 | $self->update; |
811 | $self->update; |
806 | } |
812 | } |
807 | |
813 | |
808 | sub _render { |
814 | sub _render { |
|
|
815 | my ($self) = @_; |
|
|
816 | |
809 | $_[0]{children}[0]->draw; |
817 | $self->{children}[0]->draw; |
810 | } |
818 | } |
811 | |
819 | |
812 | sub render_child { |
820 | sub render_child { |
813 | my ($self) = @_; |
821 | my ($self) = @_; |
814 | |
822 | |
815 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
823 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
816 | glClearColor 0, 0, 0, 0; |
824 | glClearColor 0, 0, 0, 0; |
817 | glClear GL_COLOR_BUFFER_BIT; |
825 | glClear GL_COLOR_BUFFER_BIT; |
818 | |
826 | |
|
|
827 | { |
|
|
828 | package CFClient::UI::Base; |
|
|
829 | |
|
|
830 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
831 | (0, 0, $self->{w}, $self->{h}); |
|
|
832 | } |
|
|
833 | |
819 | $self->_render; |
834 | $self->_render; |
820 | }; |
835 | }; |
821 | } |
836 | } |
822 | |
837 | |
823 | sub _draw { |
838 | sub _draw { |
824 | my ($self) = @_; |
839 | my ($self) = @_; |
825 | |
840 | |
826 | my ($w, $h) = ($self->w, $self->h); |
841 | my ($w, $h) = @$self{qw(w h)}; |
827 | |
842 | |
828 | my $tex = $self->{texture} |
843 | my $tex = $self->{texture} |
829 | or return; |
844 | or return; |
830 | |
845 | |
831 | glEnable GL_TEXTURE_2D; |
846 | glEnable GL_TEXTURE_2D; |
… | |
… | |
913 | } |
928 | } |
914 | } |
929 | } |
915 | |
930 | |
916 | sub _render { |
931 | sub _render { |
917 | my ($self) = @_; |
932 | my ($self) = @_; |
|
|
933 | |
|
|
934 | local $CFClient::UI::Base::draw_x = $CFClient::UI::Base::draw_x - $self->{view_x}; |
|
|
935 | local $CFClient::UI::Base::draw_y = $CFClient::UI::Base::draw_y - $self->{view_y}; |
918 | |
936 | |
919 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
937 | CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y}; |
920 | |
938 | |
921 | $self->SUPER::_render; |
939 | $self->SUPER::_render; |
922 | } |
940 | } |
… | |
… | |
3471 | glLoadIdentity; |
3489 | glLoadIdentity; |
3472 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3490 | glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000; |
3473 | glMatrixMode GL_MODELVIEW; |
3491 | glMatrixMode GL_MODELVIEW; |
3474 | glLoadIdentity; |
3492 | glLoadIdentity; |
3475 | |
3493 | |
|
|
3494 | { |
|
|
3495 | package CFClient::UI::Base; |
|
|
3496 | |
|
|
3497 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
|
|
3498 | (0, 0, $self->{w}, $self->{h}); |
|
|
3499 | } |
|
|
3500 | |
3476 | $self->_draw; |
3501 | $self->_draw; |
3477 | } |
3502 | } |
3478 | |
3503 | |
3479 | ############################################################################# |
3504 | ############################################################################# |
3480 | |
3505 | |