Skip to content

Commit

Permalink
Merge pull request #5117 from aybe/even-more-conf-tool
Browse files Browse the repository at this point in the history
More Windows 3.1 styling for CFGTOOL
  • Loading branch information
aybe authored Jul 13, 2024
2 parents 55ccbee + 88c0444 commit 3e1e445
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 73 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ NEXT
- Updated SDL2 library to 2.30.4 (maron2000)
- Fixed TTF mode didn't change to graphic mode when machine = Hercules
(maron2000)
- CFGTOOL: more Windows 3.1 styling, general UX/UI improvements (aybe).
- Configuration tool: (aybe)
- more Windows 3.1 styling: buttons, colors, focus, layout
- enhance main window layout, it is now visible in its entirety
- fix layout issues, off by one in rectangle drawing functions
- fix 'list iterators incompatible' when pressing the Tab key
- properties/help: sorted alphabetically, mouse wheel scrollable
- remove few rendundant labels, adjust names of some others
- retain 'show advanced options' state throughout session

2024.07.01
- Correct Hercules InColor memory emulation. Read and write planar
Expand Down
37 changes: 23 additions & 14 deletions src/gui/sdl_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ void macosx_reload_touchbar(void);

std::list<std::string> proplist = {};
GUI::Checkbox *advopt, *saveall, *imgfd360, *imgfd400, *imgfd720, *imgfd1200, *imgfd1440, *imgfd2880, *imghd250, *imghd520, *imghd1gig, *imghd2gig, *imghd4gig, *imghd8gig;

// user pick of 'show advanced options' for the session
bool advOptUser = false;

std::string GetDOSBoxXPath(bool withexe);
static std::map< std::vector<GUI::Char>, GUI::ToplevelWindow* > cfg_windows_active;
void getlogtext(std::string &str), getcodetext(std::string &text), ApplySetting(std::string pvar, std::string inputline, bool quiet), GUI_Run(bool pressed);
Expand Down Expand Up @@ -1662,7 +1666,7 @@ class ConfigEditor : public GUI::ToplevelWindow {
}
}

int height=title=="Config"?100:210;
int height=title=="Config"?100:81;
scroll_h += height + 2; /* border */

