From 39b304c265b9b4b6c6afa49832aec954926009ad Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 19 Sep 2024 08:59:37 +0200 Subject: [PATCH] =?UTF-8?q?-=20Editor=20de=20posici=C3=B3=20i=20tamany=20d?= =?UTF-8?q?e=20actor=20en=20bitmap=20completat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/m_editor_bitmap.cpp | 53 +++++++++++++++++++++++++++++++++----- source/m_game.cpp | 8 ++++-- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/source/m_editor_bitmap.cpp b/source/m_editor_bitmap.cpp index 71118c6..e4d4f80 100644 --- a/source/m_editor_bitmap.cpp +++ b/source/m_editor_bitmap.cpp @@ -12,6 +12,8 @@ namespace modules { int edit_mode = EDITING_BITMAP_POS; draw::surface *surf = nullptr; + int lastMX, lastMY; + bool lastMB = false; void init(int editing) { @@ -23,16 +25,47 @@ namespace modules bool loop() { if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false; + const bool ctrl = input::keyDown(SDL_SCANCODE_LCTRL); + actor::actor_t *sel = actor::getSelected(); + + if (input::keyDown(SDL_SCANCODE_UP)) if (!ctrl) sel->bmp_rect.y--; else sel->bmp_rect.h--; + if (input::keyDown(SDL_SCANCODE_DOWN)) if (!ctrl) sel->bmp_rect.y++; else sel->bmp_rect.h++; + if (input::keyDown(SDL_SCANCODE_LEFT)) if (!ctrl) sel->bmp_rect.x--; else sel->bmp_rect.w--; + if (input::keyDown(SDL_SCANCODE_RIGHT)) if (!ctrl) sel->bmp_rect.x++; else sel->bmp_rect.w++; + + if (input::mouseBtn(1)) + { + int mx = input::mouseX(); + int my = input::mouseY(); + if (!lastMB) { + lastMB = true; + lastMX = mx; + lastMY = my; + } else { + int dx = 0, dy = 0; + if (lastMX != mx) { dx = mx - lastMX; } + if (lastMY != my) { dy = my - lastMY; } + lastMX = mx; + lastMY = my; + if (!ctrl) { + sel->bmp_rect.x += dx; + sel->bmp_rect.y += dy; + } else { + sel->bmp_rect.w += dx; + sel->bmp_rect.h += dy; + } + } + } const int tx = (520-surf->w)/2; const int ty = (240-surf->h)/2; draw::cls(PAPER); draw::setSource(surf); - draw::color(BLUE); + draw::color(100); draw::setViewport(tx, ty, surf->w, surf->h); draw::fillrect(0, 0, surf->w, surf->h); - draw::color(BLUE+LIGHT); + draw::color(101); int x=0, y=0; while(y*32h) { @@ -41,19 +74,25 @@ namespace modules } draw::resetViewport(); - draw::color(WHITE); + draw::color(LIGHT+WHITE); draw::rect(((520-surf->w)/2)-1, ((240-surf->h)/2)-1, surf->w+2, surf->h+2); + draw::swapcol(1, LIGHT+WHITE); draw::draw((520-surf->w)/2, (240-surf->h)/2, surf->w, surf->h, 0, 0, 0); draw::setViewport(tx, ty, surf->w, surf->h); draw::color(RED+LIGHT); - draw::hline(0, actor::getSelected()->bmp_rect.y, surf->w); - draw::vline(actor::getSelected()->bmp_rect.x, 0, surf->h); + draw::hline(0, sel->bmp_rect.y, surf->w); + draw::vline(sel->bmp_rect.x, 0, surf->h); draw::color(YELLOW); - draw::hline(0, actor::getSelected()->bmp_rect.y+actor::getSelected()->bmp_rect.h, surf->w); - draw::vline(actor::getSelected()->bmp_rect.x+actor::getSelected()->bmp_rect.w, 0, surf->h); + draw::hline(0, sel->bmp_rect.y+sel->bmp_rect.h-1, surf->w); + draw::vline(sel->bmp_rect.x+sel->bmp_rect.w-1, 0, surf->h); draw::resetViewport(); + draw::print2(sel->bmp_rect.x, 3, 1, 4, LIGHT+WHITE, FONT_ZOOM_VERTICAL); + draw::print2(sel->bmp_rect.y, 3, 5, 4, LIGHT+WHITE, FONT_ZOOM_VERTICAL); + draw::print2(sel->bmp_rect.w, 3, 1, 7, LIGHT+WHITE, FONT_ZOOM_VERTICAL); + draw::print2(sel->bmp_rect.h, 3, 5, 7, LIGHT+WHITE, FONT_ZOOM_VERTICAL); + draw::render(); return true; } diff --git a/source/m_game.cpp b/source/m_game.cpp index 910e5c3..a1119cc 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -26,6 +26,8 @@ namespace modules if (editor::isDevMode()) { + draw::setPaletteColor(100, 0xbb, 0x80, 0x80); + draw::setPaletteColor(101, 0xff, 0xc0, 0xc0); draw::stencil::init(); FILE* f = fopen("data/gifs.txt", "r"); @@ -264,10 +266,12 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { - if (console::isEnabled()) + if (console::isEnabled()) { console::toggle(); - else + } else { + if (editor::isEditing()) room::editor::save(); return GAME_MENU; + } } // WHILE EDITING...