Files
BlitzNext/debugger/prefs.cpp
T

207 lines
5.3 KiB
C++
Raw Normal View History

2014-01-31 08:23:00 +13:00
2019-01-18 15:55:40 +01:00
#include "prefs.hpp"
2014-01-31 08:23:00 +13:00
#include <fstream>
2019-01-18 17:04:34 +01:00
#include "debuggerapp.hpp"
#include "stdafx.hpp"
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:34 +01:00
#define SWAPRB(x) ((((x) >> 16) & 0xff) | ((x)&0xff00) | (((x)&0xff) << 16))
2014-01-31 08:23:00 +13:00
Prefs prefs;
2019-01-18 17:04:34 +01:00
void Prefs::open()
{
homeDir = getenv("blitzpath");
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:34 +01:00
AddFontResource((homeDir + "/cfg/blitz.fon").c_str());
2014-01-31 08:23:00 +13:00
setDefault();
bool prg_windowed;
2019-01-18 17:04:34 +01:00
ifstream in((homeDir + "/cfg/blitzide.prefs").c_str());
if (!in.good())
return;
while (!in.eof()) {
string t;
in >> t;
if (!t.size())
continue;
while (in.peek() == '\t')
in.ignore();
if (t == "prg_debug")
in >> prg_debug;
else if (t == "prg_lastbuild")
getline(in, prg_lastbuild);
else if (t == "prg_windowed")
in >> prg_windowed;
else if (t == "win_maximized")
in >> win_maximized;
else if (t == "win_notoolbar")
in >> win_notoolbar;
else if (t == "win_rect") {
in >> win_rect.left;
in >> win_rect.top;
in >> win_rect.right;
in >> win_rect.bottom;
} else if (t.substr(0, 5) == "font_") {
string s;
int h;
in >> s;
in >> h;
t = t.substr(5);
if (t == "editor") {
font_editor = s;
font_editor_height = h;
} else if (t == "tabs") {
font_tabs = s;
font_tabs_height = h;
} else if (t == "debug") {
font_debug = s;
font_debug_height = h;
2014-01-31 08:23:00 +13:00
}
2019-01-18 17:04:34 +01:00
} else if (t.substr(0, 4) == "rgb_") {
t = t.substr(4);
string s;
in >> s;
int rgb = 0;
for (int k = 0; k < s.size(); ++k) {
int n = s[k];
rgb = (rgb << 4) | (n <= '9' ? n - '0' : (n & 31) + 9);
2014-01-31 08:23:00 +13:00
}
2019-01-18 17:04:34 +01:00
rgb = SWAPRB(rgb);
if (t == "bkgrnd")
rgb_bkgrnd = rgb;
else if (t == "string")
rgb_string = rgb;
else if (t == "ident")
rgb_ident = rgb;
else if (t == "keyword")
rgb_keyword = rgb;
else if (t == "comment")
rgb_comment = rgb;
else if (t == "digit")
rgb_digit = rgb;
else if (t == "default")
rgb_default = rgb;
} else if (t == "edit_tabs") {
in >> edit_tabs;
} else if (t == "edit_blkcursor") {
in >> edit_blkcursor;
} else if (t == "edit_backup") {
in >> edit_backup;
} else if (t == "img_toolbar") {
getline(in, img_toolbar);
} else if (t == "cmd_line") {
getline(in, cmd_line);
} else if (t == "file_recent") {
string l;
getline(in, l);
if (recentFiles.size() < 10)
recentFiles.push_back(l);
} else {
string s = "Unrecognized option '" + t + "' in blitzide.prefs";
MessageBox(0, s.c_str(), "Error in preferences", MB_OK);
2014-01-31 08:23:00 +13:00
setDefault();
return;
}
}
createFonts();
}
2019-01-18 17:04:34 +01:00
void Prefs::close()
{
ofstream out((homeDir + "cfg\\blitzide.prefs").c_str());
if (!out.good())
return;
out << "prg_debug\t" << prg_debug << endl;
out << "prg_lastbuild\t" << prg_lastbuild << endl;
out << "win_maximized\t" << win_maximized << endl;
out << "win_notoolbar\t" << win_notoolbar << endl;
out << "win_rect\t" << win_rect.left << ' ' << win_rect.top << ' ' << win_rect.right << ' ' << win_rect.bottom
<< endl;
out << "font_editor\t" << font_editor << ' ' << font_editor_height << endl;
out << "font_tabs\t" << font_tabs << ' ' << font_tabs_height << endl;
out << "font_debug\t" << font_debug << ' ' << font_debug_height << endl;
out << hex;
out << "rgb_bkgrnd\t" << SWAPRB(rgb_bkgrnd) << endl;
out << "rgb_string\t" << SWAPRB(rgb_string) << endl;
out << "rgb_ident\t" << SWAPRB(rgb_ident) << endl;
out << "rgb_keyword\t" << SWAPRB(rgb_keyword) << endl;
out << "rgb_comment\t" << SWAPRB(rgb_comment) << endl;
out << "rgb_digit\t" << SWAPRB(rgb_digit) << endl;
out << "rgb_default\t" << SWAPRB(rgb_default) << endl;
out << "edit_tabs\t" << edit_tabs << endl;
out << "edit_blkcursor\t" << edit_blkcursor << endl;
out << "edit_backup\t" << edit_backup << endl;
out << "img_toolbar\t" << img_toolbar << endl;
out << "cmd_line\t" << cmd_line << endl;
for (int k = 0; k < recentFiles.size(); ++k) {
out << "file_recent\t" << recentFiles[k] << endl;
2014-01-31 08:23:00 +13:00
}
2019-01-18 17:04:34 +01:00
out << dec;
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:34 +01:00
RemoveFontResource((homeDir + "cfg\\blitz.fon").c_str());
2014-01-31 08:23:00 +13:00
}
2019-01-18 17:04:34 +01:00
void Prefs::setDefault()
{
prg_debug = true;
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:34 +01:00
win_rect.left = win_rect.top = 0;
win_rect.right = 640;
win_rect.bottom = 480;
win_maximized = false;
win_notoolbar = false;
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:34 +01:00
font_editor = "blitz";
font_editor_height = 12;
font_tabs = "verdana";
font_tabs_height = 8;
font_debug = "verdana";
font_debug_height = 8;
2014-01-31 08:23:00 +13:00
#ifdef PRO
2019-01-18 17:04:34 +01:00
rgb_bkgrnd = RGB(0x22, 0x55, 0x88);
rgb_string = RGB(0x00, 0xff, 0x66);
rgb_ident = RGB(0xff, 0xff, 0xff);
rgb_keyword = RGB(0xaa, 0xff, 0xff);
rgb_comment = RGB(0xff, 0xee, 0x00);
rgb_digit = RGB(0x33, 0xff, 0xdd);
rgb_default = RGB(0xee, 0xee, 0xee);
rgb_unsel = RGB(0x88, 0x88, 0x88);
2014-01-31 08:23:00 +13:00
#else
2019-01-18 17:04:34 +01:00
rgb_bkgrnd = RGB(32, 96, 96);
rgb_string = RGB(0, 255, 0);
rgb_ident = RGB(255, 255, 255);
rgb_keyword = RGB(255, 231, 95);
rgb_comment = RGB(0, 255, 255);
rgb_digit = RGB(200, 240, 255);
rgb_default = RGB(255, 240, 200);
2014-01-31 08:23:00 +13:00
#endif
2019-01-18 17:04:34 +01:00
edit_tabs = 4;
edit_blkcursor = false;
edit_backup = 2;
2014-01-31 08:23:00 +13:00
2019-01-18 17:04:34 +01:00
img_toolbar = "toolbar.bmp";
2014-01-31 08:23:00 +13:00
recentFiles.clear();
createFonts();
}
2019-01-18 17:04:34 +01:00
void Prefs::createFonts()
{
2014-01-31 08:23:00 +13:00
editFont.Detach();
tabsFont.Detach();
debugFont.Detach();
conFont.Detach();
2019-01-18 17:04:34 +01:00
editFont.CreatePointFont(font_editor_height * 10, font_editor.c_str());
tabsFont.CreatePointFont(font_tabs_height * 10, font_tabs.c_str());
debugFont.CreatePointFont(font_debug_height * 10, font_debug.c_str());
conFont.CreatePointFont(80, "courier");
2014-01-31 08:23:00 +13:00
}