Enabling the close box button.

This commit is contained in:
Sergiotarxz 2024-03-08 23:42:14 +01:00
parent 77cc606473
commit 7987b5c828
1 changed files with 35 additions and 1 deletions

View File

@ -32,6 +32,10 @@ has _save => (
required => 1,
);
has _win => (
is => 'rw',
);
has _current_box => ( is => 'rw', );
my $BOX_X = 275;
@ -43,6 +47,7 @@ my $ARROW_X = 28;
my $ARROW_Y = 6;
my $ARROW_WIDTH = 16;
my $ARROW_HEIGHT = 32;
my ($CLOSE_BOX_X, $CLOSE_BOX_Y, $CLOSE_BOX_WIDTH, $CLOSE_BOX_HEIGHT) = (420, 0, 180, 40);
has _cursor_position => ( is => 'rw' );
@ -51,6 +56,7 @@ my $root = path(__FILE__)->parent->parent->parent->parent;
sub start {
my $self = shift;
my $gtk_window = Gtk4::Window->new;
$self->_win($gtk_window);
my $controller_motion = Gtk4::EventControllerMotion->new;
my $controller_gesture = Gtk4::GestureClick->new;
my $save = $self->_save;
@ -97,6 +103,7 @@ sub start {
$cairo->paint;
}
$self->draw_pokemon_details( $cairo, $selected_pokemon );
$self->draw_not_implemented($cairo);
$self->draw_cursor($cairo);
}
);
@ -111,10 +118,37 @@ sub start {
);
}
sub draw_not_implemented {
my $self = shift;
my $cairo = shift;
$cairo->rectangle(200, 0, 180, 40);
$cairo->set_source_rgb(0, 0, 0);
$cairo->fill;
$cairo->set_source_rgb(1, 1, 1);
$cairo->set_font_size(20);
$cairo->move_to( 200, 30);
$cairo->text_path("Not implemented");
$cairo->fill;
}
sub _on_primary_click {
my $self = shift;
my ( $gesture, $n_press, $x, $y ) = @_;
return if $self->_check_click_next_prev_box( $gesture, $n_press, $x, $y );
return if $self->_check_click_close_box($gesture, $n_press, $x, $y);
}
sub _check_click_close_box {
my $self = shift;
my ( $gesture, $n_press, $x, $y ) = @_;
my $match_x = $x >= $CLOSE_BOX_X && $x <= $CLOSE_BOX_WIDTH + $CLOSE_BOX_X;
my $match_y = $y >= $CLOSE_BOX_Y && $y <= $CLOSE_BOX_HEIGHT + $CLOSE_BOX_Y;
if ($match_x && $match_y) {
$self->_win->close;
return 1;
}
return;
}
sub _check_click_next_prev_box {
@ -211,7 +245,7 @@ sub draw_pokemon_details {
$cairo->move_to( 18, 138 );
$cairo->text_path("Lv@{[$selected_pokemon->level]}");
$cairo->set_source_rgb( 1, 1, 1 );
$cairo->fill_preserve;
$cairo->fill;
$cairo->scale( ( 1 / $scale_factor ) x 2 );