Games-Construder
view release on metacpan or search on metacpan
lib/Games/Construder/Client/UI.pm view on Meta::CPAN
$pos->[1] += ($isize->[1] - $size->[1]) / 2;
} elsif ($_->[1]->{align} eq 'right') {
$pos->[1] += $isize->[1] - $size->[1];
}
$self->draw_element ($_, $pos);
$x += $size->[0];
}
}
} elsif ($type eq 'text') {
$self->draw_text ($offs, $attr->{layout}, $attr->{color});
} elsif ($type eq 'entry') {
if ($self->{active_element} eq $el) {
$self->draw_box (
$offs, $attr->{size},
($self->{anim_state} ? $attr->{highlight}->[0] : $attr->{highlight}->[1]));
}
$self->draw_text ($offs, $attr->{layout}, $attr->{color});
} elsif ($type eq 'multiline') {
if ($self->{active_element} eq $el) {
if ($attr->{active_input}) {
$self->draw_box ($offs, $attr->{size}, $attr->{highlight}->[2]);
} else {
$self->draw_box ($offs, $attr->{size}, $attr->{highlight}->[1]);
}
} else {
$self->draw_box ($offs, $attr->{size}, $attr->{highlight}->[0]);
}
$self->draw_text ($offs, $attr->{layout}, $attr->{color});
} elsif ($type eq 'range') {
if ($self->{active_element} eq $el) {
$self->draw_box (
$offs, $attr->{size},
($self->{anim_state} ? $attr->{highlight}->[0] : $attr->{highlight}->[1]));
}
$self->draw_text ($offs, $attr->{layout}, $attr->{color});
} elsif ($type eq 'model') {
push @{$self->{models}}, [$offs, $attr->{size}, $childs[0], $attr->{animated}];
}
}
sub element_font {
my ($el) = @_;
my $font = $el->[1]->{font};
$font eq 'big' ? $BIG_FONT : $font eq 'small' ? $SMALL_FONT : $NORM_FONT;
}
sub fit_size_pot {
my ($size) = @_;
my $gls = 1;
$gls++ while $size->[0] > (2**$gls) || $size->[1] > (2**$gls);
2**$gls
}
sub update {
my ($self, $gui_desc) = @_;
if (defined $gui_desc) {
delete $self->{key_repeat};
$self->{desc} = $gui_desc;
}
my $win = $self->{desc}->{window};
$self->{element_offset} = 0;
$self->{relative_extents} = [];
$self->{commands} = $self->{desc}->{commands};
$self->{command_cb} = $self->{desc}->{command_cb};
$self->{sticky} = $win->{sticky};
$self->{models} = [];
$self->{entries} = [];
if ($gui_desc && $gui_desc->{layout}) {
$self->{layout} = decode_json (encode_json ($gui_desc->{layout}));
}
my $layout = $self->{layout};
$self->{active_elements} = [];
my $size;
$size = $self->setup_sizes ($layout);
$self->{layout} = $layout;
$self->{window_size} = $size;
$self->{window_pos} = $self->window_position ($win->{pos}, $size);
$self->{opengl_texture_size} = fit_size_pot ($size);
unless (grep {
$self->{active_element} eq $_
} @{$self->{active_elements}}
) {
$self->{active_element} = $self->{active_elements}->[0];
}
$self->prepare_opengl_texture;
# window_size_inside is initialized here, and window_padding too
$self->prepare_sdl_surface ($win->{bgcolor}, $size); # creates a new sdl surface for this window
ctr_prof ("draw elements", sub {
$self->draw_element ($layout, [0, 0]);
});
ctr_prof ("render_view", sub {
$self->render_view; # refresh rendering to opengl texture
});
}
sub active {
my ($self, $act) = @_;
$self->{active} = $act;
delete $self->{key_repeat};
}
( run in 1.009 second using v1.01-cache-2.11-cpan-39bf76dae61 )