track-width fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "toml.h"
|
||||
#include "commons.h"
|
||||
#include "../data/setting.hpp"
|
||||
#include "../data/dynamic.h"
|
||||
#include "../util/stringutil.h"
|
||||
#include "../files/settings_io.hpp"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../coders/toml.h"
|
||||
#include "../coders/json.h"
|
||||
#include "../debug/Logger.hpp"
|
||||
#include "../settings.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -166,44 +167,3 @@ void SettingsHandler::setValue(const std::string& name, const dynamic::Value& va
|
||||
std::vector<Section>& SettingsHandler::getSections() {
|
||||
return sections;
|
||||
}
|
||||
|
||||
std::string write_controls() {
|
||||
dynamic::Map obj;
|
||||
for (auto& entry : Events::bindings) {
|
||||
const auto& binding = entry.second;
|
||||
|
||||
auto& jentry = obj.putMap(entry.first);
|
||||
switch (binding.type) {
|
||||
case inputtype::keyboard: jentry.put("type", "keyboard"); break;
|
||||
case inputtype::mouse: jentry.put("type", "mouse"); break;
|
||||
default: throw std::runtime_error("unsupported control type");
|
||||
}
|
||||
jentry.put("code", binding.code);
|
||||
}
|
||||
return json::stringify(&obj, true, " ");
|
||||
}
|
||||
|
||||
void load_controls(std::string filename, std::string source) {
|
||||
auto obj = json::parse(filename, source);
|
||||
for (auto& entry : Events::bindings) {
|
||||
auto& binding = entry.second;
|
||||
|
||||
auto jentry = obj->map(entry.first);
|
||||
if (jentry == nullptr)
|
||||
continue;
|
||||
inputtype type;
|
||||
std::string typestr;
|
||||
jentry->str("type", typestr);
|
||||
|
||||
if (typestr == "keyboard") {
|
||||
type = inputtype::keyboard;
|
||||
} else if (typestr == "mouse") {
|
||||
type = inputtype::mouse;
|
||||
} else {
|
||||
logger.error() << "unknown input type '" << typestr << "'";
|
||||
continue;
|
||||
}
|
||||
binding.type = type;
|
||||
jentry->num("code", binding.code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
#ifndef FILES_SETTINGS_IO_HPP_
|
||||
#define FILES_SETTINGS_IO_HPP_
|
||||
|
||||
#include "../data/dynamic.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "../settings.h"
|
||||
#include "../data/dynamic.h"
|
||||
|
||||
class Setting;
|
||||
struct EngineSettings;
|
||||
|
||||
struct Section {
|
||||
std::string name;
|
||||
@@ -27,8 +30,4 @@ public:
|
||||
std::vector<Section>& getSections();
|
||||
};
|
||||
|
||||
std::string write_controls();
|
||||
|
||||
void load_controls(std::string filename, std::string source);
|
||||
|
||||
#endif // FILES_SETTINGS_IO_HPP_
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace gui {
|
||||
double max,
|
||||
double value,
|
||||
double step=1.0,
|
||||
int trackWidth=1);
|
||||
int trackWidth=12);
|
||||
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
||||
|
||||
virtual void setSupplier(doublesupplier supplier);
|
||||
|
||||
@@ -351,7 +351,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
||||
float max = element->attr("max", "1.0").asFloat();
|
||||
float def = element->attr("value", "0.0").asFloat();
|
||||
float step = element->attr("step", "1.0").asFloat();
|
||||
int trackWidth = element->attr("track-width", "1.0").asInt();
|
||||
int trackWidth = element->attr("track-width", "12.0").asInt();
|
||||
auto bar = std::make_shared<TrackBar>(min, max, def, step, trackWidth);
|
||||
_readUINode(reader, element, *bar);
|
||||
if (element->has("consumer")) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "files/engine_paths.h"
|
||||
#include "util/platform.h"
|
||||
#include "util/command_line.hpp"
|
||||
#include "window/Events.h"
|
||||
#include "debug/Logger.hpp"
|
||||
|
||||
inline std::string SETTINGS_FILE = "settings.toml";
|
||||
@@ -47,13 +48,13 @@ int main(int argc, char** argv) {
|
||||
if (fs::is_regular_file(controls_file)) {
|
||||
logger.info() << "loading controls";
|
||||
std::string text = files::read_string(controls_file);
|
||||
load_controls(controls_file.string(), text);
|
||||
Events::loadBindings(controls_file.string(), text);
|
||||
}
|
||||
engine.mainloop();
|
||||
|
||||
logger.info() << "saving settings";
|
||||
files::write_string(settings_file, toml::stringify(handler));
|
||||
files::write_string(controls_file, write_controls());
|
||||
files::write_string(controls_file, Events::writeBindings());
|
||||
}
|
||||
catch (const initialize_error& err) {
|
||||
logger.error() << "could not to initialize engine\n" << err.what();
|
||||
|
||||
+48
-1
@@ -1,9 +1,12 @@
|
||||
#include <iostream>
|
||||
#include "Events.h"
|
||||
#include "../debug/Logger.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <string.h>
|
||||
|
||||
static debug::Logger logger("events");
|
||||
|
||||
inline constexpr short _MOUSE_KEYS_OFFSET = 1024;
|
||||
|
||||
bool Events::keys[KEYS_BUFFER_SIZE] = {};
|
||||
@@ -141,3 +144,47 @@ void Events::setPosition(float xpos, float ypos) {
|
||||
Events::cursor.x = xpos;
|
||||
Events::cursor.y = ypos;
|
||||
}
|
||||
|
||||
#include "../data/dynamic.h"
|
||||
#include "../coders/json.h"
|
||||
|
||||
std::string Events::writeBindings() {
|
||||
dynamic::Map obj;
|
||||
for (auto& entry : Events::bindings) {
|
||||
const auto& binding = entry.second;
|
||||
|
||||
auto& jentry = obj.putMap(entry.first);
|
||||
switch (binding.type) {
|
||||
case inputtype::keyboard: jentry.put("type", "keyboard"); break;
|
||||
case inputtype::mouse: jentry.put("type", "mouse"); break;
|
||||
default: throw std::runtime_error("unsupported control type");
|
||||
}
|
||||
jentry.put("code", binding.code);
|
||||
}
|
||||
return json::stringify(&obj, true, " ");
|
||||
}
|
||||
|
||||
void Events::loadBindings(const std::string& filename, const std::string& source) {
|
||||
auto obj = json::parse(filename, source);
|
||||
for (auto& entry : Events::bindings) {
|
||||
auto& binding = entry.second;
|
||||
|
||||
auto jentry = obj->map(entry.first);
|
||||
if (jentry == nullptr)
|
||||
continue;
|
||||
inputtype type;
|
||||
std::string typestr;
|
||||
jentry->str("type", typestr);
|
||||
|
||||
if (typestr == "keyboard") {
|
||||
type = inputtype::keyboard;
|
||||
} else if (typestr == "mouse") {
|
||||
type = inputtype::mouse;
|
||||
} else {
|
||||
logger.error() << "unknown input type '" << typestr << "'";
|
||||
continue;
|
||||
}
|
||||
binding.type = type;
|
||||
jentry->num("code", binding.code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
static void setButton(int button, bool b);
|
||||
|
||||
static void setPosition(float xpos, float ypos);
|
||||
|
||||
static std::string writeBindings();
|
||||
static void loadBindings(const std::string& filename, const std::string& source);
|
||||
};
|
||||
|
||||
#endif /* WINDOW_EVENTS_H_ */
|
||||
|
||||
Reference in New Issue
Block a user