diff options
-rw-r--r-- | lib/libgfx/include/libgfx/draw.h | 16 | ||||
-rw-r--r-- | lib/libgfx/src/draw.c | 40 | ||||
-rw-r--r-- | lib/liboda/include/liboda/oda.h | 17 | ||||
-rw-r--r-- | lib/liboda/src/window.c | 56 |
4 files changed, 129 insertions, 0 deletions
diff --git a/lib/libgfx/include/libgfx/draw.h b/lib/libgfx/include/libgfx/draw.h index 96fe35a..8efd986 100644 --- a/lib/libgfx/include/libgfx/draw.h +++ b/lib/libgfx/include/libgfx/draw.h @@ -101,8 +101,24 @@ struct gfx_point { color_t rgb; }; +/* + * Represents a rectangular region on + * the screen. + * + * @x,y: Position of this region on the screen + * @width: Region width + * @heght: Region height + */ +struct gfx_region { + scrpos_t x, y; + dimm_t width; + dimm_t height; +}; + int gfx_draw_shape(struct gfx_ctx *ctx, const struct gfx_shape *shape); int gfx_plot_point(struct gfx_ctx *ctx, const struct gfx_point *point); + +int gfx_copy_region(struct gfx_ctx *ctx, struct gfx_region *r, scrpos_t x, scrpos_t y); color_t gfx_get_pix(struct gfx_ctx *ctx, uint32_t x, uint32_t y); __always_inline static inline size_t diff --git a/lib/libgfx/src/draw.c b/lib/libgfx/src/draw.c index 784110a..43e0f08 100644 --- a/lib/libgfx/src/draw.c +++ b/lib/libgfx/src/draw.c @@ -182,3 +182,43 @@ gfx_draw_shape(struct gfx_ctx *ctx, const struct gfx_shape *shape) return -1; } + +/* + * Copy a region on one part of a screen to + * another part of a screen. + * + * @ctx: Graphics context pointer + * @r: Region to copy + * @x: X position for copy dest + * @y: Y position for copy dest + */ +int +gfx_copy_region(struct gfx_ctx *ctx, struct gfx_region *r, scrpos_t x, scrpos_t y) +{ + struct gfx_point point; + color_t pixel; + scrpos_t src_cx, src_cy; + dimm_t w, h; + + if (ctx == NULL || r == NULL) { + return -EINVAL; + } + + w = r->width; + h = r->height; + + for (int xoff = 0; xoff < w; ++xoff) { + for (int yoff = 0; yoff < h; ++yoff) { + /* Source position */ + src_cx = r->x + xoff; + src_cy = r->y + yoff; + + /* Plot the new pixel */ + pixel = gfx_get_pix(ctx, src_cx, src_cy); + point.x = x + xoff; + point.y = y + yoff; + point.rgb = pixel; + gfx_plot_point(ctx, &point); + } + } +} diff --git a/lib/liboda/include/liboda/oda.h b/lib/liboda/include/liboda/oda.h index 13474d5..9d96f2f 100644 --- a/lib/liboda/include/liboda/oda.h +++ b/lib/liboda/include/liboda/oda.h @@ -83,6 +83,22 @@ struct oda_wattr { }; /* + * Arguments for oda_movewin() are stored + * within this structure to minimize the + * number of arguments within the function + * signature. + * + * @wp: Window to be moved + * @to_x: X position to move window to + * @to_y: Y position to move window to + */ +struct oda_movewin { + struct oda_window *wp; + odapos_t to_x; + odapos_t to_y; +}; + +/* * A pixel point that can be plotted * onto a window. * @@ -103,6 +119,7 @@ int oda_reqwin(struct oda_wattr *params, struct oda_window **res); int oda_termwin(struct oda_state *state, struct oda_window *win); int oda_plotwin(struct oda_state *state, const struct oda_point *point); +int oda_movewin(struct oda_state *state, struct oda_movewin *params); int oda_start_win(struct oda_state *state, struct oda_window *win); int oda_init(struct oda_state *res); diff --git a/lib/liboda/src/window.c b/lib/liboda/src/window.c index 8e91fac..216b106 100644 --- a/lib/liboda/src/window.c +++ b/lib/liboda/src/window.c @@ -35,6 +35,7 @@ #include <liboda/odavar.h> #include <liboda/types.h> #include <libgfx/gfx.h> +#include <libgfx/draw.h> /* * The window cache is used to reduce how many @@ -341,6 +342,61 @@ oda_reqwin(struct oda_wattr *params, struct oda_window **res) } /* + * Move a window to a new position on the + * screen. + * + * @state: ODA state pointer + * @params: Arguments to this function + */ +int +oda_movewin(struct oda_state *state, struct oda_movewin *params) +{ + struct oda_window *win; + struct gfx_shape *wsurf; + struct gfx_region r; + odadimm_t w, h; + odapos_t x, y, x_f, y_f; + odapos_t to_x, to_y; + uint32_t i = 0; + int error; + + /* Make sure arguments are valid */ + if (state == NULL || params == NULL) { + return -EINVAL; + } + + /* We need the window */ + if ((win = params->wp) == NULL) { + return -EINVAL; + } + + /* Verify state cookie */ + if ((error = oda_cookie_verify(state)) != 0) { + return error; + } + + wsurf = &win->surface; + to_x = params->to_x; + to_y = params->to_y; + + r.x = wsurf->x; + r.y = wsurf->y; + r.width = wsurf->width; + r.height = wsurf->height; + + /* + * We will copy the window to the new location and + * fill where the old window was with GFX_BLACK. + * + * TODO: Handle overlapping of windows + */ + gfx_copy_region(&state->gctx, &r, to_x, to_y); + wsurf->x = to_x; + wsurf->y = to_y; + return 0; +} + +/* * Register a window into the current ODA state. * Everytime a compositor requests a window, we * must keep track of it. |