xlib_playground

Xlib playground for experiments.
Log | Files | Refs

commit 816b14c55ca8ae15c60c1f00f7284dc8e38bc273
parent ea937ad07b4b0b0d6ec2263d79e253f31a625d19
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue, 10 Jan 2023 10:48:44 +0900

Disable drawing outside the screen.

Diffstat:
Mex9/main.c | 12+++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/ex9/main.c b/ex9/main.c @@ -260,7 +260,6 @@ game_play(void) #endif x_clear_area(); - // TODO: disable drawing outside of window. for (olc = ol; olc != NULL; olc = olc->next) { draw_object_scroll((struct Object *)olc->item, scroll_dst); } @@ -460,10 +459,13 @@ void draw_object_scroll(const struct Object *o, int sd) { if (o->shape == SRECTANGLE) { - x_draw_rectangle(o->color, - o->p.x - sd, o->p.y, - o->body.rectangle.w, - o->body.rectangle.h); + if (sd - o->body.rectangle.w <= o->p.x && + o->p.x < WIN_WIDTH + sd) { + x_draw_rectangle(o->color, + o->p.x - sd, o->p.y, + o->body.rectangle.w, + o->body.rectangle.h); + } } else { fprintf(stderr, "draw_object_scroll: Drawing object other than" "rectangle is not implemented yet.\n");