1 #include "core/framebuffer.hpp"
2 #include "lua/internal.hpp"
3 #include "library/framebuffer.hpp"
7 lua_render_context
* saved
= NULL
;
8 lua_render_context
* last
= NULL
;
11 struct render_queue_obj
13 render_queue_obj(lua_state
& L
, uint32_t width
, uint32_t height
) throw()
15 lctx
.left_gap
= std::numeric_limits
<uint32_t>::max();
16 lctx
.right_gap
= std::numeric_limits
<uint32_t>::max();
17 lctx
.bottom_gap
= std::numeric_limits
<uint32_t>::max();
18 lctx
.top_gap
= std::numeric_limits
<uint32_t>::max();
23 ~render_queue_obj() throw() {}
24 lua_render_context
* get() { return &lctx
; }
27 size_t s
= rqueue
.get_object_count();
28 return (stringfmt() << s
<< " " << ((s
!= 1) ? "objects" : "object")).str();
31 framebuffer::queue rqueue
;
32 lua_render_context lctx
;
35 function_ptr_luafun
gui_rq_run(lua_func_misc
, "gui.renderq_run", [](lua_state
& L
, const std::string
& fname
)
39 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
40 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
41 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
42 lua_render_context
* ptr
= q
->get();
43 if(ptr
->top_gap
!= std::numeric_limits
<uint32_t>::max())
44 lua_render_ctx
->top_gap
= ptr
->top_gap
;
45 if(ptr
->right_gap
!= std::numeric_limits
<uint32_t>::max())
46 lua_render_ctx
->right_gap
= ptr
->right_gap
;
47 if(ptr
->bottom_gap
!= std::numeric_limits
<uint32_t>::max())
48 lua_render_ctx
->bottom_gap
= ptr
->bottom_gap
;
49 if(ptr
->left_gap
!= std::numeric_limits
<uint32_t>::max())
50 lua_render_ctx
->left_gap
= ptr
->left_gap
;
51 lua_render_ctx
->queue
->copy_from(*ptr
->queue
);
53 throw std::runtime_error("Expected RENDERCTX as argument 1 for gui.renderq_run.");
57 function_ptr_luafun
gui_srepaint(lua_func_misc
, "gui.synchronous_repaint", [](lua_state
& L
,
58 const std::string
& fname
) -> int {
59 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
60 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
61 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
62 synchronous_paint_ctx
= &*q
;
65 throw std::runtime_error("Expected RENDERCTX as argument 1 for gui.renderq_run.");
69 function_ptr_luafun
gui_rq_clear(lua_func_misc
, "gui.renderq_clear", [](lua_state
& L
,
70 const std::string
& fname
) -> int {
71 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
72 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
73 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
74 lua_render_context
* ptr
= q
->get();
75 ptr
->top_gap
= std::numeric_limits
<uint32_t>::max();
76 ptr
->right_gap
= std::numeric_limits
<uint32_t>::max();
77 ptr
->bottom_gap
= std::numeric_limits
<uint32_t>::max();
78 ptr
->left_gap
= std::numeric_limits
<uint32_t>::max();
81 throw std::runtime_error("Expected RENDERCTX as argument 1 for gui.renderq_clear.");
85 function_ptr_luafun
gui_rq_new(lua_func_misc
, "gui.renderq_new", [](lua_state
& L
, const std::string
& fname
)
87 int32_t x
= L
.get_numeric_argument
<int32_t>(1, fname
.c_str());
88 int32_t y
= L
.get_numeric_argument
<int32_t>(2, fname
.c_str());
89 lua_class
<render_queue_obj
>::create(L
, x
, y
);
93 function_ptr_luafun
gui_rq_set(lua_func_misc
, "gui.renderq_set", [](lua_state
& L
, const std::string
& fname
)
95 if(lua_class
<render_queue_obj
>::is(L
, 1)) {
96 lua_class
<render_queue_obj
>::get(L
, 1, fname
.c_str());
97 auto q
= lua_class
<render_queue_obj
>::pin(L
, 1, fname
.c_str());
98 lua_render_context
* ptr
= q
->get();
99 if(!redirect
|| last
!= lua_render_ctx
)
100 saved
= lua_render_ctx
;
101 lua_render_ctx
= last
= ptr
;
103 } else if(L
.type(1) == LUA_TNIL
) {
104 if(redirect
&& last
== lua_render_ctx
)
105 //If there is valid redirect, undo it.
106 lua_render_ctx
= saved
;
111 throw std::runtime_error("Expected RENDERCTX or nil as argument 1 for gui.renderq_set.");
115 lua_class
<render_queue_obj
> class_render_queue_obj("RENDERCTX");
118 void lua_renderq_run(lua_render_context
* ctx
, void* _sctx
)
120 render_queue_obj
* sctx
= (render_queue_obj
*)_sctx
;
121 lua_render_context
* ptr
= sctx
->get();
122 if(ptr
->top_gap
!= std::numeric_limits
<uint32_t>::max())
123 ctx
->top_gap
= ptr
->top_gap
;
124 if(ptr
->right_gap
!= std::numeric_limits
<uint32_t>::max())
125 ctx
->right_gap
= ptr
->right_gap
;
126 if(ptr
->bottom_gap
!= std::numeric_limits
<uint32_t>::max())
127 ctx
->bottom_gap
= ptr
->bottom_gap
;
128 if(ptr
->left_gap
!= std::numeric_limits
<uint32_t>::max())
129 ctx
->left_gap
= ptr
->left_gap
;
130 ctx
->queue
->copy_from(*ptr
->queue
);