aboutsummaryrefslogtreecommitdiff
path: root/libgui
diff options
context:
space:
mode:
authorMarvin Borner2020-08-23 23:02:32 +0200
committerMarvin Borner2020-08-23 23:02:32 +0200
commita1ab3aac9cd9f03a421ff1681c0da3487097deae (patch)
treeab2b322a121e6fed371b96fadc1bdbaeaabd6ee3 /libgui
parentc2cccf6f2ef4f6f8c828074e68be2d95255a89b5 (diff)
Some window buffer switching
Diffstat (limited to 'libgui')
-rw-r--r--libgui/gui.c66
-rw-r--r--libgui/inc/gui.h10
2 files changed, 46 insertions, 30 deletions
diff --git a/libgui/gui.c b/libgui/gui.c
index 3b918e7..cfc33b3 100644
--- a/libgui/gui.c
+++ b/libgui/gui.c
@@ -40,51 +40,65 @@ void gui_write(struct vbe *vbe, int x, int y, const u32 c[3], char *text)
}
}
-void gui_load_wallpaper(struct vbe *vbe, char *path)
+void gui_load_image(struct window *win, char *path, int x, int y)
{
struct bmp *bmp = bmp_load(path);
- assert(bmp);
+ assert(bmp && bmp->width + x <= win->width);
+ assert(bmp && bmp->height + y <= win->height);
+ // TODO: Support padding with odd widths
+ u8 *srcfb = bmp->data;
+ u8 *destfb = win->fb;
int bpl = bmp->bpp >> 3;
- int x1 = 0;
- int x2 = bmp->width;
- int y1 = 0;
- int y2 = bmp->height;
+ for (u32 cy = 0; cy <= bmp->height; cy++) {
+ for (u32 cx = 0; cx <= bmp->width; cx++) {
+ destfb[bpl * cx + 0] = srcfb[bpl * cx + 0];
+ destfb[bpl * cx + 1] = srcfb[bpl * cx + 1];
+ destfb[bpl * cx + 2] = srcfb[bpl * cx + 2];
+ }
+ srcfb += bmp->pitch;
+ destfb += win->pitch;
+ }
+}
- // TODO: Support padding with odd widths
- /* int pitch = bmp->width * bpl; */
- /* int padding = 1; */
- /* while ((pitch + padding) % 4 != 0) */
- /* padding++; */
- /* int psw = pitch + padding; */
+void gui_load_wallpaper(struct window *win, char *path)
+{
+ gui_load_image(win, path, 0, 0);
+}
- int pos1 = x1 * bpl + y1 * vbe->pitch;
- u8 *draw = &vbe->fb[pos1];
- u8 *data = bmp->data;
- for (int i = 0; i <= y2 - y1; i++) {
- for (int j = 0; j <= x2 - x1; j++) {
- draw[bpl * j] = data[bpl * j];
- draw[bpl * j + 1] = data[bpl * j + 1];
- draw[bpl * j + 2] = data[bpl * j + 2];
+void gui_win_on_win(struct window *src, struct window *dest, int x, int y)
+{
+ // TODO: x, y image coords
+ (void)x;
+ (void)y;
+
+ u8 *srcfb = src->fb;
+ u8 *destfb = dest->fb;
+ int bpl = dest->bpp >> 3;
+ for (u32 cy = 0; cy <= src->height; cy++) {
+ for (u32 cx = 0; cx <= src->width; cx++) {
+ destfb[bpl * cx + 0] = srcfb[bpl * cx + 0];
+ destfb[bpl * cx + 1] = srcfb[bpl * cx + 1];
+ destfb[bpl * cx + 2] = srcfb[bpl * cx + 2];
}
- draw += vbe->pitch;
- data += bmp->pitch;
+ srcfb += src->pitch;
+ destfb += dest->pitch;
}
}
void gui_draw_rectangle(struct window *win, int x1, int y1, int x2, int y2, const u32 color[3])
{
- int bpl = win->vbe->bpp >> 3;
+ int bpl = win->bpp >> 3;
- int pos1 = x1 * bpl + y1 * win->vbe->pitch;
+ int pos1 = x1 * bpl + y1 * win->pitch;
u8 *draw = &win->fb[pos1];
for (int i = 0; i <= y2 - y1; i++) {
for (int j = 0; j <= x2 - x1; j++) {
- draw[bpl * j] = color[2];
+ draw[bpl * j + 0] = color[2];
draw[bpl * j + 1] = color[1];
draw[bpl * j + 2] = color[0];
}
- draw += win->vbe->pitch;
+ draw += win->pitch;
}
}
diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h
index 467496a..ccd4bd9 100644
--- a/libgui/inc/gui.h
+++ b/libgui/inc/gui.h
@@ -19,15 +19,17 @@ struct font {
struct window {
int x;
int y;
- u16 width;
- u16 height;
- struct vbe *vbe;
+ u32 width;
+ u32 height;
u8 *fb;
+ u32 bpp;
+ u32 pitch;
};
+void gui_load_wallpaper(struct window *win, char *path);
+void gui_win_on_win(struct window *src, struct window *dest, int x, int y);
void gui_draw_rectangle(struct window *win, int x1, int y1, int x2, int y2, const u32 color[3]);
void gui_fill(struct window *win, const u32 color[3]);
-void gui_load_wallpaper(struct vbe *vbe, char *path);
void gui_init(char *font_path);
/**