diff --git a/src/dialog/ffc_editor.cpp b/src/dialog/ffc_editor.cpp index 8945f34364..1b54e32483 100644 --- a/src/dialog/ffc_editor.cpp +++ b/src/dialog/ffc_editor.cpp @@ -170,6 +170,17 @@ TextField( \ { \ mem = byte(val)-offs; \ }) +#define SWAPFIELDB_PROC(str, mem, lb, hb, offs, proc) \ +Label(text = str, hAlign = 1.0), \ +TextField( \ + type = GUI::TextField::type::SWAP_BYTE, \ + low = lb, high = hb, val = mem+offs, \ + leftPadding = 0_px, fitParent = true, \ + onValChangedFunc = [&](GUI::TextField::type,std::string_view,int32_t val) \ + { \ + mem = byte(val)-offs; \ + proc(); \ + }) #define CHECKB(str, fl, inf) \ Row( \ @@ -255,6 +266,13 @@ void FFCDialog::refreshScript() } } +void FFCDialog::refreshSize() +{ + GUI::DialogRef& ref = cmbsw->alDialog; + if(!ref) return; + ref->w = (ffc.twid+1)*32+4; + ref->h = (ffc.thei+1)*32+4; +} static size_t ffctab = 0; std::shared_ptr FFCDialog::view() { @@ -276,42 +294,47 @@ std::shared_ptr FFCDialog::view() Column( TabPanel( ptr = &ffctab, - TabRef(name = "Data", Rows<4>( - Label(text = "Link to:", hAlign = 1.0), - DropDownList(data = list_link, - fitParent = true, - selectedValue = ffc.link, - onSelectFunc = [&](int32_t val) - { - ffc.link = (byte)val; - } - ), - cmbsw = SelComboSwatch( - combo = ffc.data, - cset = ffc.cset, - rowSpan = 2, colSpan = 2, - // showvals = false, - onSelectFunc = [&](int32_t cmb, int32_t c) - { - ffc.data = cmb; - ffc.cset = c; - tCSet = c; - } + TabRef(name = "Data", Row( + Rows<4>( + SWAPFIELD("X Pos:", ffc.x, SWAP_MIN, SWAP_MAX), + SWAPFIELD("X Speed:", ffc.dx, SWAP_MIN, SWAP_MAX), + // + SWAPFIELD("Y Pos:", ffc.y, SWAP_MIN, SWAP_MAX), + SWAPFIELD("Y Speed:", ffc.dy, SWAP_MIN, SWAP_MAX), + // + SWAPFIELDB("Combo W:", ffc.fwid, 1, 64, 1), + SWAPFIELD("X Accel:", ffc.ax, SWAP_MIN, SWAP_MAX), + // + SWAPFIELDB("Combo H:", ffc.fhei, 1, 64, 1), + SWAPFIELD("Y Accel:", ffc.ay, SWAP_MIN, SWAP_MAX), + // + SWAPFIELDB_PROC("Tile W:", ffc.twid, 1, 4, 1, refreshSize), + SWAPFIELDS("A. Delay:", ffc.delay, 0, 9999), + // + SWAPFIELDB_PROC("Tile H:", ffc.thei, 1, 4, 1, refreshSize), + Label(text = "Link to:", hAlign = 1.0), + DropDownList(data = list_link, + fitParent = true, + selectedValue = ffc.link, + onSelectFunc = [&](int32_t val) + { + ffc.link = (byte)val; + } + ) ), - // DummyWidget(), - SWAPFIELD("X Pos:", ffc.x, SWAP_MIN, SWAP_MAX), - // DummyWidget(), - // DummyWidget(), - SWAPFIELD("Y Pos:", ffc.y, SWAP_MIN, SWAP_MAX), - SWAPFIELDB("Combo W:", ffc.fwid, 1, 64, 1), - SWAPFIELD("X Speed:", ffc.dx, SWAP_MIN, SWAP_MAX), - SWAPFIELDB("Combo H:", ffc.fhei, 1, 64, 1), - SWAPFIELD("Y Speed:", ffc.dy, SWAP_MIN, SWAP_MAX), - SWAPFIELDB("Tile W:", ffc.twid, 1, 4, 1), - SWAPFIELD("X Accel:", ffc.ax, SWAP_MIN, SWAP_MAX), - SWAPFIELDB("Tile H:", ffc.thei, 1, 4, 1), - SWAPFIELD("Y Accel:", ffc.ay, SWAP_MIN, SWAP_MAX), - SWAPFIELDS("A. Delay:", ffc.delay, 0, 9999) + cmb_container = Column(width = 128_px + 5_px + 1_em + text_length(GUI_DEF_FONT, "Combo: 99999"), height = 128_px, + cmbsw = SelComboSwatch(vAlign = 0.0, hAlign = 0.0, + combo = ffc.data, + cset = ffc.cset, + // showvals = false, + onSelectFunc = [&](int32_t cmb, int32_t c) + { + ffc.data = cmb; + ffc.cset = c; + tCSet = c; + } + ) + ) )), TabRef(name = "Flags", Column( Rows<2>( @@ -434,6 +457,11 @@ std::shared_ptr FFCDialog::view() return window; } +void FFCDialog::post_realize() +{ + refreshSize(); +} + bool FFCDialog::handleMessage(const GUI::DialogMessage& msg) { bool m = false; diff --git a/src/dialog/ffc_editor.h b/src/dialog/ffc_editor.h index 094c2a8cab..66cf724bba 100644 --- a/src/dialog/ffc_editor.h +++ b/src/dialog/ffc_editor.h @@ -2,6 +2,7 @@ #define ZC_DIALOG_FFCDLG_H #include +#include #include #include #include @@ -51,10 +52,12 @@ class FFCDialog: public GUI::Dialog std::shared_ptr view() override; bool handleMessage(const GUI::DialogMessage& msg); - + + virtual void post_realize(); private: std::shared_ptr FFC_INITD(int index); void refreshScript(); + void refreshSize(); std::shared_ptr window; std::shared_ptr cmbsw; @@ -63,6 +66,7 @@ class FFCDialog: public GUI::Dialog std::shared_ptr tf_initd[8]; std::shared_ptr ib_initds[8]; std::shared_ptr l_initds[8]; + std::shared_ptr cmb_container; ffdata ffc; mapscr* thescr; diff --git a/src/gui/dialog.h b/src/gui/dialog.h index 9be2cdfccb..03642484f3 100644 --- a/src/gui/dialog.h +++ b/src/gui/dialog.h @@ -67,6 +67,8 @@ class Dialog rerun_dlg = true; close(); } + + virtual void post_realize(){} /* Subclasses must define an int32_t-convertible type called `message` * and implement: diff --git a/src/gui/dialog_runner.cpp b/src/gui/dialog_runner.cpp index 8d7cddccfc..8a4857cc1f 100644 --- a/src/gui/dialog_runner.cpp +++ b/src/gui/dialog_runner.cpp @@ -117,8 +117,6 @@ void DialogRunner::realize(shared_ptr root) void DialogRunner::runInner(std::shared_ptr root) { - realize(root); - realized = true; popup_zqdialog_start_a5(); new_gui_popup_dialog(alDialog.data(), focused, done, running); popup_zqdialog_end_a5(); diff --git a/src/gui/dialog_runner.h b/src/gui/dialog_runner.h index a7536b50b6..6a13724f22 100644 --- a/src/gui/dialog_runner.h +++ b/src/gui/dialog_runner.h @@ -29,7 +29,12 @@ class DialogRunner std::shared_ptr root = dlg.view(); if(root) + { + realize(root); + realized = true; + dlg.post_realize(); runInner(root); + } } /* Add a DIALOG and connect it to its owner. diff --git a/src/gui/widget.h b/src/gui/widget.h index bbed0ccc9e..836160ad7a 100644 --- a/src/gui/widget.h +++ b/src/gui/widget.h @@ -334,6 +334,15 @@ class Widget: public std::enable_shared_from_this { return std::any_cast(userData); } + + int32_t getX() const + { + return x; + } + int32_t getY() const + { + return y; + } protected: inline bool getWidthOverridden() const noexcept {return flags&f_WIDTH_OVERRIDDEN;} diff --git a/src/zq/gui/selcombo_swatch.cpp b/src/zq/gui/selcombo_swatch.cpp index fbe6dc2853..f5a2bc4ad0 100644 --- a/src/zq/gui/selcombo_swatch.cpp +++ b/src/zq/gui/selcombo_swatch.cpp @@ -53,25 +53,37 @@ int32_t newg_selcombo_proc(int32_t msg,DIALOG *d,int32_t) break; case MSG_DRAW: - BITMAP *buf = create_bitmap_ex(8,20,20); - BITMAP *bigbmp = create_bitmap_ex(8,d->h,d->h); + { + static const int TILE_SZ = 32; + int tw = (d->w-4)/TILE_SZ, th = (d->h-4)/TILE_SZ; + BITMAP *buf = create_bitmap_ex(8,16*tw+4,16*th+4); + BITMAP *bigbmp = create_bitmap_ex(8,d->w,d->h); if(buf && bigbmp) { if(dis) - rectfill(bigbmp,0,0,d->h-1,d->h-1,jwin_pal[jcBOX]); + rectfill(bigbmp,0,0,d->w-1,d->h-1,jwin_pal[jcBOX]); else { clear_bitmap(buf); - + clear_bitmap(bigbmp); if(d->d1) - overtile16(buf,combobuf[d->d1].tile,2,2,d->d2,combobuf[d->d1].flip); - - stretch_blit(buf, bigbmp, 2,2, 17, 17, 2, 2, d->h-4, d->h-4); + { + if(tw > 1 || th > 1) + { + overtileblock16(buf, combobuf[d->d1].tile, 2, 2, tw, th, d->d2, combobuf[d->d1].flip, 0); + stretch_blit(buf, bigbmp, 2,2, tw*16, th*16, 2, 2, d->w-4, d->h-4); + } + else + { + overtile16(buf,combobuf[d->d1].tile,2,2,d->d2,combobuf[d->d1].flip); + stretch_blit(buf, bigbmp, 2,2, 16, 16, 2, 2, d->w-4, d->h-4); + } + } } destroy_bitmap(buf); - jwin_draw_frame(bigbmp,0,0,d->h,d->h,FR_DEEP); - blit(bigbmp,screen,0,0,d->x,d->y,d->h,d->h); + jwin_draw_frame(bigbmp,0,0,d->w,d->h,FR_DEEP); + blit(bigbmp,screen,0,0,d->x,d->y,d->w,d->h); destroy_bitmap(bigbmp); } @@ -83,19 +95,20 @@ int32_t newg_selcombo_proc(int32_t msg,DIALOG *d,int32_t) int32_t xo = 5; if(dis) { - textprintf_ex(screen,fonty,d->x+d->h+xo+1,d->y+3,jwin_pal[jcLIGHT],jwin_pal[jcBOX],"Combo: %d",d->d1); - textprintf_ex(screen,fonty,d->x+d->h+xo,d->y+2,jwin_pal[jcDISABLED_FG],-1,"Combo: %d",d->d1); + textprintf_ex(screen,fonty,d->x+d->w+xo+1,d->y+3,jwin_pal[jcLIGHT],jwin_pal[jcBOX],"Combo: %d",d->d1); + textprintf_ex(screen,fonty,d->x+d->w+xo,d->y+2,jwin_pal[jcDISABLED_FG],-1,"Combo: %d",d->d1); - textprintf_ex(screen,fonty,d->x+d->h+xo+1,d->y+text_height(fonty)+4,jwin_pal[jcLIGHT],jwin_pal[jcBOX],"CSet: %d",d->d2); - textprintf_ex(screen,fonty,d->x+d->h+xo,d->y+text_height(fonty)+3,jwin_pal[jcDISABLED_FG],-1,"CSet: %d",d->d2); + textprintf_ex(screen,fonty,d->x+d->w+xo+1,d->y+text_height(fonty)+4,jwin_pal[jcLIGHT],jwin_pal[jcBOX],"CSet: %d",d->d2); + textprintf_ex(screen,fonty,d->x+d->w+xo,d->y+text_height(fonty)+3,jwin_pal[jcDISABLED_FG],-1,"CSet: %d",d->d2); } else { - textprintf_ex(screen,fonty,d->x+d->h+xo,d->y+2,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Combo: %d",d->d1); - textprintf_ex(screen,fonty,d->x+d->h+xo,d->y+text_height(fonty)+3,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"CSet: %d",d->d2); + textprintf_ex(screen,fonty,d->x+d->w+xo,d->y+2,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Combo: %d",d->d1); + textprintf_ex(screen,fonty,d->x+d->w+xo,d->y+text_height(fonty)+3,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"CSet: %d",d->d2); } } break; + } } return D_O_K; } diff --git a/src/zq/gui/selcombo_swatch.h b/src/zq/gui/selcombo_swatch.h index a114c7a5fc..32ce58cf72 100644 --- a/src/zq/gui/selcombo_swatch.h +++ b/src/zq/gui/selcombo_swatch.h @@ -29,12 +29,12 @@ class SelComboSwatch: public Widget { message = static_cast(m); } + DialogRef alDialog; protected: int32_t message; private: int32_t combo, cset; bool showsVals; - DialogRef alDialog; std::function onSelectFunc; void applyVisibility(bool visible) override;