wiw = new GUI::WindowInWindow(this, 5, 5, width-border_left-border_right-10, scroll_h);
Expand Down Expand Up @@ -3166,14 +3170,16 @@ class ConfigurationWindow : public GUI::ToplevelWindow {
bar->addActionHandler(this);

int gridbtnwidth = 130;
int gridbtnheight = 26;
int gridbtnheight = GUI::CurrentTheme.ButtonHeight;
int gridbtnx = 12;
int gridbtny = 25;
int btnperrow = 4;
int i = 0;

const auto xSpace = gridbtnwidth + 2;
const auto ySpace = gridbtnheight + 2;
constexpr auto margin = 3;

const auto xSpace = gridbtnwidth + margin;
const auto ySpace = gridbtnheight + margin;

std::function< std::pair<int,int>(const int) > gridfunc = [&/*access to locals here*/](const int i){
return std::pair<int,int>(gridbtnx+(i%btnperrow)*xSpace, gridbtny+(i/btnperrow)*ySpace);
Expand Down Expand Up @@ -3239,14 +3245,12 @@ class ConfigurationWindow : public GUI::ToplevelWindow {

for(const auto & sec : sections)
{
if (i != 0 && (i%15) == 0) bar->addItem(1, "|");
std::string name = sec->GetName();
std::string title = CapName(name);
name[0] = std::toupper(name[0]);
if (i != 0 && (i%16) == 0) bar->addItem(1, "|");
std::string sectionTitle = CapName(std::string(sec->GetName()));
const auto sz = gridfunc(i);
GUI::Button *b = new GUI::Button(this, sz.first, sz.second, title, gridbtnwidth, gridbtnheight);
GUI::Button *b = new GUI::Button(this, sz.first, sz.second, sectionTitle, gridbtnwidth, gridbtnheight);
b->addActionHandler(this);
bar->addItem(1, title);
bar->addItem(1, sectionTitle);
i++;
}

Expand All @@ -3255,13 +3259,17 @@ class ConfigurationWindow : public GUI::ToplevelWindow {

advopt = new GUI::Checkbox(this, gridbtnx, closerow_y, MSG_Get("SHOW_ADVOPT"));
Section_prop * section=static_cast<Section_prop *>(control->GetSection("dosbox"));
advopt->setChecked(section->Get_bool("show advanced options"));
advopt->setChecked(section->Get_bool("show advanced options") || advOptUser);

strcpy(tmp1, (MSG_Get("SAVE")+std::string("...")).c_str());
(saveButton = new GUI::Button(this, 276, closerow_y, tmp1, 130, gridbtnheight))->addActionHandler(this);
(closeButton = new GUI::Button(this, 408, closerow_y, MSG_Get("CLOSE"), 130, gridbtnheight))->addActionHandler(this);

resize(gridbtnx + (xSpace * btnperrow) + 12 + border_left + border_right,
const auto xSave = gridbtnx + (gridbtnwidth + margin) * 2;
const auto xExit = gridbtnx + (gridbtnwidth + margin) * 3;

(saveButton = new GUI::Button(this, xSave, closerow_y, tmp1, gridbtnwidth, gridbtnheight))->addActionHandler(this);
(closeButton = new GUI::Button(this, xExit, closerow_y, MSG_Get("CLOSE"), gridbtnwidth, gridbtnheight))->addActionHandler(this);

resize(gridbtnx + (xSpace * btnperrow) + gridbtnx + border_left + border_right,
closerow_y + closeButton->getHeight() + 8 + border_top + border_bottom);

bar->resize(getWidth(),bar->getHeight());
Expand All @@ -3287,6 +3295,7 @@ class ConfigurationWindow : public GUI::ToplevelWindow {
}

void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) override {
advOptUser = advopt->isChecked();
GUI::String sname = RestoreName(arg);
sname.at(0) = (unsigned int)std::tolower((int)sname.at(0));
Section *sec;
Expand Down
110 changes: 69 additions & 41 deletions src/libs/gui_tk/gui_tk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,26 @@ void Drawable::drawCircle(int d) {

void Drawable::drawRect(int w, int h)
{
gotoXY(x-lineWidth/2,y);
drawLine(x+w+lineWidth-1,y);
gotoXY(x-(lineWidth-1)/2,y);
drawLine(x,y+h);
gotoXY(x+(lineWidth-1)/2,y);
drawLine(x-w-lineWidth+1,y);
gotoXY(x+lineWidth/2,y);
drawLine(x,y-h);
gotoXY(x - lineWidth / 2, y); // tl
drawLine(x + (w - 1) + lineWidth - 1, y); // tr
gotoXY(x - (lineWidth - 1) / 2, y); // tl
drawLine(x, y + (h - 1)); // bl
gotoXY(x + (lineWidth - 1) / 2, y); // tl
drawLine(x - (w - 1) - lineWidth + 1, y); // tr
gotoXY(x + lineWidth / 2, y); // tl
drawLine(x, y - (h - 1)); // bl
}

void Drawable::drawDotRect(int w, int h)
{
gotoXY(x-lineWidth/2,y);
drawDotLine(x+w+lineWidth-1,y);
gotoXY(x-(lineWidth-1)/2,y);
drawDotLine(x,y+h);
gotoXY(x+(lineWidth-1)/2,y);
drawDotLine(x-w-lineWidth+1,y);
gotoXY(x+lineWidth/2,y);
drawDotLine(x,y-h);
gotoXY(x - lineWidth / 2, y); // tl
drawDotLine(x + (w - 1) + lineWidth - 1, y); // tr
gotoXY(x - (lineWidth - 1) / 2, y); // tl
drawDotLine(x, y + (h - 1)); // bl
gotoXY(x + (lineWidth - 1) / 2, y); // tl
drawDotLine(x - (w - 1) - lineWidth + 1, y); // tr
gotoXY(x + lineWidth / 2, y); // tl
drawDotLine(x, y - (h - 1)); // bl
}

void Drawable::fill()
Expand Down Expand Up @@ -761,13 +761,15 @@ bool Window::keyDown(const Key &key)
if ((*i) != children.back()) children.back()->onTabbing(ONTABBING_REVTABFROMTHIS);
(*i)->onTabbing(ONTABBING_REVTABTOTHIS);
if ((*i)->raise())
break;
{
toplevel = true;
break;
}
}

++i;
}
if (tab_quit) return false;
return (i != e) || toplevel/*prevent TAB escape to another window*/;
return handleTab(tab_quit, i, e);
} else {
std::list<Window *>::iterator i = children.begin(), e = children.end();
--e;
Expand All @@ -781,16 +783,15 @@ bool Window::keyDown(const Key &key)
if ((*i) != children.back()) children.back()->onTabbing(ONTABBING_TABFROMTHIS);
(*i)->onTabbing(ONTABBING_TABTOTHIS);
if ((*i)->raise())
break;
{
toplevel = true;
break;
}
}

++i;
}
if (tab_quit) return false;
// BUG/TODO swapped operands below to fix 'list iterators incompatible'
// occurs in VS debug build when pressing TAB after opening configuration tool
// currently this works but that just sweeps the problem under the rug
return toplevel /*prevent TAB escape to another window*/ || (i != e);
return handleTab(tab_quit, i, e);
}
}

