Skip to content

Commit

Permalink
Merge branch 'main' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Oct 12, 2021
2 parents c1628e4 + 161264a commit db44eeb
Show file tree
Hide file tree
Showing 261 changed files with 817 additions and 84,853 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
[submodule "src/tga"]
path = src/tga
url = https://github.com/aseprite/tga.git
[submodule "third_party/curl"]
path = third_party/curl
url = https://github.com/aseprite/curl.git
[submodule "third_party/IXWebSocket"]
path = third_party/IXWebSocket
url = https://github.com/machinezone/IXWebSocket
[submodule "third_party/cityhash"]
path = third_party/cityhash
url = https://github.com/aseprite/cityhash.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)"
option(ENABLE_NEWS "Enable the news in Home tab" on)
option(ENABLE_UPDATER "Enable automatic check for updates" on)
option(ENABLE_SCRIPTING "Compile with scripting support" on)
option(ENABLE_WEBSOCKET "Compile with websocket support" on)
option(ENABLE_TESTS "Compile unit tests" off)
option(ENABLE_BENCHMARKS "Compile benchmarks" off)
option(ENABLE_TRIAL_MODE "Compile the trial version" off)
Expand Down
2 changes: 2 additions & 0 deletions data/strings/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1463,11 +1463,13 @@ title = Security
script_label = The following script:
file_label = wants to access to this file:
command_label = wants to execute the following command:
websocket_label = wants to open a WebSocket connection to this URL:
dont_show_for_this_access = Don't show this specific alert again for this script
dont_show_for_this_script = Give full trust to this script
allow_execute_access = &Allow Execute Access
allow_write_access = &Allow Write Access
allow_read_access = &Allow Read Access
allow_open_conn_access = &Allow to Open Connections
give_full_access = Give Script Full &Access
stop_script = &Stop Script
Expand Down
2 changes: 1 addition & 1 deletion laf
Submodule laf updated 2 files
+1 −0 base/CMakeLists.txt
+8 −0 base/sha1.h
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ if(ENABLE_SCRIPTING)
add_definitions(-DENABLE_SCRIPTING)
endif()

if(ENABLE_WEBSOCKET)
# Needed for "app" and "main"
add_definitions(-DENABLE_WEBSOCKET)
endif()

######################################################################
# Aseprite Libraries (in preferred order to be built)

Expand Down
10 changes: 10 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ if(ENABLE_SCRIPTING)
commands/cmd_open_script_folder.cpp
ui/devconsole_view.cpp)
endif()
if(ENABLE_WEBSOCKET)
set(scripting_files_ws
script/websocket_class.cpp)
endif()
set(scripting_files
commands/cmd_run_script.cpp
script/app_command_object.cpp
Expand All @@ -159,6 +163,7 @@ if(ENABLE_SCRIPTING)
script/color_space_class.cpp
script/dialog_class.cpp
script/engine.cpp
script/events_class.cpp
script/frame_class.cpp
script/frames_class.cpp
script/grid_class.cpp
Expand Down Expand Up @@ -193,6 +198,7 @@ if(ENABLE_SCRIPTING)
script/values.cpp
script/version_class.cpp
shell.cpp
${scripting_files_ws}
${scripting_files_ui})
endif()

Expand Down Expand Up @@ -695,6 +701,10 @@ endif()

if(ENABLE_SCRIPTING)
target_link_libraries(app-lib lua lauxlib lualib)

if(ENABLE_WEBSOCKET)
target_link_libraries(app-lib ixwebsocket)
endif()
endif()

if(ENABLE_UPDATER)
Expand Down
11 changes: 6 additions & 5 deletions src/app/active_site_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand Down Expand Up @@ -28,10 +28,11 @@ ActiveSiteHandler::~ActiveSiteHandler()
void ActiveSiteHandler::addDoc(Doc* doc)
{
Data data;
if (doc::Layer* layer = doc->sprite()->root()->firstLayer())
data.layer = layer->id();
else
data.layer = doc::NullId;
data.layer = doc::NullId;
if (doc->sprite()) { // The sprite can be nullptr in some tests
if (doc::Layer* layer = doc->sprite()->root()->firstLayer())
data.layer = layer->id();
}
data.frame = 0;
m_data.insert(std::make_pair(doc, data));
doc->add_observer(this);
Expand Down
29 changes: 21 additions & 8 deletions src/app/context.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -98,7 +98,7 @@ Doc* Context::activeDocument() const

void Context::setActiveDocument(Doc* document)
{
onSetActiveDocument(document);
onSetActiveDocument(document, true);
}

void Context::setActiveLayer(doc::Layer* layer)
Expand Down Expand Up @@ -242,15 +242,19 @@ void Context::onAddDocument(Doc* doc)

if (m_activeSiteHandler)
m_activeSiteHandler->addDoc(doc);

notifyActiveSiteChanged();
}

