Skip to content

Commit

Permalink
FLTK: Use less magic numbers for UI element sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
rdanbrook committed Mar 29, 2024
1 parent 6457ea6 commit 063e4bb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 80 deletions.
34 changes: 16 additions & 18 deletions source/fltkui/fltkui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
#include "fltkui_cheats.h"
#include "fltkui_config.h"

#define MBARHEIGHT 24

static NstWindow *nstwin;
static Fl_Menu_Bar *menubar;
static NstGlArea *glarea;
Expand Down Expand Up @@ -265,9 +263,9 @@ static void fltkui_reset(Fl_Widget* w, void* userdata) {
void fltkui_resize() {
video_set_dimensions();
dimensions_t rendersize = nst_video_get_dimensions_render();
nstwin->size(rendersize.w, rendersize.h + MBARHEIGHT);
menubar->resize(0, 0, nstwin->w(), MBARHEIGHT);
glarea->resize(0, 24, rendersize.w, rendersize.h);
nstwin->size(rendersize.w, rendersize.h + UI_MBARHEIGHT);
menubar->resize(0, 0, nstwin->w(), UI_MBARHEIGHT);
glarea->resize(0, UI_MBARHEIGHT, rendersize.w, rendersize.h);
nst_video_set_dimensions_screen(rendersize);
video_init();
}
Expand All @@ -292,10 +290,10 @@ void fltkui_fullscreen(Fl_Widget* w, void* userdata) {
video_set_dimensions();
dimensions_t rendersize = nst_video_get_dimensions_render();
nstwin->fullscreen_off();
nstwin->size(rendersize.w, rendersize.h + MBARHEIGHT);
nstwin->size(rendersize.w, rendersize.h + UI_MBARHEIGHT);
menubar->show();
menubar->resize(0, 0, nstwin->w(), MBARHEIGHT);
glarea->resize(0, 24, rendersize.w, rendersize.h);
menubar->resize(0, 0, nstwin->w(), UI_MBARHEIGHT);
glarea->resize(0, UI_MBARHEIGHT, rendersize.w, rendersize.h);
nst_video_set_dimensions_screen(rendersize);
video_init();
}
Expand All @@ -318,20 +316,20 @@ static void fltkui_about(Fl_Widget* w, void* userdata) {
Fl_Window about(460, 440);
Fl_Box iconbox(166, 16, 128, 128);

Fl_Box text0(0, 144, 460, 24, "Nestopia UE");
Fl_Box text0(0, 144, 460, UI_SPACING, "Nestopia UE");
text0.labelfont(FL_BOLD);

Fl_Box text1(0, 166, 460, 24, "1.52.0");
Fl_Box text1(0, 166, 460, UI_SPACING, "1.52.1");

Fl_Box text2(0, 208, 460, 24, "Cycle-Accurate Nintendo Entertainment System Emulator");
Fl_Box text2(0, 208, 460, UI_SPACING, "Cycle-Accurate Nintendo Entertainment System Emulator");

Fl_Box text3(0, 256, 460, 24, "FLTK Frontend\n(c) 2012-2023, R. Danbrook\n(c) 2007-2008, R. Belmont");
Fl_Box text3(0, 256, 460, UI_SPACING, "FLTK Frontend\n(c) 2012-2024, R. Danbrook\n(c) 2007-2008, R. Belmont");
text3.labelsize(10);

Fl_Box text4(0, 320, 460, 24, "Nestopia Emulator\n(c) 2020-2023, Rupert Carmichael\n(c) 2012-2020, Nestopia UE Contributors\n(c) 2003-2008, Martin Freij");
Fl_Box text4(0, 320, 460, UI_SPACING, "Nestopia Emulator\n(c) 2020-2024, Rupert Carmichael\n(c) 2012-2020, Nestopia UE Contributors\n(c) 2003-2008, Martin Freij");
text4.labelsize(10);

Fl_Box text5(0, 360, 460, 24, "Icon based on drawing by Trollekop");
Fl_Box text5(0, 360, 460, UI_SPACING, "Icon based on drawing by Trollekop");
text5.labelsize(10);

// Set up the icon
Expand All @@ -346,7 +344,7 @@ static void fltkui_about(Fl_Widget* w, void* userdata) {
Fl_PNG_Image nsticon(iconpath);
iconbox.image(nsticon);

Fl_Button close(360, 400, 80, 24, "&Close");
Fl_Button close(360, 400, 80, UI_SPACING, "&Close");
close.callback(fltkui_about_close, (void*)&about);

about.set_modal();
Expand Down Expand Up @@ -448,16 +446,16 @@ void makenstwin(const char *name) {
confwin->populate();

// Main Window
nstwin = new NstWindow(rendersize.w, rendersize.h + MBARHEIGHT, name);
nstwin = new NstWindow(rendersize.w, rendersize.h + UI_MBARHEIGHT, name);
nstwin->color(FL_BLACK);
nstwin->xclass("nestopia");

// Menu Bar
menubar = new Fl_Menu_Bar(0, 0, nstwin->w(), MBARHEIGHT);
menubar = new Fl_Menu_Bar(0, 0, nstwin->w(), UI_MBARHEIGHT);
menubar->box(FL_FLAT_BOX);
menubar->menu(menutable);

glarea = new NstGlArea(0, MBARHEIGHT, nstwin->w(), nstwin->h() - MBARHEIGHT);
glarea = new NstGlArea(0, UI_MBARHEIGHT, nstwin->w(), nstwin->h() - UI_MBARHEIGHT);
glarea->color(FL_BLACK);

nstwin->end();
Expand Down
7 changes: 7 additions & 0 deletions source/fltkui/fltkui.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef MAIN_H
#define MAIN_H

#define UI_MBARHEIGHT 24
#define UI_SPACING 24
#define UI_ELEMHEIGHT 25
#define UI_ELEMWIDTH 160
#define UI_DIAL_LG 100
#define UI_DIAL_SM 40

class NstWindow : public Fl_Double_Window {
private:
int handle(int e);
Expand Down
23 changes: 13 additions & 10 deletions source/fltkui/fltkui_cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
#include <FL/Fl_Table_Row.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/fl_draw.H>

#include "cheats.h"
#include "nstcommon.h"
#include "video.h"
#include "fltkui.h"
#include "fltkui_cheats.h"

static Fl_Input *input_desc;
Expand Down Expand Up @@ -246,29 +249,29 @@ void NstChtWindow::populate() {
ctable->when(FL_WHEN_CHANGED);
ctable->end();

input_desc = new Fl_Input(380, 310, 260, 25, "Description:");
input_gg = new Fl_Input(380, 340, 260, 25, "Game Genie:");
input_par = new Fl_Input(380, 370, 260, 25, "Pro Action Rocky:");
input_desc = new Fl_Input(380, 310, 260, UI_ELEMHEIGHT, "Description:");
input_gg = new Fl_Input(380, 340, 260, UI_ELEMHEIGHT, "Game Genie:");
input_par = new Fl_Input(380, 370, 260, UI_ELEMHEIGHT, "Pro Action Rocky:");

Fl_Button *btnadd = new Fl_Button(380, 400, 80, 25, "Add");
Fl_Button *btnadd = new Fl_Button(380, 400, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "Add");
btnadd->callback(cb_add, 0);

Fl_Button *btntog = new Fl_Button(20, 300, 80, 25, "Toggle");
Fl_Button *btntog = new Fl_Button(20, 300, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "Toggle");
btntog->callback(cb_toggle, 0);

Fl_Button *btndel = new Fl_Button(110, 300, 80, 25, "Delete");
Fl_Button *btndel = new Fl_Button(110, 300, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "Delete");
btndel->callback(cb_del, 0);

Fl_Button *btnclr = new Fl_Button(200, 300, 80, 25, "Clear");
Fl_Button *btnclr = new Fl_Button(200, 300, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "Clear");
btnclr->callback(cb_clr, 0);

Fl_Button *btnload = new Fl_Button(20, 350, 80, 25, "Load...");
Fl_Button *btnload = new Fl_Button(20, 350, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "Load...");
btnload->callback(cb_load, 0);

Fl_Button *btnsave = new Fl_Button(20, 380, 80, 25, "Save...");
Fl_Button *btnsave = new Fl_Button(20, 380, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "Save...");
btnsave->callback(cb_save, 0);

Fl_Button *btnok = new Fl_Button(560, 460, 80, 25, "&OK");
Fl_Button *btnok = new Fl_Button(560, 460, UI_ELEMWIDTH / 2, UI_ELEMHEIGHT, "&OK");
btnok->callback(cb_ok, 0);

this->end();
Expand Down
Loading

0 comments on commit 063e4bb

Please sign in to comment.