merge clip rects in ingame gui; improved lua api
This commit is contained in:
parent
ec18f8ac0e
commit
461c4be2f5
6 changed files with 86 additions and 19 deletions
|
@ -403,7 +403,8 @@ template <> inline float toType(lua_State* L, int index)
|
|||
}
|
||||
template <> inline const char* toType(lua_State* L, int index)
|
||||
{
|
||||
return lua_tostring(L, index);
|
||||
const char* res = lua_tostring(L, index);
|
||||
return res ? res : "";
|
||||
}
|
||||
template <> inline void* toType(lua_State* L, int index)
|
||||
{
|
||||
|
@ -511,7 +512,27 @@ inline void push(lua_State* L, EntityRef value)
|
|||
{
|
||||
lua_pushinteger(L, value.index);
|
||||
}
|
||||
|
||||
|
||||
inline bool toEntity(lua_State* L, int idx, Ref<Universe*> universe, Ref<EntityRef> entity)
|
||||
{
|
||||
if (!lua_istable(L, idx)) return false;
|
||||
if (getField(L, 1, "_entity") != LUA_TNUMBER) {
|
||||
lua_pop(L, 1);
|
||||
return false;
|
||||
}
|
||||
entity = EntityRef {toType<i32>(L, -1)};
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (getField(L, 1, "_universe") != LUA_TLIGHTUSERDATA) {
|
||||
lua_pop(L, 1);
|
||||
return false;
|
||||
}
|
||||
universe = toType<Universe*>(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void pushEntity(lua_State* L, EntityPtr value, Universe* universe)
|
||||
{
|
||||
if (!value.isValid()) {
|
||||
|
|
|
@ -42,7 +42,7 @@ struct GUIScene : IScene
|
|||
virtual IVec2 getCursorPosition() = 0;
|
||||
|
||||
virtual bool hasGUI(EntityRef entity) const = 0;
|
||||
virtual Rect getRectEx(EntityPtr entity, const Vec2& canva_size) const = 0;
|
||||
virtual Rect getRectEx(EntityPtr entity, const Vec2& canvas_size) const = 0;
|
||||
virtual Rect getRect(EntityRef entity) const = 0;
|
||||
virtual EntityPtr getRectAtEx(const Vec2& pos, const Vec2& canvas_size) const = 0;
|
||||
virtual EntityPtr getRectAt(const Vec2& pos) const = 0;
|
||||
|
|
|
@ -176,8 +176,10 @@ struct GUISystemImpl final : GUISystem
|
|||
|
||||
static int LUA_GUIRect_getScreenRect(lua_State* L)
|
||||
{
|
||||
GUIScene* scene = LuaWrapper::checkArg<GUIScene*>(L, 1);
|
||||
EntityRef e = LuaWrapper::checkArg<EntityRef>(L, 2);
|
||||
EntityRef e;
|
||||
Universe* universe;
|
||||
if (!LuaWrapper::toEntity(L, 1, Ref(universe), Ref(e))) return 0;
|
||||
GUIScene* scene = (GUIScene*)universe->getScene(crc32("gui"));
|
||||
GUIScene::Rect rect = scene->getRect(e);
|
||||
lua_newtable(L);
|
||||
LuaWrapper::push(L, rect.x);
|
||||
|
|
|
@ -579,9 +579,25 @@ namespace Lumix
|
|||
|
||||
static int getEnvironment(lua_State* L)
|
||||
{
|
||||
auto* universe = LuaWrapper::checkArg<Universe*>(L, 1);
|
||||
EntityRef entity = LuaWrapper::checkArg<EntityRef>(L, 2);
|
||||
int scr_index = LuaWrapper::checkArg<int>(L, 3);
|
||||
if (!lua_istable(L, 1)) {
|
||||
LuaWrapper::argError(L, 1, "entity");
|
||||
}
|
||||
|
||||
if (LuaWrapper::getField(L, 1, "_entity") != LUA_TNUMBER) {
|
||||
lua_pop(L, 1);
|
||||
LuaWrapper::argError(L, 1, "entity");
|
||||
}
|
||||
const EntityRef entity = {LuaWrapper::toType<i32>(L, -1)};
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (LuaWrapper::getField(L, 1, "_universe") != LUA_TLIGHTUSERDATA) {
|
||||
lua_pop(L, 1);
|
||||
LuaWrapper::argError(L, 1, "entity");
|
||||
}
|
||||
Universe* universe = LuaWrapper::toType<Universe*>(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
const i32 scr_index = LuaWrapper::checkArg<i32>(L, 2);
|
||||
|
||||
if (!universe->hasComponent(entity, LUA_SCRIPT_TYPE))
|
||||
{
|
||||
|
@ -771,6 +787,25 @@ namespace Lumix
|
|||
static int lua_prop_getter(lua_State* L) {
|
||||
LuaWrapper::checkTableArg(L, 1); // self
|
||||
|
||||
lua_getfield(L, 1, "_scene");
|
||||
LuaScriptSceneImpl* scene = LuaWrapper::toType<LuaScriptSceneImpl*>(L, -1);
|
||||
lua_getfield(L, 1, "_entity");
|
||||
const EntityRef entity = {LuaWrapper::toType<i32>(L, -1)};
|
||||
lua_pop(L, 2);
|
||||
|
||||
if (lua_isnumber(L, 2)) {
|
||||
const i32 scr_index = LuaWrapper::toType<i32>(L, 2);
|
||||
int env = scene->getEnvironment(entity, scr_index);
|
||||
if (env < 0) {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, env);
|
||||
ASSERT(lua_type(L, -1) == LUA_TTABLE);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
LuaPropGetterVisitor v;
|
||||
v.prop_name = LuaWrapper::checkArg<const char*>(L, 2);
|
||||
v.L = L;
|
||||
|
@ -778,11 +813,8 @@ namespace Lumix
|
|||
v.cmp.type = LuaWrapper::toType<ComponentType>(L, lua_upvalueindex(1));
|
||||
const Reflection::ComponentBase* cmp = Reflection::getComponent(v.cmp.type);
|
||||
|
||||
lua_getfield(L, 1, "_scene");
|
||||
v.cmp.scene = LuaWrapper::toType<IScene*>(L, -1);
|
||||
lua_getfield(L, 1, "_entity");
|
||||
v.cmp.entity.index = LuaWrapper::toType<i32>(L, -1);
|
||||
lua_pop(L, 2);
|
||||
v.cmp.scene = scene;
|
||||
v.cmp.entity = entity;
|
||||
|
||||
cmp->visit(v);
|
||||
|
||||
|
@ -885,7 +917,6 @@ namespace Lumix
|
|||
lua_pushvalue(L, -1); // [ scene, scene ]
|
||||
lua_setfield(L, -2, "__index"); // [ scene ]
|
||||
|
||||
|
||||
lua_pushcfunction(L, lua_new_scene); // [ scene, fn_new_scene ]
|
||||
lua_setfield(L, -2, "new"); // [ scene ]
|
||||
|
||||
|
|
|
@ -30,11 +30,24 @@ void Draw2D::clear(Vec2 atlas_size) {
|
|||
}
|
||||
|
||||
void Draw2D::pushClipRect(const Vec2& from, const Vec2& to) {
|
||||
m_clip_queue.push({from, to});
|
||||
Rect r = {from, to};
|
||||
if (!m_clip_queue.empty()) {
|
||||
const Rect prev = m_clip_queue.back();
|
||||
if (prev.to.x >= 0) {
|
||||
r.from.x = maximum(r.from.x, prev.from.x);
|
||||
r.from.y = maximum(r.from.y, prev.from.y);
|
||||
r.to.x = minimum(r.to.x, prev.to.x);
|
||||
r.to.y = minimum(r.to.y, prev.to.y);
|
||||
}
|
||||
}
|
||||
r.to.x = maximum(r.from.x, r.to.x);
|
||||
r.to.y = maximum(r.from.y, r.to.y);
|
||||
|
||||
m_clip_queue.push({r.from, r.to});
|
||||
Cmd& cmd = m_cmds.emplace();
|
||||
cmd.texture = nullptr;
|
||||
cmd.clip_pos = from;
|
||||
cmd.clip_size = to - from;
|
||||
cmd.clip_pos = r.from;
|
||||
cmd.clip_size = r.to - r.from;
|
||||
cmd.indices_count = 0;
|
||||
cmd.index_offset = m_indices.size();
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ private:
|
|||
WorldEditor& m_editor;
|
||||
StudioApp& m_app;
|
||||
float m_time_multiplier;
|
||||
Vec2 m_pos;
|
||||
Vec2 m_size;
|
||||
Vec2 m_pos = Vec2(0);
|
||||
Vec2 m_size = Vec2(0);
|
||||
struct GUIInterface* m_gui_interface;
|
||||
bool m_is_mouse_captured;
|
||||
bool m_is_ingame_cursor;
|
||||
|
|
Loading…
Reference in a new issue