lua: Fix tools tests when ENABLE_UI is not defined

This commit is contained in:
David Capello 2019-03-18 13:30:17 -03:00
parent 7aec117b5e
commit 33c6fc5f40
5 changed files with 49 additions and 31 deletions

View File

@ -303,20 +303,10 @@ if(ENABLE_UI)
commands/filters/filter_window.cpp
commands/filters/filter_worker.cpp
file_selector.cpp
gui_xml.cpp
modules/editors.cpp
modules/gfx.cpp
modules/gui.cpp
send_crash.cpp
tools/active_tool.cpp
tools/ink_type.cpp
tools/intertwine.cpp
tools/pick_ink.cpp
tools/point_shape.cpp
tools/stroke.cpp
tools/symmetries.cpp
tools/tool_box.cpp
tools/tool_loop_manager.cpp
ui/app_menuitem.cpp
ui/backup_indicator.cpp
ui/browser_view.cpp
@ -356,7 +346,6 @@ if(ENABLE_UI)
ui/editor/select_box_state.cpp
ui/editor/standby_state.cpp
ui/editor/state_with_wheel_behavior.cpp
ui/editor/tool_loop_impl.cpp
ui/editor/transform_handles.cpp
ui/editor/zooming_state.cpp
ui/export_file_window.cpp
@ -550,6 +539,7 @@ add_library(app-lib
filename_formatter.cpp
flatten.cpp
font_path.cpp
gui_xml.cpp
i18n/strings.cpp
i18n/xml_translator.cpp
ini_file.cpp
@ -572,8 +562,18 @@ add_library(app-lib
sprite_job.cpp
thumbnail_generator.cpp
thumbnails.cpp
tools/active_tool.cpp
tools/ink_type.cpp
tools/intertwine.cpp
tools/pick_ink.cpp
tools/point_shape.cpp
tools/stroke.cpp
tools/symmetries.cpp
tools/tool_box.cpp
tools/tool_loop_manager.cpp
transaction.cpp
transformation.cpp
ui/editor/tool_loop_impl.cpp
ui/layer_frame_comboboxes.cpp
util/autocrop.cpp
util/buffer_region.cpp

View File

@ -127,10 +127,8 @@ public:
Extensions m_extensions;
// Load main language (after loading the extensions)
LoadLanguage m_loadLanguage;
#ifdef ENABLE_UI
tools::ToolBox m_toolbox;
tools::ActiveToolManager m_activeToolManager;
#endif
Commands m_commands;
ContextT m_context;
#ifdef ENABLE_UI
@ -145,8 +143,8 @@ public:
Preferences& pref)
: m_loggerModule(createLogInDesktop)
, m_loadLanguage(pref, m_extensions)
#ifdef ENABLE_UI
, m_activeToolManager(&m_toolbox)
#ifdef ENABLE_UI
, m_recent_files(pref.general.recentItems())
#endif
, m_recovery(nullptr) {
@ -493,29 +491,17 @@ bool App::isPortable()
tools::ToolBox* App::toolBox() const
{
ASSERT(m_modules != NULL);
#ifdef ENABLE_UI
return &m_modules->m_toolbox;
#else
return nullptr;
#endif
}
tools::Tool* App::activeTool() const
{
#ifdef ENABLE_UI
return m_modules->m_activeToolManager.activeTool();
#else
return nullptr;
#endif
}
tools::ActiveToolManager* App::activeToolManager() const
{
#ifdef ENABLE_UI
return &m_modules->m_activeToolManager;
#else
return nullptr;
#endif
}
RecentFiles* App::recentFiles() const

View File

@ -192,7 +192,6 @@ int App_refresh(lua_State* L)
int App_toolStroke(lua_State* L)
{
#ifdef ENABLE_UI
// First argument must be a table
if (!lua_istable(L, 1))
return luaL_error(L, "app.toolStroke() must be called with a table as its first argument");
@ -251,7 +250,6 @@ int App_toolStroke(lua_State* L)
loop->commitOrRollback();
}
lua_pop(L, 1);
#endif
return 0;
}
@ -420,8 +418,8 @@ int App_set_activeSprite(lua_State* L)
int App_set_activeLayer(lua_State* L)
{
auto layer = get_docobj<Layer>(L, 2);
#ifdef ENABLE_UI
auto layer = get_docobj<Layer>(L, 2);
app::Context* ctx = App::instance()->context();
if (auto uiCtx = dynamic_cast<UIContext*>(ctx)) {
DocView* docView = uiCtx->activeView();
@ -437,8 +435,8 @@ int App_set_activeLayer(lua_State* L)
int App_set_activeFrame(lua_State* L)
{
const doc::frame_t frame = get_frame_number_from_arg(L, 2);
#ifdef ENABLE_UI
const doc::frame_t frame = get_frame_number_from_arg(L, 2);
app::Context* ctx = App::instance()->context();
if (auto uiCtx = dynamic_cast<UIContext*>(ctx)) {
DocView* docView = uiCtx->activeView();
@ -454,8 +452,8 @@ int App_set_activeFrame(lua_State* L)
int App_set_activeCel(lua_State* L)
{
const auto cel = get_docobj<Cel>(L, 2);
#ifdef ENABLE_UI
const auto cel = get_docobj<Cel>(L, 2);
app::Context* ctx = App::instance()->context();
if (auto uiCtx = dynamic_cast<UIContext*>(ctx)) {
DocView* docView = uiCtx->activeView();

View File

@ -84,11 +84,13 @@ Ink* ActiveToolManager::activeInk() const
case tools::InkType::SIMPLE: {
id = tools::WellKnownInks::Paint;
#ifdef ENABLE_UI
ColorBar* colorbar = ColorBar::instance();
app::Color color = (m_rightClick ? colorbar->getBgColor():
colorbar->getFgColor());
if (color.getAlpha() == 0)
id = tools::WellKnownInks::PaintCopy;
#endif
break;
}

View File

@ -187,11 +187,13 @@ public:
m_opacity = 255;
}
#ifdef ENABLE_UI // TODO add support when UI is not enabled
if (m_toolPref.ink() == tools::InkType::SHADING) {
m_shadingRemap.reset(
App::instance()->contextBar()->createShadeRemap(
button == tools::ToolLoop::Left));
}
#endif
}
~ToolLoopBase() {
@ -263,6 +265,7 @@ public:
doc::Remap* getShadingRemap() override { return m_shadingRemap.get(); }
void limitDirtyAreaToViewport(gfx::Region& rgn) override {
#ifdef ENABLE_UI
// Visible region (on the screen) of the all editors showing the
// given document.
gfx::Region allVisibleRgn;
@ -276,38 +279,55 @@ public:
}
rgn &= allVisibleRgn;
#endif // ENABLE_UI
}
void updateDirtyArea(const gfx::Region& dirtyArea) override {
if (!m_editor)
return;
#ifdef ENABLE_UI
// This is necessary here so the "on sprite crosshair" is hidden,
// we update screen pixels with the new sprite, and then we show
// the crosshair saving the updated pixels. It fixes problems with
// filled shape tools when we release the button, or paint-bucket
// when we press the button.
HideBrushPreview hide(m_editor->brushPreview());
#endif
m_document->notifySpritePixelsModified(
m_sprite, dirtyArea, m_frame);
}
void updateStatusBar(const char* text) override {
#ifdef ENABLE_UI
if (auto statusBar = StatusBar::instance())
statusBar->setStatusText(0, text);
#endif
}
gfx::Point statusBarPositionOffset() override {
#ifdef ENABLE_UI
return (m_editor ? -m_editor->mainTilePosition(): gfx::Point(0, 0));
#else
return gfx::Point(0, 0);
#endif
}
render::DitheringMatrix getDitheringMatrix() override {
#ifdef ENABLE_UI // TODO add support when UI is not enabled
return App::instance()->contextBar()->ditheringMatrix();
#else
return render::DitheringMatrix();
#endif
}
render::DitheringAlgorithmBase* getDitheringAlgorithm() override {
#ifdef ENABLE_UI // TODO add support when UI is not enabled
return App::instance()->contextBar()->ditheringAlgorithm();
#else
return nullptr;
#endif
}
};
@ -503,8 +523,10 @@ public:
}
}
#ifdef ENABLE_UI
if (redraw)
update_screen_for_document(m_document);
#endif
}
const Image* getSrcImage() override { return m_expandCelCanvas->getSourceCanvas(); }
@ -552,6 +574,8 @@ public:
};
#ifdef ENABLE_UI
tools::ToolLoop* create_tool_loop(
Editor* editor,
Context* context,
@ -649,6 +673,8 @@ tools::ToolLoop* create_tool_loop(
}
}
#endif // ENABLE_UI
tools::ToolLoop* create_tool_loop_for_script(
Context* context,
tools::Tool* tool,
@ -666,8 +692,10 @@ tools::ToolLoop* create_tool_loop_for_script(
tools::ToolLoop::Button toolLoopButton = tools::ToolLoop::Left;
tools::Controller* controller = tool->getController(toolLoopButton);
BrushRef brush;
#ifdef ENABLE_UI
if (App::instance()->contextBar())
brush = App::instance()->contextBar()->activeBrush(tool, ink);
#endif
if (!brush)
brush = BrushRef(new Brush(BrushType::kCircleBrushType, 1, 0));
@ -686,6 +714,8 @@ tools::ToolLoop* create_tool_loop_for_script(
//////////////////////////////////////////////////////////////////////
// For preview
#ifdef ENABLE_UI
class PreviewToolLoopImpl : public ToolLoopBase {
Image* m_image;
@ -780,6 +810,8 @@ tools::ToolLoop* create_tool_loop_preview(
}
}
#endif // ENABLE_UI
//////////////////////////////////////////////////////////////////////
} // namespace app