2016-07-26 03:37:48 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-11-29 10:57:41 +08:00
|
|
|
// Our platform support functions for the headless (no OpenGL) test runner.
|
2016-07-26 03:37:48 +08:00
|
|
|
//
|
|
|
|
// Copyright 2016 whitequark
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#include "solvespace.h"
|
|
|
|
#include <cairo.h>
|
|
|
|
|
|
|
|
namespace SolveSpace {
|
|
|
|
|
2018-07-13 03:29:44 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Rendering
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::shared_ptr<ViewportCanvas> CreateRenderer() {
|
|
|
|
return std::make_shared<CairoPixmapRenderer>();
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:35:31 +08:00
|
|
|
namespace Platform {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Timers
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TimerImplDummy : public Timer {
|
|
|
|
public:
|
|
|
|
void WindUp(unsigned milliseconds) override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
TimerRef CreateTimer() {
|
|
|
|
return std::unique_ptr<Timer>(new TimerImplDummy);
|
|
|
|
}
|
|
|
|
|
2018-07-11 18:48:38 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Menus
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MenuRef CreateMenu() {
|
2018-07-13 03:29:44 +08:00
|
|
|
return std::shared_ptr<Menu>();
|
2018-07-11 18:48:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuBarRef GetOrCreateMainMenu(bool *unique) {
|
|
|
|
*unique = false;
|
2018-07-13 03:29:44 +08:00
|
|
|
return std::shared_ptr<MenuBar>();
|
2018-07-11 18:48:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-13 03:29:44 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Windows
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
WindowRef CreateWindow(Window::Kind kind, WindowRef parentWindow) {
|
|
|
|
return std::shared_ptr<Window>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Application-wide APIs
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Exit() {
|
|
|
|
exit(0);
|
2018-07-11 18:48:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-11 13:35:31 +08:00
|
|
|
}
|
|
|
|
|
2016-07-26 03:37:48 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Settings
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Setting {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
Undefined,
|
|
|
|
Int,
|
|
|
|
Float,
|
|
|
|
String
|
|
|
|
};
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
int valueInt;
|
|
|
|
float valueFloat;
|
|
|
|
std::string valueString;
|
|
|
|
|
|
|
|
void CheckType(Type expectedType) {
|
|
|
|
ssassert(type == Setting::Type::Undefined ||
|
|
|
|
type == expectedType, "Wrong setting type");
|
|
|
|
type = expectedType;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, Setting> settings;
|
|
|
|
|
|
|
|
void CnfFreezeInt(uint32_t val, const std::string &key) {
|
|
|
|
Setting &setting = settings[key];
|
|
|
|
setting.CheckType(Setting::Type::Int);
|
|
|
|
setting.valueInt = val;
|
|
|
|
}
|
|
|
|
uint32_t CnfThawInt(uint32_t val, const std::string &key) {
|
|
|
|
if(settings.find(key) != settings.end()) {
|
|
|
|
Setting &setting = settings[key];
|
|
|
|
setting.CheckType(Setting::Type::Int);
|
|
|
|
val = setting.valueInt;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CnfFreezeFloat(float val, const std::string &key) {
|
|
|
|
Setting &setting = settings[key];
|
|
|
|
setting.CheckType(Setting::Type::Float);
|
|
|
|
setting.valueFloat = val;
|
|
|
|
}
|
|
|
|
float CnfThawFloat(float val, const std::string &key) {
|
|
|
|
if(settings.find(key) != settings.end()) {
|
|
|
|
Setting &setting = settings[key];
|
|
|
|
setting.CheckType(Setting::Type::Float);
|
|
|
|
val = setting.valueFloat;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CnfFreezeString(const std::string &val, const std::string &key) {
|
|
|
|
Setting &setting = settings[key];
|
|
|
|
setting.CheckType(Setting::Type::String);
|
|
|
|
setting.valueString = val;
|
|
|
|
}
|
|
|
|
std::string CnfThawString(const std::string &val, const std::string &key) {
|
|
|
|
std::string ret = val;
|
|
|
|
if(settings.find(key) != settings.end()) {
|
|
|
|
Setting &setting = settings[key];
|
|
|
|
setting.CheckType(Setting::Type::String);
|
|
|
|
ret = setting.valueString;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Dialogs
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
bool GetOpenFile(Platform::Path *filename, const std::string &activeOrEmpty,
|
2016-07-26 03:37:48 +08:00
|
|
|
const FileFilter filters[]) {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
2017-03-11 22:43:21 +08:00
|
|
|
bool GetSaveFile(Platform::Path *filename, const std::string &activeOrEmpty,
|
2016-07-26 03:37:48 +08:00
|
|
|
const FileFilter filters[]) {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
DialogChoice SaveFileYesNoCancel() {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
DialogChoice LoadAutosaveYesNo() {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
2017-03-11 22:43:21 +08:00
|
|
|
DialogChoice LocateImportedFileYesNoCancel(const Platform::Path &filename,
|
2016-07-26 03:37:48 +08:00
|
|
|
bool canCancel) {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void DoMessageBox(const char *message, int rows, int cols, bool error) {
|
|
|
|
dbp("%s box: %s", error ? "error" : "message", message);
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void OpenWebsite(const char *url) {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Resources
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-03-11 22:43:21 +08:00
|
|
|
std::vector<Platform::Path> fontFiles;
|
|
|
|
std::vector<Platform::Path> GetFontFiles() {
|
2016-07-31 16:43:33 +08:00
|
|
|
return fontFiles;
|
2016-07-26 03:37:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|