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 {
|
|
|
|
|
2018-07-17 20:32:58 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Fatal errors
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FatalError(std::string message) {
|
|
|
|
fprintf(stderr, "%s", message.c_str());
|
|
|
|
|
|
|
|
#if !defined(LIBRARY) && defined(HAVE_BACKTRACE)
|
|
|
|
static void *ptrs[1024] = {};
|
|
|
|
size_t nptrs = backtrace(ptrs, sizeof(ptrs) / sizeof(ptrs[0]));
|
|
|
|
char **syms = backtrace_symbols(ptrs, nptrs);
|
|
|
|
|
|
|
|
fprintf(stderr, "Backtrace:\n");
|
|
|
|
if(syms != NULL) {
|
|
|
|
for(size_t i = 0; i < nptrs; i++) {
|
|
|
|
fprintf(stderr, "%2zu: %s\n", i, syms[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(size_t i = 0; i < nptrs; i++) {
|
|
|
|
fprintf(stderr, "%2zu: %p\n", i, ptrs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
fprintf(stderr, "Backtrace support not compiled in.\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:37:41 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Settings
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SettingsImplDummy : public Settings {
|
|
|
|
public:
|
|
|
|
void FreezeInt(const std::string &key, uint32_t value) {}
|
|
|
|
|
|
|
|
uint32_t ThawInt(const std::string &key, uint32_t defaultValue = 0) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreezeFloat(const std::string &key, double value) {}
|
|
|
|
|
|
|
|
double ThawFloat(const std::string &key, double defaultValue = 0.0) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreezeString(const std::string &key, const std::string &value) {}
|
|
|
|
|
|
|
|
std::string ThawString(const std::string &key,
|
|
|
|
const std::string &defaultValue = "") {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SettingsRef GetSettings() {
|
|
|
|
static std::shared_ptr<SettingsImplDummy> settings =
|
|
|
|
std::make_shared<SettingsImplDummy>();
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:35:31 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Timers
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TimerImplDummy : public Timer {
|
|
|
|
public:
|
Eliminate imperative redraws.
This commit removes Platform::Window::Redraw function, and rewrites
its uses to run on timer events. Most UI toolkits have obscure issues
with recursive event handling loops, and Emscripten is purely event-
driven and cannot handle imperative redraws at all.
As a part of this change, the Platform::Timer::WindUp function
is split into three to make the interpretation of its argument
less magical. The new functions are RunAfter (a regular timeout,
setTimeout in browser terms), RunAfterNextFrame (an animation
request, requestAnimationFrame in browser terms), and
RunAfterProcessingEvents (a request to run something after all
events for the current frame are processed, used for coalescing
expensive operations in face of input event queues).
This commit changes two uses of Redraw(): the AnimateOnto() and
ScreenStepDimGo() functions. The latter was actually broken in that
on small sketches, it would run very quickly and not animate
the dimension change at all; this has been fixed.
While we're at it, get rid of unused Platform::Window::NativePtr
function as well.
2018-07-19 07:11:49 +08:00
|
|
|
void RunAfter(unsigned milliseconds) override {}
|
2018-07-11 13:35:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TimerRef CreateTimer() {
|
2018-07-19 07:49:51 +08:00
|
|
|
return std::make_shared<TimerImplDummy>();
|
2018-07-11 13:35:31 +08:00
|
|
|
}
|
|
|
|
|
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>();
|
|
|
|
}
|
|
|
|
|
2018-07-18 08:48:49 +08:00
|
|
|
void Request3DConnexionEventsForWindow(WindowRef window) {}
|
|
|
|
|
2018-07-17 23:00:46 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2018-07-18 02:51:00 +08:00
|
|
|
// Message dialogs
|
2018-07-17 23:00:46 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
|
|
|
|
return std::shared_ptr<MessageDialog>();
|
|
|
|
}
|
|
|
|
|
2018-07-18 02:51:00 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// File dialogs
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
FileDialogRef CreateOpenFileDialog(WindowRef parentWindow) {
|
|
|
|
return std::shared_ptr<FileDialog>();
|
|
|
|
}
|
|
|
|
|
|
|
|
FileDialogRef CreateSaveFileDialog(WindowRef parentWindow) {
|
|
|
|
return std::shared_ptr<FileDialog>();
|
|
|
|
}
|
|
|
|
|
2018-07-13 03:29:44 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Application-wide APIs
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-07-18 10:20:25 +08:00
|
|
|
std::vector<Platform::Path> fontFiles;
|
|
|
|
std::vector<Platform::Path> GetFontFiles() {
|
|
|
|
return fontFiles;
|
2018-07-11 18:48:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-18 10:20:25 +08:00
|
|
|
void OpenInBrowser(const std::string &url) {}
|
2018-07-11 13:35:31 +08:00
|
|
|
|
2018-07-18 10:20:25 +08:00
|
|
|
void InitGui(int argc, char **argv) {}
|
2016-07-26 03:37:48 +08:00
|
|
|
|
2018-07-18 10:20:25 +08:00
|
|
|
void RunGui() {}
|
2016-07-26 03:37:48 +08:00
|
|
|
|
2018-07-18 10:20:25 +08:00
|
|
|
void ExitGui() {
|
|
|
|
exit(0);
|
|
|
|
}
|
2016-07-26 03:37:48 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|