Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-non-chip8-support' into dev-…
Browse files Browse the repository at this point in the history
…non-chip8-support
  • Loading branch information
gulrak committed Mar 23, 2024
2 parents 8d19428 + 646775c commit 012ed81
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 75 deletions.
66 changes: 32 additions & 34 deletions external/rlguipp/rlguipp4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,43 +417,41 @@ struct GuiContext
}
}
}
static void handleDeferredDropBox(int*const & active, DropdownInfo& info)
{
if (info.lastDraw < info.lastUpdate && info.lastUpdate == frameId) {
for (int i = 0; i < RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED; ++i) {
SetStyle(DROPDOWNBOX, i, info.style[i]);
}
auto oldState = GuiGetState();
if(info.guiDisabled)
GuiDisable();
if (info.directionUp ? GuiDropupBox(info.rect, info.text.c_str(), active, info.editMode) : GuiDropdownBox(info.rect, info.text.c_str(), active, info.editMode)) {
if (openDropdownboxId != active) {
closeOpenDropdownBox();
}
info.clicked = info.editMode;
info.editMode = !info.editMode;
openDropdownboxId = info.editMode ? active : nullptr;
}
else {
info.clicked = false;
}
if(info.guiDisabled)
GuiEnable();
info.lastDraw = info.lastUpdate;
}
}
static void handleDeferredDropBoxes()
{
for (auto& [active, info] : dropdownBoxes) {
if (info.lastDraw < info.lastUpdate && info.lastUpdate == frameId) {
for (int i = 0; i < RAYGUI_MAX_PROPS_BASE + RAYGUI_MAX_PROPS_EXTENDED; ++i) {
SetStyle(DROPDOWNBOX, i, info.style[i]);
}
/*auto r = info.rect;
auto r2 = r;
bool shifted = false;
if(info.editMode) {
auto count = std::count_if( info.text.begin(), info.text.end(), []( char c ){return c ==';';}) + 2;
if(r.y + count*r.height > 192*2+36) {
r.y = 192*2+36 - count*r.height - 4;
r2 = r;
r2.height = 192*2+36 - count*r.height;
shifted = true;
}
}
bool wasEdit = info.editMode;*/
auto oldState = GuiGetState();
if(info.guiDisabled)
GuiDisable();
if (info.directionUp ? GuiDropupBox(info.rect, info.text.c_str(), active, info.editMode) : GuiDropdownBox(info.rect, info.text.c_str(), active, info.editMode)) {
if (openDropdownboxId != active) {
closeOpenDropdownBox();
}
info.clicked = info.editMode;
info.editMode = !info.editMode;
openDropdownboxId = info.editMode ? active : nullptr;
}
else {
info.clicked = false;
}
if(info.guiDisabled)
GuiEnable();
info.lastDraw = info.lastUpdate;
if(!info.editMode) {
handleDeferredDropBox(active, info);
}
}
for (auto& [active, info] : dropdownBoxes) {
if(info.editMode) {
handleDeferredDropBox(active, info);
}
}
if(!GuiContext::tooltipText.empty()) {
Expand Down
1 change: 1 addition & 0 deletions src/emulation/chip8vip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Chip8VIP::Private {
case Cdp186x::eCDP1861:
default:
_properties[PROP_VIDEO].setSelectedIndex(0);
_properties[PROP_AUDIO].setSelectedIndex(0);
break;
}
}
Expand Down
29 changes: 26 additions & 3 deletions src/emulation/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,38 @@
namespace emu {

std::map<std::string_view,Properties> Properties::propertyRegistry{};
std::unordered_map<std::string,std::string> Properties::registeredKeys{};
std::unordered_map<std::string,std::string> Properties::registeredJsonKeys{};


Property::Property(std::string name, Value val, std::string additionalInfo, bool isReadOnly)
: _name(name)
, _jsonKey(Properties::makeJsonKey(name))
, _value(val)
, _additionalInfo(additionalInfo)
, _isReadonly(isReadOnly)
{}

Property::Property(std::string name, Value val, bool isReadOnly)
: _name(name)
, _jsonKey(Properties::makeJsonKey(name))
, _value(val)
, _isReadonly(isReadOnly)
{}

Property::Property(const Property& other)
: _name(other._name)
, _jsonKey(other._jsonKey)
, _value(other._value)
, _additionalInfo(other._additionalInfo)
, _isReadonly(other._isReadonly)
{
}

void to_json(nlohmann::json& j, const Properties& props)
{
j = nlohmann::json::object();
for(size_t i = 0; i < props.numProperties(); ++i) {
const auto& prop = props[i];
auto name = Properties::makeJsonKey(prop.getName());
const auto& name = prop.getJsonKey();
std::visit(emu::visitor{
[&](nullptr_t) { },
[&](bool val) { j[name] = val; },
Expand Down
31 changes: 6 additions & 25 deletions src/emulation/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,12 @@ class Property
};
using Value = std::variant<nullptr_t,bool,Integer,std::string,Combo>;

Property(std::string name, Value val, std::string additionalInfo, bool isReadOnly = true)
: _name(name)
, _value(val)
, _additionalInfo(additionalInfo)
, _isReadonly(isReadOnly)
{}
Property(std::string name, Value val, bool isReadOnly = true)
: _name(name)
, _value(val)
, _isReadonly(isReadOnly)
{}
Property(const Property& other)
: _name(other._name)
, _value(other._value)
, _additionalInfo(other._additionalInfo)
, _isReadonly(other._isReadonly)
{
}
Property(std::string name, Value val, std::string additionalInfo, bool isReadOnly = true);
Property(std::string name, Value val, bool isReadOnly = true);
Property(const Property& other);
const std::string& getName() const { return _name; }
const std::string& getJsonKey() const { return _jsonKey; }
void setJsonKey(const std::string& jsonKey) { _jsonKey = jsonKey; }
const std::string& getAdditionalInfo() const { return _additionalInfo; }
void setAdditionalInfo(std::string info) { _additionalInfo = std::move(info); }
bool isReadonly() const { return _isReadonly; }
Expand Down Expand Up @@ -139,6 +126,7 @@ class Property
}
private:
std::string _name;
std::string _jsonKey;
Value _value;
std::string _additionalInfo;
bool _isReadonly{true};
Expand All @@ -152,7 +140,6 @@ class Properties {
{
auto iter = _valueMap.find(prop.getName());
if(iter == _valueMap.end()) {
registerKey(prop.getName());
_valueList.push_back(prop.getName());
_valueMap.emplace(prop.getName(), prop);
}
Expand Down Expand Up @@ -245,12 +232,6 @@ class Properties {
}
return key;
}
inline static void registerKey(const std::string& key)
{
auto jsonKey = makeJsonKey(key);
registeredKeys[key] = jsonKey;
registeredJsonKeys[jsonKey] = key;
}
private:
std::vector<std::string> _valueList;
std::map<std::string, Property> _valueMap;
Expand Down
13 changes: 0 additions & 13 deletions tools/c8db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ static bool platformMatchesOptions(const c8db::Platform& platform, const emu::Ch
return false;
}

template<typename Iter>
std::string join(Iter first, Iter last, const std::string& delimiter)
{
std::ostringstream result;
for (Iter i = first; i != last; ++i) {
if (i != first) {
result << delimiter;
}
result << *i;
}
return result.str();
}


int main(int argc, char* argv[])
{
Expand Down

0 comments on commit 012ed81

Please sign in to comment.