Expand Down Expand Up @@ -891,8 +892,7 @@ bool WindowInWindow::keyDown(const Key &key)

++i;
}
if (tab_quit) return false;
return (i != e) || toplevel/*prevent TAB escape to another window*/;
return handleTab(tab_quit, i, e);
} else {
std::list<Window *>::iterator i = children.begin(), e = children.end();
--e;
Expand All @@ -907,13 +907,15 @@ bool WindowInWindow::keyDown(const Key &key)
(*i)->onTabbing(ONTABBING_TABTOTHIS);
if (!tab_quit) scrollToWindow(*i);
if ((*i)->raise())
break;
{
toplevel = true;
break;
}
}

++i;
}
if (tab_quit) return false;
return (i != e) || toplevel/*prevent TAB escape to another window*/;
return handleTab(tab_quit, i, e);
}
}

Expand Down Expand Up @@ -1024,10 +1026,32 @@ bool Window::mouseDoubleClicked(int x, int y, MouseButton button)
return mouseChild->mouseDoubleClicked(x-mouseChild->x, y-mouseChild->y, button);
}

bool Window::mouseWheel(int wheel)
bool Window::mouseWheel(int x, int y, int wheel)
{
for(const auto& win1 : children)
{
if(win1->hasFocus())
{
for(const auto& win2 : win1->children)
{
if(dynamic_cast<WindowInWindow*>(win2))
{
const auto xMin = win1->x + win2->x;
const auto yMin = win1->y + win2->y;
const auto xMax = xMin + win2->width - 1;
const auto yMax = yMin + win2->height - 1;

if(x >= xMin && x <= xMax && y >= yMin && y <= yMax)
{
return win2->mouseWheel(x, y, wheel);
}
}
}
}
}

if (mouseChild == NULL) return false;
return mouseChild->mouseWheel(wheel);
return mouseChild->mouseWheel(x, y, wheel);
}

bool BorderedWindow::mouseDown(int x, int y, MouseButton button)
Expand Down Expand Up @@ -2334,8 +2358,13 @@ bool ScreenSDL::event(SDL_Event &event) {
lastdown = 0;
return rc;
#if C_SDL2
#if WIN32
case SDL_MOUSEWHEEL:
return mouseWheel(event.wheel.y);
{
const auto wheel = event.wheel;
return mouseWheel(wheel.mouseX / scale, wheel.mouseY / scale, wheel.y);
}
#endif
#endif
}

