
This commit mostly just changes the settings code to be in line with the rest of the platform abstractions, although it also fixes some settings names to be consistent with others, and uses native bool types where applicable. This commit also makes settings-related operations much less wasteful, not that it should matter.
74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
//-----------------------------------------------------------------------------
|
|
// Platform-dependent GUI functionality that has only minor differences.
|
|
//
|
|
// Copyright 2018 whitequark
|
|
//-----------------------------------------------------------------------------
|
|
#include "solvespace.h"
|
|
|
|
namespace SolveSpace {
|
|
namespace Platform {
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Keyboard events
|
|
//-----------------------------------------------------------------------------
|
|
|
|
std::string AcceleratorDescription(const KeyboardEvent &accel) {
|
|
std::string label;
|
|
if(accel.controlDown) {
|
|
#ifdef __APPLE__
|
|
label += "⌘+";
|
|
#else
|
|
label += "Ctrl+";
|
|
#endif
|
|
}
|
|
|
|
if(accel.shiftDown) {
|
|
label += "Shift+";
|
|
}
|
|
|
|
switch(accel.key) {
|
|
case KeyboardEvent::Key::FUNCTION:
|
|
label += ssprintf("F%d", accel.num);
|
|
break;
|
|
|
|
case KeyboardEvent::Key::CHARACTER:
|
|
if(accel.chr == '\t') {
|
|
label += "Tab";
|
|
} else if(accel.chr == ' ') {
|
|
label += "Space";
|
|
} else if(accel.chr == '\x1b') {
|
|
label += "Esc";
|
|
} else if(accel.chr == '\x7f') {
|
|
label += "Del";
|
|
} else if(accel.chr != 0) {
|
|
label += toupper((char)(accel.chr & 0xff));
|
|
}
|
|
break;
|
|
}
|
|
|
|
return label;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Settings
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void Settings::FreezeBool(const std::string &key, bool value) {
|
|
FreezeInt(key, (int)value);
|
|
}
|
|
|
|
bool Settings::ThawBool(const std::string &key, bool defaultValue) {
|
|
return (bool)ThawInt(key, (int)defaultValue);
|
|
}
|
|
|
|
void Settings::FreezeColor(const std::string &key, RgbaColor value) {
|
|
FreezeInt(key, value.ToPackedInt());
|
|
}
|
|
|
|
RgbaColor Settings::ThawColor(const std::string &key, RgbaColor defaultValue) {
|
|
return RgbaColor::FromPackedInt(ThawInt(key, defaultValue.ToPackedInt()));
|
|
}
|
|
|
|
}
|
|
}
|