void Context::onRemoveDocument(Doc* doc)
{
if (doc == m_lastSelectedDoc)
m_lastSelectedDoc = nullptr;

if (m_activeSiteHandler)
m_activeSiteHandler->removeDoc(doc);

if (doc == m_lastSelectedDoc) {
m_lastSelectedDoc = nullptr;
notifyActiveSiteChanged();
}
}

void Context::onGetActiveSite(Site* site) const
Expand All @@ -260,24 +264,33 @@ void Context::onGetActiveSite(Site* site) const
activeSiteHandler()->getActiveSiteForDoc(doc, site);
}

void Context::onSetActiveDocument(Doc* doc)
void Context::onSetActiveDocument(Doc* doc, bool notify)
{
m_lastSelectedDoc = doc;
if (notify)
notifyActiveSiteChanged();
}

void Context::onSetActiveLayer(doc::Layer* layer)
{
Doc* newDoc = (layer ? static_cast<Doc*>(layer->sprite()->document()): nullptr);
if (!newDoc)
return;

activeSiteHandler()->setActiveLayerInDoc(newDoc, layer);

if (newDoc != m_lastSelectedDoc)
setActiveDocument(newDoc);
if (newDoc)
activeSiteHandler()->setActiveLayerInDoc(newDoc, layer);
else
notifyActiveSiteChanged();
}

void Context::onSetActiveFrame(const doc::frame_t frame)
{
if (m_lastSelectedDoc)
activeSiteHandler()->setActiveFrameInDoc(m_lastSelectedDoc, frame);

notifyActiveSiteChanged();
}