Expand Down Expand Up @@ -2366,7 +2395,7 @@ void WindowInWindow::paintScrollBar3DOutset(Drawable &dscroll, int x, int y, int
void WindowInWindow::paintScrollBarThumb(Drawable &dscroll, vscrollbarlayout &vsl) const {
// black border
dscroll.setColor(vsl.disabled ? CurrentTheme.Shadow3D : Color::Black);
dscroll.drawRect(vsl.xleft,vsl.ytop,vsl.thumbwidth-1,vsl.thumbheight-1);
dscroll.drawRect(vsl.xleft,vsl.ytop,vsl.thumbwidth,vsl.thumbheight);

// 3D outset style, 1 pixel inward each side, inside the black rectangle we just drew
paintScrollBar3DOutset(dscroll, vsl.xleft+1, vsl.ytop+1, vsl.thumbwidth-2, vsl.thumbheight-2);
Expand All @@ -2375,7 +2404,7 @@ void WindowInWindow::paintScrollBarThumb(Drawable &dscroll, vscrollbarlayout &vs
void WindowInWindow::paintScrollBarBackground(Drawable &dscroll,const vscrollbarlayout &vsl) const {
/* scroll bar border, background */
dscroll.setColor(vsl.disabled ? CurrentTheme.Shadow3D : Color::Black);
dscroll.drawRect(vsl.scrollthumbRegion.x, vsl.scrollthumbRegion.y, vsl.scrollthumbRegion.w-1,vsl.scrollthumbRegion.h-1);
dscroll.drawRect(vsl.scrollthumbRegion.x, vsl.scrollthumbRegion.y, vsl.scrollthumbRegion.w,vsl.scrollthumbRegion.h);

dscroll.setColor(CurrentTheme.Background);
dscroll.fillRect(vsl.scrollthumbRegion.x+1,vsl.scrollthumbRegion.y+1,vsl.scrollthumbRegion.w-2,vsl.scrollthumbRegion.h-2);
Expand Down Expand Up @@ -2497,7 +2526,7 @@ void WindowInWindow::paintAll(Drawable &d) const {

// black border
dscroll.setColor(vsl.disabled ? CurrentTheme.Shadow3D : Color::Black);
dscroll.drawRect(x,y,w-1,h-1);
dscroll.drawRect(x,y,w,h);

// 3D outset style, 1 pixel inward each side, inside the black rectangle we just drew
if (vscroll_uparrowhold && vscroll_uparrowdown)
Expand All @@ -2519,7 +2548,7 @@ void WindowInWindow::paintAll(Drawable &d) const {

// black border
dscroll.setColor(vsl.disabled ? CurrentTheme.Shadow3D : Color::Black);
dscroll.drawRect(x,y,w-1,h-1);
dscroll.drawRect(x,y,w,h);

// 3D outset style, 1 pixel inward each side, inside the black rectangle we just drew
if (vscroll_downarrowhold && vscroll_downarrowdown)
Expand Down Expand Up @@ -2876,11 +2905,10 @@ bool WindowInWindow::mouseDoubleClicked(int x, int y, MouseButton button) {
return Window::mouseDoubleClicked(x-xadj,y-xadj,button);
}

bool WindowInWindow::mouseWheel(int wheel)
bool WindowInWindow::mouseWheel(int x, int y, int wheel)
{
// BUG requires to click at least once in window for it to work
scroll_pos_y = imin(imax(scroll_pos_y - wheel * 15, 0), scroll_pos_h);
return Window::mouseWheel(wheel);
scroll_pos_y = imin(imax(scroll_pos_y - wheel * 30, 0), scroll_pos_h);
return Window::mouseWheel(x, y, wheel);
}

void WindowInWindow::resize(int w, int h) {
Expand Down
Loading

0 comments on commit 3e1e445

Please sign in to comment.