mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
[lua] Add Dialog:repaint() function
This commit is contained in:
parent
2cb526a19b
commit
25682a44d8
@ -32,6 +32,20 @@ Canvas::Canvas() : ui::Widget(Type())
|
||||
{
|
||||
}
|
||||
|
||||
void Canvas::callPaint()
|
||||
{
|
||||
if (!m_surface)
|
||||
return;
|
||||
|
||||
os::Paint p;
|
||||
p.color(bgColor());
|
||||
m_surface->drawRect(m_surface->bounds(), p);
|
||||
|
||||
// Draw only on resize (onPaint we draw the cached m_surface)
|
||||
GraphicsContext gc(m_surface);
|
||||
Paint(gc);
|
||||
}
|
||||
|
||||
void Canvas::onInitTheme(ui::InitThemeEvent& ev)
|
||||
{
|
||||
Widget::onInitTheme(ev);
|
||||
@ -56,13 +70,7 @@ void Canvas::onResize(ui::ResizeEvent& ev)
|
||||
m_surface->height() != h) {
|
||||
m_surface = os::instance()->makeSurface(w, h);
|
||||
|
||||
os::Paint p;
|
||||
p.color(bgColor());
|
||||
m_surface->drawRect(m_surface->bounds(), p);
|
||||
|
||||
// Draw only on resize (onPaint we draw the cached m_surface)
|
||||
GraphicsContext gc(m_surface);
|
||||
Paint(gc);
|
||||
callPaint();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -24,6 +24,8 @@ public:
|
||||
|
||||
Canvas();
|
||||
|
||||
void callPaint();
|
||||
|
||||
obs::signal<void(GraphicsContext&)> Paint;
|
||||
|
||||
private:
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "ui/window.h"
|
||||
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -1115,6 +1116,27 @@ int Dialog_modify(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Dialog_repaint(lua_State* L)
|
||||
{
|
||||
auto dlg = get_obj<Dialog>(L, 1);
|
||||
std::stack<ui::Widget*> widgets;
|
||||
widgets.push(&dlg->grid);
|
||||
|
||||
while (!widgets.empty()) {
|
||||
auto child = widgets.top();
|
||||
widgets.pop();
|
||||
|
||||
if (child->type() == Canvas::Type()) {
|
||||
static_cast<Canvas*>(child)->callPaint();
|
||||
child->invalidate();
|
||||
}
|
||||
|
||||
for (auto subchild : child->children())
|
||||
widgets.push(subchild);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Dialog_get_data(lua_State* L)
|
||||
{
|
||||
auto dlg = get_obj<Dialog>(L, 1);
|
||||
@ -1333,6 +1355,7 @@ const luaL_Reg Dialog_methods[] = {
|
||||
{ "file", Dialog_file },
|
||||
{ "canvas", Dialog_canvas },
|
||||
{ "modify", Dialog_modify },
|
||||
{ "repaint", Dialog_repaint },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user