Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update confdialog.h #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 110 additions & 68 deletions RunCPM_VGA32_v5_1/confdialog.h
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
/*
Created by Fabrizio Di Vittorio ([email protected]) - www.fabgl.com
Copyright (c) 2019-2020 Fabrizio Di Vittorio.
All rights reserved.

This file is part of FabGL Library.

FabGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

FabGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FabGL. If not, see <http://www.gnu.org/licenses/>.
*/


#pragma once

#include <Preferences.h>

#include "fabui.h"

#include "uistyle.h"

Preferences preferences;


#define TERMVERSION_MAJ 1
#define TERMVERSION_MIN 3

#define STYLE_FRAME_ID 1
#define STYLE_LABEL_ID 2
#define STYLE_LABELHELP_ID 3
#define STYLE_BUTTON_ID 4
#define STYLE_COMBOBOX 5

#define BACKGROUND_COLOR RGB888(64, 64, 64)
#define BUTTONS_BACKGROUND_COLOR RGB888(128, 128, 64);


struct ConfDialogStyle : uiStyle {
void setStyle(uiObject * object, uint32_t styleClassID) {
switch (styleClassID) {
case STYLE_FRAME_ID:
((uiFrame*)object)->windowStyle().activeBorderColor = RGB888(128, 128, 255);
((uiFrame*)object)->frameStyle().activeTitleBackgroundColor = RGB888(128, 128, 255);
((uiFrame*)object)->frameStyle().backgroundColor = BACKGROUND_COLOR;
break;
case STYLE_LABEL_ID:
((uiLabel*)object)->labelStyle().textFont = &fabgl::FONT_std_12;
((uiLabel*)object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
((uiLabel*)object)->labelStyle().textColor = RGB888(255, 255, 255);
break;
case STYLE_LABELHELP_ID:
((uiLabel*)object)->labelStyle().textFont = &fabgl::FONT_std_14;
((uiLabel*)object)->labelStyle().backgroundColor = BACKGROUND_COLOR;
((uiLabel*)object)->labelStyle().textColor = RGB888(255, 255, 0);
break;
case STYLE_BUTTON_ID:
((uiButton*)object)->windowStyle().borderColor = RGB888(0, 0, 0);
((uiButton*)object)->buttonStyle().backgroundColor = BUTTONS_BACKGROUND_COLOR;
break;
case STYLE_COMBOBOX:
((uiFrame*)object)->windowStyle().borderColor = RGB888(255, 255, 255);
((uiFrame*)object)->windowStyle().borderSize = 1;
break;
}
}
} confDialogStyle;

constexpr int BOOTINFO_DISABLED = 0;
constexpr int BOOTINFO_ENABLED = 1;
constexpr int BOOTINFO_TEMPDISABLED = 2;

constexpr int KEYCLICK_DISABLED = 0;
constexpr int KEYCLICK_ENABLED = 1;

class ConfDialogApp : public uiApp {



struct ConfDialogApp : public uiApp {

Rect frameRect;
int progToInstall;

uiFrame * frame;
uiComboBox * termComboBox;
uiComboBox * kbdComboBox;
uiColorComboBox * bgColorComboBox;
uiColorComboBox * fgColorComboBox;
uiColorComboBox * bdColorComboBox;
uiCheckBox * infoCheckBox;
uiCheckBox * clickCheckBox;

void init() {

setStyle(&confDialogStyle);
setStyle(&dialogStyle);

rootWindow()->frameProps().fillBackground = false;

frame = new uiFrame(rootWindow(), "Screen Configuration", Point(110, 60), Size(380, 220), true, STYLE_FRAME_ID);
frame = new uiFrame(rootWindow(), "Terminal Configuration", UIWINDOW_PARENTCENTER, Size(380, 275), true, STYLE_FRAME);
frameRect = frame->rect(fabgl::uiOrigin::Screen);

frame->frameProps().resizeable = false;
frame->frameProps().moveable = false;
frame->frameProps().hasCloseButton = false;
frame->frameProps().hasMaximizeButton = false;
frame->frameProps().hasMinimizeButton = false;

// ESC : exit without save
// F10 : save and exit
Expand All @@ -81,50 +87,71 @@ class ConfDialogApp : public uiApp {
int y = 24;

// little help
new uiLabel(frame, "Use the TAB key to move between fields", Point(90, y), Size(0, 0), true, STYLE_LABELHELP_ID);
new uiLabel(frame, "RunCPM for VGA32 by coopzone-dc & Guido Lehwalder", Point(52, y), Size(0, 0), true, STYLE_LABELHELP);
new uiLabel(frame, "Press TAB key to move between fields", Point(100, y +24), Size(0, 0), true, STYLE_LABELHELP);
new uiLabel(frame, "Outside this dialog press CTRL-ALT-F12 to reset settings", Point(52, y + 36), Size(0, 0), true, STYLE_LABELHELP);


y += 30;
y += 56;

// select terminal emulation combobox
new uiLabel(frame, "Terminal Type", Point(10, y), Size(0, 0), true, STYLE_LABEL_ID);
new uiLabel(frame, "Terminal Type", Point(10, y), Size(0, 0), true, STYLE_LABEL);
termComboBox = new uiComboBox(frame, Point(10, y + 12), Size(85, 20), 80, true, STYLE_COMBOBOX);
termComboBox->items().append(SupportedTerminals::names(), SupportedTerminals::count());
termComboBox->selectItem((int)getTermType());

// select keyboard layout
new uiLabel(frame, "Keyboard Layout", Point(110, y), Size(0, 0), true, STYLE_LABEL_ID);
new uiLabel(frame, "Keyboard Layout", Point(110, y), Size(0, 0), true, STYLE_LABEL);
kbdComboBox = new uiComboBox(frame, Point(110, y + 12), Size(75, 20), 70, true, STYLE_COMBOBOX);
kbdComboBox->items().append(SupportedLayouts::names(), SupportedLayouts::count());
kbdComboBox->selectItem(getKbdLayoutIndex());

// background color
new uiLabel(frame, "Background Color", Point(200, y), Size(0, 0), true, STYLE_LABEL_ID);
new uiLabel(frame, "Background Color", Point(200, y), Size(0, 0), true, STYLE_LABEL);
bgColorComboBox = new uiColorComboBox(frame, Point(200, y + 12), Size(75, 20), 70, true, STYLE_COMBOBOX);
bgColorComboBox->selectColor(getBGColor());

// foreground color
new uiLabel(frame, "Foreground Color", Point(290, y), Size(0, 0), true, STYLE_LABEL_ID);
new uiLabel(frame, "Foreground Color", Point(290, y), Size(0, 0), true, STYLE_LABEL);
fgColorComboBox = new uiColorComboBox(frame, Point(290, y + 12), Size(75, 20), 70, true, STYLE_COMBOBOX);
fgColorComboBox->selectColor(getFGColor());

y += 56;

// show keyclick select
new uiLabel(frame, "KeyClick", Point(10, y), Size(0, 0), true, STYLE_LABEL);
clickCheckBox = new uiCheckBox(frame, Point(80, y - 2), Size(16, 16), uiCheckBoxKind::CheckBox, true, STYLE_CHECKBOX);
clickCheckBox->setChecked(getKeyClick() == KEYCLICK_ENABLED);

// bold attribute color
new uiLabel(frame, "Bold Color", Point(290, y-16), Size(0, 0), true, STYLE_LABEL);
bdColorComboBox = new uiColorComboBox(frame, Point(290, y -4), Size(75, 20), 70, true, STYLE_COMBOBOX);
bdColorComboBox->selectColor(getBDColor());

y += 24;

y += 115;
// show boot info
new uiLabel(frame, "BootInfo", Point(10, y), Size(0, 0), true, STYLE_LABEL);
infoCheckBox = new uiCheckBox(frame, Point(80, y - 2), Size(16, 16), uiCheckBoxKind::CheckBox, true, STYLE_CHECKBOX);
infoCheckBox->setChecked(getBootInfo() == BOOTINFO_ENABLED);

y += 48;

// exit without save button
auto exitNoSaveButton = new uiButton(frame, "Quit [ESC]", Point(90, y), Size(90, 20), uiButtonKind::Button, true, STYLE_BUTTON_ID);
auto exitNoSaveButton = new uiButton(frame, "Quit [ESC]", Point(10, y), Size(90, 20), uiButtonKind::Button, true, STYLE_BUTTON);
exitNoSaveButton->onClick = [&]() {
quit(0);
};

// exit with save button
auto exitSaveButton = new uiButton(frame, "Save & Quit [F10]", Point(190, y), Size(90, 20), uiButtonKind::Button, true, STYLE_BUTTON_ID);
auto exitSaveButton = new uiButton(frame, "Save & Quit [F10]", Point(110, y), Size(90, 20), uiButtonKind::Button, true, STYLE_BUTTON);
exitSaveButton->onClick = [&]() {
saveProps();
quit(0);
};



setActiveWindow(frame);
setFocusedWindow(exitNoSaveButton);

Expand All @@ -136,11 +163,21 @@ class ConfDialogApp : public uiApp {
preferences.putInt("KbdLayout", kbdComboBox->selectedItem());
preferences.putInt("BGColor", (int)bgColorComboBox->selectedColor());
preferences.putInt("FGColor", (int)fgColorComboBox->selectedColor());
preferences.putInt("BDColor", (int)bdColorComboBox->selectedColor());
preferences.putInt("BootInfo", infoCheckBox->checked() ? BOOTINFO_ENABLED : BOOTINFO_DISABLED);
preferences.putInt("KeyClick", clickCheckBox->checked() ? KEYCLICK_ENABLED : KEYCLICK_DISABLED);

loadConfiguration();
}


public:
~ConfDialogApp() {
// this is required, becasue the terminal may not cover the entire screen
canvas()->reset();
canvas()->setBrushColor(getBGColor());
canvas()->fillRectangle(frameRect);
}


static TermType getTermType() {
return (TermType) preferences.getInt("TermType", 7); // default 7 = ANSILegacy
Expand All @@ -150,39 +187,44 @@ class ConfDialogApp : public uiApp {
return preferences.getInt("KbdLayout", 3); // default 3 = "US"
}

static int getBaudRateIndex() {
return preferences.getInt("BaudRate", 11); // default 11 = 115200
static Color getBGColor() {
return (Color) preferences.getInt("BGColor", (int)Color::Black);
}

static int getDataLenIndex() {
return preferences.getInt("DataLen", 3); // default 3 = 8 bits
static Color getFGColor() {
return (Color) preferences.getInt("FGColor", (int)Color::BrightGreen);
}

static int getParityIndex() {
return preferences.getInt("Parity", 0); // default 0 = no parity
static Color getBDColor() {
return (Color) preferences.getInt("BDColor", (int)Color::BrightYellow);
}

static int getStopBitsIndex() {
return preferences.getInt("StopBits", 1); // default 1 = 1 stop bit
static int getBootInfo() {
return preferences.getInt("BootInfo", BOOTINFO_ENABLED);
}

static FlowControl getFlowCtrl() {
return (FlowControl) preferences.getInt("FlowCtrl", 0); // default 0 = no flow control
static int getKeyClick() {
return preferences.getInt("KeyClick", KEYCLICK_ENABLED);
}

static Color getBGColor() {
return (Color) preferences.getInt("BGColor", (int)Color::Black);
// if version in preferences doesn't match, reset preferences
static void checkVersion() {
if (preferences.getInt("VerMaj", 0) != TERMVERSION_MAJ || preferences.getInt("VerMin", 0) != TERMVERSION_MIN) {
preferences.clear();
preferences.putInt("VerMaj", TERMVERSION_MAJ);
preferences.putInt("VerMin", TERMVERSION_MIN);
}
}

static Color getFGColor() {
return (Color) preferences.getInt("FGColor", (int)Color::BrightGreen);
}

static void loadConfiguration() {
Terminal.setTerminalType(getTermType());
Terminal.keyboard()->setLayout(SupportedLayouts::layouts()[getKbdLayoutIndex()]);
Terminal.connectLocally(); // to use Terminal.read(), available(), etc..
Terminal.setBackgroundColor(getBGColor());
Terminal.setForegroundColor(getFGColor());
Terminal.setColorForAttribute(CharStyle::Bold, getBDColor(), true);

}

};