From 12e7804d9f459ac53205c90a1e4f171720636b86 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Fri, 17 Jan 2025 10:57:41 +0900 Subject: [PATCH] AGS: Use SDL drawing functions --- src/sys/ags_draw.cpp | 24 ++++++++--------- src/sys/ags_window.cpp | 59 ++++++++++++++---------------------------- 2 files changed, 30 insertions(+), 53 deletions(-) diff --git a/src/sys/ags_draw.cpp b/src/sys/ags_draw.cpp index b7b9ba1..25cff4c 100644 --- a/src/sys/ags_draw.cpp +++ b/src/sys/ags_draw.cpp @@ -189,11 +189,8 @@ void AGS::draw_mesh(int sx, int sy, int width, int height) void AGS::box_fill(int dest, int sx, int sy, int ex, int ey, uint8 color) { - for(int y = sy; y <= ey && y < 480; y++) { - for(int x = sx; x <= ex && x < 640; x++) { - vram[dest][y][x] = color; - } - } + SDL_Rect rect = {sx, sy, ex - sx + 1, ey - sy + 1}; + SDL_FillRect(hBmpScreen[dest], &rect, color); if(dest == 0) { draw_screen(sx, sy, ex - sx + 1, ey - sy + 1); } @@ -201,14 +198,15 @@ void AGS::box_fill(int dest, int sx, int sy, int ex, int ey, uint8 color) void AGS::box_line(int dest, int sx, int sy, int ex, int ey, uint8 color) { - for(int x = sx; x <= ex && x < 640; x++) { - vram[dest][sy][x] = color; - vram[dest][ey][x] = color; - } - for(int y = sy; y <= ey && y < 480; y++) { - vram[dest][y][sx] = color; - vram[dest][y][ex] = color; - } + SDL_Rect top = {sx, sy, ex - sx + 1, 1}; + SDL_Rect bottom = {sx, ey, ex - sx + 1, 1}; + SDL_Rect left = {sx, sy, 1, ey - sy + 1}; + SDL_Rect right = {ex, sy, 1, ey - sy + 1}; + + SDL_FillRect(hBmpScreen[dest], &top, color); + SDL_FillRect(hBmpScreen[dest], &bottom, color); + SDL_FillRect(hBmpScreen[dest], &left, color); + SDL_FillRect(hBmpScreen[dest], &right, color); if(dest == 0) { draw_screen(sx, sy, ex - sx + 1, ey - sy + 1); } diff --git a/src/sys/ags_window.cpp b/src/sys/ags_window.cpp index 6b21779..1b7494c 100644 --- a/src/sys/ags_window.cpp +++ b/src/sys/ags_window.cpp @@ -174,8 +174,8 @@ void AGS::close_text_window(int index, bool update) void AGS::clear_menu_window() { - // TODO: use draw function - memset(hBmpScreen[2]->pixels, menu_back_color, 640 * 480); + SDL_Rect rect = {0, 0, 640, 480}; + SDL_FillRect(hBmpScreen[2], &rect, menu_back_color); } void AGS::open_menu_window(int index) @@ -211,11 +211,9 @@ void AGS::open_menu_window(int index) // メニュー表示 draw_window(wsx, wsy, wex, wey, menu_w[index - 1].frame, menu_frame_color, menu_back_color); - for(int y = 0; y < height && y + sy < 480; y++) { - for(int x = 0; x < width && x + sx < 640; x++) { - vram[0][y + sy][x + sx] = vram[2][y][x]; - } - } + SDL_Rect src_rect = {0, 0, width, height}; + SDL_Rect dst_rect = {sx, sy, width, height}; + SDL_BlitSurface(hBmpScreen[2], &src_rect, hBmpScreen[0], &dst_rect); box_line(0, sx, sy, ex, sy + menu_font_size + 3, menu_frame_color); draw_screen(wsx, wsy, wwidth, wheight); } @@ -229,11 +227,9 @@ void AGS::redraw_menu_window(int index, int selected) int width = ex - sx + 1; int height = ey - sy + 1; - for(int y = 0; y < height && y + sy < 480; y++) { - for(int x = 0; x < width && x + sx < 640; x++) { - vram[0][y + sy][x + sx] = vram[2][y][x]; - } - } + SDL_Rect src_rect = {0, 0, width, height}; + SDL_Rect dst_rect = {sx, sy, width, height}; + SDL_BlitSurface(hBmpScreen[2], &src_rect, hBmpScreen[0], &dst_rect); box_line(0, sx, sy + (menu_font_size + 4) * selected, ex, sy + (menu_font_size + 4) * (selected + 1) - 1, menu_frame_color); draw_screen(sx, sy, width, height); } @@ -259,36 +255,19 @@ void AGS::close_menu_window(int index) void AGS::draw_window(int sx, int sy, int ex, int ey, bool frame, uint8 frame_color, uint8 back_color) { - // 領域の塗り潰し - for(int y = sy; y <= ey && y < 480; y++) { - uint8_t* dest = vram[0][y]; - for(int x = sx; x <= ex && x < 640; x++) { - dest[x] = back_color; - } - } + SDL_Rect rect = {sx, sy, ex - sx + 1, ey - sy + 1}; + SDL_FillRect(hBmpScreen[0], &rect, back_color); - // 枠表示 if(frame) { - for(int x = sx + 1; x <= ex - 1; x++) { - vram[0][sy + 1][x] = frame_color; - vram[0][sy + 2][x] = frame_color; - vram[0][ey - 2][x] = frame_color; - vram[0][ey - 1][x] = frame_color; - } - for(int y = sy + 1; y <= ey - 1; y++) { - vram[0][y][sx + 1] = frame_color; - vram[0][y][sx + 2] = frame_color; - vram[0][y][ex - 2] = frame_color; - vram[0][y][ex - 1] = frame_color; - } - for(int x = sx + 4; x <= ex - 4; x++) { - vram[0][sy + 4][x] = frame_color; - vram[0][ey - 4][x] = frame_color; - } - for(int y = sy + 4; y <= ey - 4; y++) { - vram[0][y][sx + 4] = frame_color; - vram[0][y][ex - 4] = frame_color; - } + SDL_Rect top = {sx + 1, sy + 1, ex - sx - 1, 2}; + SDL_Rect bottom = {sx + 1, ey - 2, ex - sx - 1, 2}; + SDL_Rect left = {sx + 1, sy + 1, 2, ey - sy - 1}; + SDL_Rect right = {ex - 2, sy + 1, 2, ey - sy - 1}; + SDL_FillRect(hBmpScreen[0], &top, frame_color); + SDL_FillRect(hBmpScreen[0], &bottom, frame_color); + SDL_FillRect(hBmpScreen[0], &left, frame_color); + SDL_FillRect(hBmpScreen[0], &right, frame_color); + box_line(0, sx + 4, sy + 4, ex - 4, ey - 4, frame_color); } draw_screen(sx, sy, ex - sx + 1, ey - sy + 1); }