track-width fixes
This commit is contained in:
parent
788bd6bf0f
commit
167388aefb
@ -1,7 +1,7 @@
|
|||||||
<panel size='400' color='0' padding='8'>
|
<panel size='400' color='0' padding='8'>
|
||||||
<label id='sensitivity_label'>-</label>
|
<label id='sensitivity_label'>-</label>
|
||||||
<trackbar id='sensitivity_track'
|
<trackbar id='sensitivity_track'
|
||||||
min='0.1' max='10' value='2' step='0.1' track-width='4'
|
min='0.1' max='10' value='2' step='0.1'
|
||||||
consumer='change_sensitivity'>
|
consumer='change_sensitivity'>
|
||||||
</trackbar>
|
</trackbar>
|
||||||
<panel id='bindings_panel' size='380,200' padding='2' interval='1' max-length='400' color='#0000004C'>
|
<panel id='bindings_panel' size='380,200' padding='2' interval='1' max-length='400' color='#0000004C'>
|
||||||
|
|||||||
@ -10,7 +10,6 @@ function create_setting(id, name, step, postfix)
|
|||||||
min=info.min,
|
min=info.min,
|
||||||
max=info.max,
|
max=info.max,
|
||||||
step=step,
|
step=step,
|
||||||
track_width=12,
|
|
||||||
postfix=postfix
|
postfix=postfix
|
||||||
}))
|
}))
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,7 +11,7 @@ function new_volume_control(setting, id, name)
|
|||||||
document.tracks_panel:add("<label id='l_"..id.."'>-</label>")
|
document.tracks_panel:add("<label id='l_"..id.."'>-</label>")
|
||||||
-- value track-bar
|
-- value track-bar
|
||||||
document.tracks_panel:add(string.format(
|
document.tracks_panel:add(string.format(
|
||||||
"<trackbar id='t_%s' min='0' max='1' value='%s' step='0.01' track-width='5' "..
|
"<trackbar id='t_%s' min='0' max='1' value='%s' step='0.01' "..
|
||||||
" consumer='function(x) on_volume_change(%q, %q, %q, x) end'/>"
|
" consumer='function(x) on_volume_change(%q, %q, %q, x) end'/>"
|
||||||
, id, core.get_setting(setting), setting, id, name))
|
, id, core.get_setting(setting), setting, id, name))
|
||||||
refresh_label(setting, id, name)
|
refresh_label(setting, id, name)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
<panel color='0' context='settings'>
|
<panel color='0' context='settings'>
|
||||||
<label id='%{id}.L'>%{name}: %{value}%{postfix}</label>
|
<label id='%{id}.L'>%{name}: %{value}%{postfix}</label>
|
||||||
<trackbar
|
<trackbar
|
||||||
value='%{value}' min='%{min}' max='%{max}'
|
value='%{value}' min='%{min}' max='%{max}' step='%{step}'
|
||||||
step='%{step}' track-width="%{track_width}"
|
|
||||||
consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/>
|
consumer='function(x) update_setting(x, "%{id}", "%{name}", "%{postfix}") end'/>
|
||||||
</panel>
|
</panel>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "toml.h"
|
#include "toml.h"
|
||||||
#include "commons.h"
|
#include "commons.h"
|
||||||
|
#include "../data/setting.hpp"
|
||||||
#include "../data/dynamic.h"
|
#include "../data/dynamic.h"
|
||||||
#include "../util/stringutil.h"
|
#include "../util/stringutil.h"
|
||||||
#include "../files/settings_io.hpp"
|
#include "../files/settings_io.hpp"
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include "../coders/toml.h"
|
#include "../coders/toml.h"
|
||||||
#include "../coders/json.h"
|
#include "../coders/json.h"
|
||||||
#include "../debug/Logger.hpp"
|
#include "../debug/Logger.hpp"
|
||||||
|
#include "../settings.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -166,44 +167,3 @@ void SettingsHandler::setValue(const std::string& name, const dynamic::Value& va
|
|||||||
std::vector<Section>& SettingsHandler::getSections() {
|
std::vector<Section>& SettingsHandler::getSections() {
|
||||||
return sections;
|
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_
|
#ifndef FILES_SETTINGS_IO_HPP_
|
||||||
#define FILES_SETTINGS_IO_HPP_
|
#define FILES_SETTINGS_IO_HPP_
|
||||||
|
|
||||||
|
#include "../data/dynamic.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "../settings.h"
|
|
||||||
#include "../data/dynamic.h"
|
class Setting;
|
||||||
|
struct EngineSettings;
|
||||||
|
|
||||||
struct Section {
|
struct Section {
|
||||||
std::string name;
|
std::string name;
|
||||||
@ -27,8 +30,4 @@ public:
|
|||||||
std::vector<Section>& getSections();
|
std::vector<Section>& getSections();
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string write_controls();
|
|
||||||
|
|
||||||
void load_controls(std::string filename, std::string source);
|
|
||||||
|
|
||||||
#endif // FILES_SETTINGS_IO_HPP_
|
#endif // FILES_SETTINGS_IO_HPP_
|
||||||
|
|||||||
@ -19,7 +19,7 @@ namespace gui {
|
|||||||
double max,
|
double max,
|
||||||
double value,
|
double value,
|
||||||
double step=1.0,
|
double step=1.0,
|
||||||
int trackWidth=1);
|
int trackWidth=12);
|
||||||
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
virtual void draw(const GfxContext* pctx, Assets* assets) override;
|
||||||
|
|
||||||
virtual void setSupplier(doublesupplier supplier);
|
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 max = element->attr("max", "1.0").asFloat();
|
||||||
float def = element->attr("value", "0.0").asFloat();
|
float def = element->attr("value", "0.0").asFloat();
|
||||||
float step = element->attr("step", "1.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);
|
auto bar = std::make_shared<TrackBar>(min, max, def, step, trackWidth);
|
||||||
_readUINode(reader, element, *bar);
|
_readUINode(reader, element, *bar);
|
||||||
if (element->has("consumer")) {
|
if (element->has("consumer")) {
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "files/engine_paths.h"
|
#include "files/engine_paths.h"
|
||||||
#include "util/platform.h"
|
#include "util/platform.h"
|
||||||
#include "util/command_line.hpp"
|
#include "util/command_line.hpp"
|
||||||
|
#include "window/Events.h"
|
||||||
#include "debug/Logger.hpp"
|
#include "debug/Logger.hpp"
|
||||||
|
|
||||||
inline std::string SETTINGS_FILE = "settings.toml";
|
inline std::string SETTINGS_FILE = "settings.toml";
|
||||||
@ -47,13 +48,13 @@ int main(int argc, char** argv) {
|
|||||||
if (fs::is_regular_file(controls_file)) {
|
if (fs::is_regular_file(controls_file)) {
|
||||||
logger.info() << "loading controls";
|
logger.info() << "loading controls";
|
||||||
std::string text = files::read_string(controls_file);
|
std::string text = files::read_string(controls_file);
|
||||||
load_controls(controls_file.string(), text);
|
Events::loadBindings(controls_file.string(), text);
|
||||||
}
|
}
|
||||||
engine.mainloop();
|
engine.mainloop();
|
||||||
|
|
||||||
logger.info() << "saving settings";
|
logger.info() << "saving settings";
|
||||||
files::write_string(settings_file, toml::stringify(handler));
|
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) {
|
catch (const initialize_error& err) {
|
||||||
logger.error() << "could not to initialize engine\n" << err.what();
|
logger.error() << "could not to initialize engine\n" << err.what();
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
#include <iostream>
|
|
||||||
#include "Events.h"
|
#include "Events.h"
|
||||||
|
#include "../debug/Logger.hpp"
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static debug::Logger logger("events");
|
||||||
|
|
||||||
inline constexpr short _MOUSE_KEYS_OFFSET = 1024;
|
inline constexpr short _MOUSE_KEYS_OFFSET = 1024;
|
||||||
|
|
||||||
bool Events::keys[KEYS_BUFFER_SIZE] = {};
|
bool Events::keys[KEYS_BUFFER_SIZE] = {};
|
||||||
@ -141,3 +144,47 @@ void Events::setPosition(float xpos, float ypos) {
|
|||||||
Events::cursor.x = xpos;
|
Events::cursor.x = xpos;
|
||||||
Events::cursor.y = ypos;
|
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 setButton(int button, bool b);
|
||||||
|
|
||||||
static void setPosition(float xpos, float ypos);
|
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_ */
|
#endif /* WINDOW_EVENTS_H_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user