… | |
… | |
171 | sub rescale_widgets { |
171 | sub rescale_widgets { |
172 | my ($sx, $sy) = @_; |
172 | my ($sx, $sy) = @_; |
173 | |
173 | |
174 | for my $widget (values %WIDGET) { |
174 | for my $widget (values %WIDGET) { |
175 | if ($widget->{is_toplevel}) { |
175 | if ($widget->{is_toplevel}) { |
176 | $widget->{x} += $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
176 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
177 | $widget->{y} += $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
177 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
178 | |
178 | |
179 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
179 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
180 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
180 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
181 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
181 | $widget->{force_w} = int 0.5 + $widget->{force_w} * $sx if exists $widget->{force_w}; |
182 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
182 | $widget->{y} = int 0.5 + $widget->{y} * $sy if $widget->{y} =~ /^[0-9.]+$/; |
183 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
183 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
184 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
184 | $widget->{force_h} = int 0.5 + $widget->{force_h} * $sy if exists $widget->{force_h}; |
185 | |
185 | |
186 | $widget->{x} -= $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
186 | $widget->{x} -= int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
187 | $widget->{y} -= $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
187 | $widget->{y} -= int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
188 | |
188 | |
189 | } |
189 | } |
190 | } |
190 | } |
191 | |
191 | |
192 | reconfigure_widgets; |
192 | reconfigure_widgets; |
… | |
… | |
529 | sub draw { |
529 | sub draw { |
530 | my ($self) = @_; |
530 | my ($self) = @_; |
531 | |
531 | |
532 | return unless $self->{h} && $self->{w}; |
532 | return unless $self->{h} && $self->{w}; |
533 | |
533 | |
|
|
534 | # update screen rectangle |
534 | local $draw_x = $draw_x + $self->{x}; |
535 | local $draw_x = $draw_x + $self->{x}; |
535 | local $draw_y = $draw_y + $self->{y}; |
536 | local $draw_y = $draw_y + $self->{y}; |
|
|
537 | local $draw_w = $draw_x + $self->{w}; |
|
|
538 | local $draw_h = $draw_y + $self->{h}; |
536 | |
539 | |
537 | return if $draw_x + $self->{w} < 0; |
540 | # skip widgets that are entirely outside the drawing area |
538 | return if $draw_x >= $draw_w; |
541 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
539 | return if $draw_y + $self->{h} < 0; |
542 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
540 | return if $draw_y >= $draw_h; |
|
|
541 | |
543 | |
542 | glPushMatrix; |
544 | glPushMatrix; |
543 | glTranslate $self->{x}, $self->{y}, 0; |
545 | glTranslate $self->{x}, $self->{y}, 0; |
544 | $self->_draw; |
546 | $self->_draw; |
545 | glPopMatrix; |
547 | glPopMatrix; |