void Context::onSetRange(const DocRange& range)
Expand Down
8 changes: 5 additions & 3 deletions src/app/context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -113,7 +113,7 @@ namespace app {
void onRemoveDocument(Doc* doc) override;

virtual void onGetActiveSite(Site* site) const;
virtual void onSetActiveDocument(Doc* doc);
virtual void onSetActiveDocument(Doc* doc, bool notify);
virtual void onSetActiveLayer(doc::Layer* layer);
virtual void onSetActiveFrame(const doc::frame_t frame);
virtual void onSetRange(const DocRange& range);
Expand All @@ -126,10 +126,12 @@ namespace app {
private:
ActiveSiteHandler* activeSiteHandler() const;

// This must be defined before m_docs because ActiveSiteHandler
// will be an observer of all documents.
mutable std::unique_ptr<ActiveSiteHandler> m_activeSiteHandler;
mutable Docs m_docs;
ContextFlags m_flags; // Last updated flags.
Doc* m_lastSelectedDoc;
mutable std::unique_ptr<ActiveSiteHandler> m_activeSiteHandler;
mutable std::unique_ptr<Preferences> m_preferences;

DISABLE_COPYING(Context);
Expand Down
8 changes: 8 additions & 0 deletions src/app/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ Doc::Doc(Sprite* sprite)
Doc::~Doc()
{
DOC_TRACE("DOC: Deleting", this);

try {
notify_observers<Doc*>(&DocObserver::onDestroy, this);
}
catch (...) {
LOG(ERROR, "DOC: Exception on DocObserver::onDestroy()\n");
}

removeFromContext();
}

Expand Down
5 changes: 2 additions & 3 deletions src/app/doc_observer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2018-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -17,6 +17,7 @@ namespace app {
public:
virtual ~DocObserver() { }

virtual void onDestroy(Doc* doc) { }
virtual void onFileNameChanged(Doc* doc) { }

// General update. If an observer receives this event, it's because
Expand Down Expand Up @@ -85,8 +86,6 @@ namespace app {
// The tileset has changed.
virtual void onTilesetChanged(DocEvent& ev) { }

// Called to destroy the observable. (Here you could call "delete this".)
virtual void dispose() { }
};

} // namespace app
Expand Down
11 changes: 6 additions & 5 deletions src/app/doc_undo_observer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2015-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -19,12 +20,12 @@ namespace app {
class DocUndoObserver {
public:
virtual ~DocUndoObserver() { }
virtual void onAddUndoState(DocUndo* history) = 0;
virtual void onAddUndoState(DocUndo* history) { }
virtual void onDeleteUndoState(DocUndo* history,
undo::UndoState* state) = 0;
virtual void onCurrentUndoStateChange(DocUndo* history) = 0;
virtual void onClearRedo(DocUndo* history) = 0;
virtual void onTotalUndoSizeChange(DocUndo* history) = 0;
undo::UndoState* state) { }
virtual void onCurrentUndoStateChange(DocUndo* history) { }
virtual void onClearRedo(DocUndo* history) { }
virtual void onTotalUndoSizeChange(DocUndo* history) { }
};

} // namespace app
Expand Down
25 changes: 8 additions & 17 deletions src/app/job.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -12,10 +13,10 @@

#include "app/app.h"
#include "app/console.h"
#include "app/context.h"
#include "app/i18n/strings.h"
#include "base/mutex.h"
#include "base/scoped_lock.h"
#include "base/thread.h"
#include "fmt/format.h"
#include "ui/alert.h"
#include "ui/widget.h"
Expand All @@ -36,14 +37,10 @@ int Job::runningJobs()

Job::Job(const char* jobName)
{
m_mutex = NULL;
m_thread = NULL;
m_last_progress = 0.0;
m_done_flag = false;
m_canceled_flag = false;

m_mutex = new base::mutex();

if (App::instance()->isGui()) {
m_alert_window = ui::Alert::create(
fmt::format(Strings::alerts_job_working(), jobName));
Expand All @@ -59,27 +56,23 @@ Job::~Job()
{
if (App::instance()->isGui()) {
ASSERT(!m_timer->isRunning());
ASSERT(m_thread == NULL);

if (m_alert_window)
m_alert_window->closeWindow(NULL);
}

if (m_mutex)
delete m_mutex;
}

void Job::startJob()
{
m_thread = new base::thread(&Job::thread_proc, this);
m_thread = std::thread(&Job::thread_proc, this);
++g_runningJobs;

if (m_alert_window) {
m_alert_window->openWindowInForeground();

// The job was canceled by the user?
{
base::scoped_lock hold(*m_mutex);
std::unique_lock<std::mutex> hold(m_mutex);
if (!m_done_flag)
m_canceled_flag = true;
}
Expand Down Expand Up @@ -107,10 +100,8 @@ void Job::waitJob()
if (m_timer && m_timer->isRunning())
m_timer->stop();

if (m_thread) {
m_thread->join();
delete m_thread;
m_thread = nullptr;
if (m_thread.joinable()) {
m_thread.join();

--g_runningJobs;
}
Expand All @@ -128,7 +119,7 @@ bool Job::isCanceled()

void Job::onMonitoringTick()
{
base::scoped_lock hold(*m_mutex);
std::unique_lock<std::mutex> hold(m_mutex);

// update progress
m_alert_window->setProgress(m_last_progress);
Expand All @@ -142,7 +133,7 @@ void Job::onMonitoringTick()

void Job::done()
{
base::scoped_lock hold(*m_mutex);
std::unique_lock<std::mutex> hold(m_mutex);
m_done_flag = true;
}

Expand Down
11 changes: 4 additions & 7 deletions src/app/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

#include <atomic>
#include <exception>

namespace base {
class thread;
class mutex;
}
#include <mutex>
#include <thread>

namespace app {

Expand Down Expand Up @@ -62,9 +59,9 @@ namespace app {
static void monitor_proc(void* data);
static void monitor_free(void* data);

base::thread* m_thread;
std::thread m_thread;
std::unique_ptr<ui::Timer> m_timer;
base::mutex* m_mutex;
std::mutex m_mutex;
ui::AlertPtr m_alert_window;
std::atomic<double> m_last_progress;
bool m_done_flag;
Expand Down
Loading

0 comments on commit db44eeb

Please sign in to comment.