mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
dummy widget and widget system
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
#include "components/spine_player.hpp"
|
||||
#include "components/sprite_renderer.hpp"
|
||||
#include "components/touchable.hpp"
|
||||
#include "components/widget.hpp"
|
||||
|
||||
#include "systems/camera_system.hpp"
|
||||
#include "systems/flipbook_system.hpp"
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace e2d
|
||||
class spine_player;
|
||||
class sprite_renderer;
|
||||
class touchable;
|
||||
class widget;
|
||||
|
||||
class camera_system;
|
||||
class flipbook_system;
|
||||
|
||||
75
headers/enduro2d/high/components/widget.hpp
Normal file
75
headers/enduro2d/high/components/widget.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "_components.hpp"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
class widget final {
|
||||
public:
|
||||
widget() = default;
|
||||
|
||||
widget& size(const v2f& value) noexcept;
|
||||
[[nodiscard]] const v2f& size() const noexcept;
|
||||
|
||||
widget& pivot(const v2f& value) noexcept;
|
||||
[[nodiscard]] const v2f& pivot() const noexcept;
|
||||
private:
|
||||
v2f size_ = v2f::zero();
|
||||
v2f pivot_ = v2f::unit() * 0.5f;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
template <>
|
||||
class factory_loader<widget> final : factory_loader<> {
|
||||
public:
|
||||
static const char* schema_source;
|
||||
|
||||
bool operator()(
|
||||
widget& component,
|
||||
const fill_context& ctx) const;
|
||||
|
||||
bool operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
template <>
|
||||
class component_inspector<widget> final : component_inspector<> {
|
||||
public:
|
||||
static const char* title;
|
||||
|
||||
void operator()(gcomponent<widget>& c) const;
|
||||
};
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
inline widget& widget::size(const v2f& value) noexcept {
|
||||
size_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const v2f& widget::size() const noexcept {
|
||||
return size_;
|
||||
}
|
||||
|
||||
inline widget& widget::pivot(const v2f& value) noexcept {
|
||||
pivot_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const v2f& widget::pivot() const noexcept {
|
||||
return pivot_;
|
||||
}
|
||||
}
|
||||
26
headers/enduro2d/high/systems/widget_system.hpp
Normal file
26
headers/enduro2d/high/systems/widget_system.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "_systems.hpp"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
class widget_system final
|
||||
: public ecs::system<ecs::after<systems::update_event>> {
|
||||
public:
|
||||
widget_system();
|
||||
~widget_system() noexcept final;
|
||||
|
||||
void process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::update_event>& trigger) override;
|
||||
private:
|
||||
class internal_state;
|
||||
std::unique_ptr<internal_state> state_;
|
||||
};
|
||||
}
|
||||
25
samples/bin/library/scripts/emmy/components/widget.lua
Normal file
25
samples/bin/library/scripts/emmy/components/widget.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
---@class widget
|
||||
local widget = {
|
||||
---@type boolean
|
||||
enabled = true,
|
||||
|
||||
---@type boolean
|
||||
disabled = false,
|
||||
|
||||
---@type v2f
|
||||
size = v2f.zero(),
|
||||
|
||||
---@type v2f
|
||||
pivot = v2f.unit() * 0.5
|
||||
}
|
||||
|
||||
---@overload fun(self: widget)
|
||||
---@param self widget
|
||||
function widget.enable(self) end
|
||||
|
||||
---@overload fun(self: widget)
|
||||
---@param self widget
|
||||
function widget.disable(self) end
|
||||
|
||||
---@type widget
|
||||
_G.widget = _G.widget or widget
|
||||
@@ -52,7 +52,10 @@ local gobject = {
|
||||
sprite_renderer = nil,
|
||||
|
||||
---@type touchable
|
||||
touchable = nil
|
||||
touchable = nil,
|
||||
|
||||
---@type widget
|
||||
widget = nil
|
||||
}
|
||||
|
||||
---@param self gobject
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace e2d::bindings::high
|
||||
void bind_spine_player(sol::state& l);
|
||||
void bind_sprite_renderer(sol::state& l);
|
||||
void bind_touchable(sol::state& l);
|
||||
void bind_widget(sol::state& l);
|
||||
}
|
||||
|
||||
namespace e2d::bindings
|
||||
@@ -59,5 +60,6 @@ namespace e2d::bindings
|
||||
high::bind_spine_player(l);
|
||||
high::bind_sprite_renderer(l);
|
||||
high::bind_touchable(l);
|
||||
high::bind_widget(l);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../_high_binds.hpp"
|
||||
|
||||
#include <enduro2d/high/gobject.hpp>
|
||||
#include <enduro2d/high/components/disabled.hpp>
|
||||
#include <enduro2d/high/components/widget.hpp>
|
||||
|
||||
namespace e2d::bindings::high
|
||||
{
|
||||
void bind_widget(sol::state& l) {
|
||||
l.new_usertype<gcomponent<widget>>("widget",
|
||||
sol::no_constructor,
|
||||
|
||||
"enable", [](gcomponent<widget>& c){
|
||||
c.owner().component<disabled<widget>>().remove();
|
||||
},
|
||||
|
||||
"disable", [](gcomponent<widget>& c){
|
||||
c.owner().component<disabled<widget>>().ensure();
|
||||
},
|
||||
|
||||
"enabled", sol::property(
|
||||
[](const gcomponent<widget>& c) -> bool {
|
||||
return !c.owner().component<disabled<widget>>().exists();
|
||||
},
|
||||
[](gcomponent<widget>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
c.owner().component<disabled<widget>>().remove();
|
||||
} else {
|
||||
c.owner().component<disabled<widget>>().ensure();
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"disabled", sol::property(
|
||||
[](const gcomponent<widget>& c) -> bool {
|
||||
return c.owner().component<disabled<widget>>().exists();
|
||||
},
|
||||
[](gcomponent<widget>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
c.owner().component<disabled<widget>>().ensure();
|
||||
} else {
|
||||
c.owner().component<disabled<widget>>().remove();
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"size", sol::property(
|
||||
[](const gcomponent<widget>& c) -> v2f {
|
||||
return c->size();
|
||||
},
|
||||
[](gcomponent<widget>& c, const v2f& v){
|
||||
c->size(v);
|
||||
}),
|
||||
|
||||
"pivot", sol::property(
|
||||
[](const gcomponent<widget>& c) -> v2f {
|
||||
return c->pivot();
|
||||
},
|
||||
[](gcomponent<widget>& c, const v2f& v){
|
||||
c->pivot(v);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <enduro2d/high/components/spine_player.hpp>
|
||||
#include <enduro2d/high/components/sprite_renderer.hpp>
|
||||
#include <enduro2d/high/components/touchable.hpp>
|
||||
#include <enduro2d/high/components/widget.hpp>
|
||||
|
||||
namespace e2d::bindings::high
|
||||
{
|
||||
@@ -54,7 +55,8 @@ namespace e2d::bindings::high
|
||||
"scene", sol::property([](gobject& go){ return component_wrapper<scene>{go}; }),
|
||||
"spine_player", sol::property([](gobject& go){ return component_wrapper<spine_player>{go}; }),
|
||||
"sprite_renderer", sol::property([](gobject& go){ return component_wrapper<sprite_renderer>{go}; }),
|
||||
"touchable", sol::property([](gobject& go){ return component_wrapper<touchable>{go}; })
|
||||
"touchable", sol::property([](gobject& go){ return component_wrapper<touchable>{go}; }),
|
||||
"widget", sol::property([](gobject& go){ return component_wrapper<widget>{go}; })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
72
sources/enduro2d/high/components/widget.cpp
Normal file
72
sources/enduro2d/high/components/widget.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <enduro2d/high/components/widget.hpp>
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<widget>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"size" : { "$ref": "#/common_definitions/v2" },
|
||||
"pivot" : { "$ref": "#/common_definitions/v2" }
|
||||
}
|
||||
})json";
|
||||
|
||||
bool factory_loader<widget>::operator()(
|
||||
widget& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
if ( ctx.root.HasMember("size") ) {
|
||||
v2f size = component.size();
|
||||
if ( !json_utils::try_parse_value(ctx.root["size"], size) ) {
|
||||
the<debug>().error("WIDGET: Incorrect formatting of 'size' property");
|
||||
return false;
|
||||
}
|
||||
component.size(size);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("pivot") ) {
|
||||
v2f pivot = component.pivot();
|
||||
if ( !json_utils::try_parse_value(ctx.root["pivot"], pivot) ) {
|
||||
the<debug>().error("WIDGET: Incorrect formatting of 'pivot' property");
|
||||
return false;
|
||||
}
|
||||
component.pivot(pivot);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<widget>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* component_inspector<widget>::title = ICON_FA_VECTOR_SQUARE " widget";
|
||||
|
||||
void component_inspector<widget>::operator()(gcomponent<widget>& c) const {
|
||||
if ( v2f size = c->size();
|
||||
ImGui::DragFloat2("size", size.data(), 1.f) )
|
||||
{
|
||||
c->size(size);
|
||||
}
|
||||
|
||||
if ( v2f pivot = c->pivot();
|
||||
ImGui::DragFloat2("pivot", pivot.data(), 0.01f) )
|
||||
{
|
||||
c->pivot(pivot);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <enduro2d/high/components/spine_player.hpp>
|
||||
#include <enduro2d/high/components/sprite_renderer.hpp>
|
||||
#include <enduro2d/high/components/touchable.hpp>
|
||||
#include <enduro2d/high/components/widget.hpp>
|
||||
|
||||
#include <enduro2d/high/systems/camera_system.hpp>
|
||||
#include <enduro2d/high/systems/flipbook_system.hpp>
|
||||
@@ -41,6 +42,7 @@
|
||||
#include <enduro2d/high/systems/script_system.hpp>
|
||||
#include <enduro2d/high/systems/spine_system.hpp>
|
||||
#include <enduro2d/high/systems/touch_system.hpp>
|
||||
#include <enduro2d/high/systems/widget_system.hpp>
|
||||
#include <enduro2d/high/systems/world_system.hpp>
|
||||
|
||||
namespace
|
||||
@@ -81,6 +83,8 @@ namespace
|
||||
.add_system<spine_system>())
|
||||
.feature<struct touch_feature>(ecs::feature()
|
||||
.add_system<touch_system>())
|
||||
.feature<struct widget_feature>(ecs::feature()
|
||||
.add_system<widget_system>())
|
||||
.feature<struct world_feature>(ecs::feature()
|
||||
.add_system<world_system>());
|
||||
return !application_ || application_->initialize();
|
||||
@@ -209,6 +213,7 @@ namespace e2d
|
||||
.register_component<sprite_renderer>("sprite_renderer")
|
||||
.register_component<touchable>("touchable")
|
||||
.register_component<events<touchable_events::event>>("touchable.events")
|
||||
.register_component<widget>("widget")
|
||||
;
|
||||
|
||||
safe_module_initialize<inspector>()
|
||||
@@ -235,6 +240,7 @@ namespace e2d
|
||||
.register_component<sprite_renderer>("sprite_renderer")
|
||||
.register_component<touchable>("touchable")
|
||||
//.register_component<events<touchable_events::event>>("touchable.events")
|
||||
.register_component<widget>("widget")
|
||||
;
|
||||
|
||||
safe_module_initialize<luasol>();
|
||||
|
||||
41
sources/enduro2d/high/systems/widget_system.cpp
Normal file
41
sources/enduro2d/high/systems/widget_system.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "Enduro2D"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <enduro2d/high/systems/widget_system.hpp>
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
//
|
||||
// widget_system::internal_state
|
||||
//
|
||||
|
||||
class widget_system::internal_state final : private noncopyable {
|
||||
public:
|
||||
internal_state() = default;
|
||||
~internal_state() noexcept = default;
|
||||
|
||||
void process_update(ecs::registry& owner) {
|
||||
E2D_UNUSED(owner);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// widget_system
|
||||
//
|
||||
|
||||
widget_system::widget_system()
|
||||
: state_(new internal_state()) {}
|
||||
widget_system::~widget_system() noexcept = default;
|
||||
|
||||
void widget_system::process(
|
||||
ecs::registry& owner,
|
||||
const ecs::after<systems::update_event>& trigger)
|
||||
{
|
||||
E2D_UNUSED(trigger);
|
||||
E2D_PROFILER_SCOPE("widget_system.process_update");
|
||||
state_->process_update(owner);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user