2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2009-06-01 10:59:15 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2009-06-01 10:59:15 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "app/app.h"
|
2013-11-11 05:27:11 +08:00
|
|
|
#include "app/document.h"
|
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/settings/ui_settings_impl.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/color_bar.h"
|
|
|
|
#include "app/ui/document_view.h"
|
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
#include "app/ui/main_window.h"
|
|
|
|
#include "app/ui/mini_editor.h"
|
|
|
|
#include "app/ui/tabs.h"
|
2013-11-11 05:27:11 +08:00
|
|
|
#include "app/ui/timeline.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/workspace.h"
|
2013-11-11 05:27:11 +08:00
|
|
|
#include "app/ui_context.h"
|
2011-03-23 08:11:25 +08:00
|
|
|
#include "base/mutex.h"
|
2009-06-01 10:59:15 +08:00
|
|
|
#include "raster/sprite.h"
|
2011-03-24 22:50:00 +08:00
|
|
|
#include "undo/undo_history.h"
|
2009-06-01 10:59:15 +08:00
|
|
|
|
2011-03-24 22:50:00 +08:00
|
|
|
#include <allegro/file.h>
|
|
|
|
#include <allegro/system.h>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2009-06-01 10:59:15 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
UIContext* UIContext::m_instance = NULL;
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2009-10-09 09:34:06 +08:00
|
|
|
UIContext::UIContext()
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
: Context(new UISettingsImpl)
|
2009-06-01 10:59:15 +08:00
|
|
|
{
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(m_instance == NULL);
|
2009-10-09 09:34:06 +08:00
|
|
|
m_instance = this;
|
2009-06-01 10:59:15 +08:00
|
|
|
}
|
|
|
|
|
2009-10-09 09:34:06 +08:00
|
|
|
UIContext::~UIContext()
|
2009-06-01 10:59:15 +08:00
|
|
|
{
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(m_instance == this);
|
2009-10-09 09:34:06 +08:00
|
|
|
m_instance = NULL;
|
2014-07-29 11:53:24 +08:00
|
|
|
|
|
|
|
// The context must be empty at this point. (It's to check if the UI
|
|
|
|
// is working correctly, i.e. closing all files when the user can
|
|
|
|
// take any action about it.)
|
|
|
|
ASSERT(documents().empty());
|
2009-06-01 10:59:15 +08:00
|
|
|
}
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
DocumentView* UIContext::activeView() const
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
2013-03-28 08:19:35 +08:00
|
|
|
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
2014-07-29 11:53:24 +08:00
|
|
|
WorkspaceView* view = workspace->activeView();
|
2013-03-28 08:19:35 +08:00
|
|
|
if (DocumentView* docView = dynamic_cast<DocumentView*>(view))
|
|
|
|
return docView;
|
|
|
|
else
|
|
|
|
return NULL;
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
void UIContext::setActiveView(DocumentView* docView)
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
2014-07-29 11:53:24 +08:00
|
|
|
setActiveDocument(docView ? docView->getDocument(): NULL);
|
|
|
|
|
2013-03-28 08:19:35 +08:00
|
|
|
if (docView != NULL) {
|
|
|
|
App::instance()->getMainWindow()->getTabsBar()->selectTab(docView);
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
if (App::instance()->getMainWindow()->getWorkspace()->activeView() != docView)
|
2013-03-28 08:19:35 +08:00
|
|
|
App::instance()->getMainWindow()->getWorkspace()->setActiveView(docView);
|
|
|
|
}
|
|
|
|
|
|
|
|
current_editor = (docView ? docView->getEditor(): NULL);
|
2013-01-21 05:40:37 +08:00
|
|
|
|
|
|
|
if (current_editor)
|
|
|
|
current_editor->requestFocus();
|
|
|
|
|
|
|
|
App::instance()->getMainWindow()->getMiniEditor()->updateUsingEditor(current_editor);
|
2013-11-11 05:27:11 +08:00
|
|
|
App::instance()->getMainWindow()->getTimeline()->updateUsingEditor(current_editor);
|
2013-02-21 06:54:00 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
// Change the image-type of color bar.
|
|
|
|
ColorBar::instance()->setPixelFormat(app_get_current_pixel_format());
|
|
|
|
|
2013-02-21 06:54:00 +08:00
|
|
|
// Restore the palette of the selected document.
|
2013-03-12 07:29:45 +08:00
|
|
|
app_refresh_screen();
|
|
|
|
|
|
|
|
// Change the main frame title.
|
2014-04-21 06:53:27 +08:00
|
|
|
std::string defaultTitle = PACKAGE " v" VERSION;
|
|
|
|
std::string title;
|
2013-03-28 08:19:35 +08:00
|
|
|
if (docView) {
|
2013-03-12 07:29:45 +08:00
|
|
|
// Prepend the document's filename.
|
2014-07-29 11:53:24 +08:00
|
|
|
title += docView->getDocument()->name();
|
2013-03-12 07:29:45 +08:00
|
|
|
title += " - ";
|
|
|
|
}
|
2014-07-29 11:53:24 +08:00
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
title += defaultTitle;
|
|
|
|
set_window_title(title.c_str());
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t UIContext::countViewsOf(Document* document) const
|
|
|
|
{
|
2013-03-28 08:19:35 +08:00
|
|
|
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
2013-01-21 05:40:37 +08:00
|
|
|
size_t counter = 0;
|
2013-03-28 08:19:35 +08:00
|
|
|
|
|
|
|
for (Workspace::iterator it=workspace->begin(); it != workspace->end(); ++it) {
|
|
|
|
WorkspaceView* view = *it;
|
|
|
|
if (DocumentView* docView = dynamic_cast<DocumentView*>(view)) {
|
|
|
|
if (docView->getDocument() == document) {
|
|
|
|
++counter;
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
2013-03-28 08:19:35 +08:00
|
|
|
|
2013-01-21 05:40:37 +08:00
|
|
|
return counter;
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
Editor* UIContext::activeEditor()
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
2014-07-29 11:53:24 +08:00
|
|
|
DocumentView* view = activeView();
|
|
|
|
if (view)
|
|
|
|
return view->getEditor();
|
2013-01-21 05:40:37 +08:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
void UIContext::onAddDocument(doc::Document* doc)
|
2009-06-01 10:59:15 +08:00
|
|
|
{
|
2014-07-29 11:53:24 +08:00
|
|
|
Context::onAddDocument(doc);
|
2009-06-01 10:59:15 +08:00
|
|
|
|
2013-12-09 07:19:32 +08:00
|
|
|
// We don't create views in batch mode.
|
|
|
|
if (!App::instance()->isGui())
|
|
|
|
return;
|
|
|
|
|
2013-01-21 05:40:37 +08:00
|
|
|
// Add a new view for this document
|
2014-07-29 11:53:24 +08:00
|
|
|
DocumentView* view = new DocumentView(static_cast<app::Document*>(doc), DocumentView::Normal);
|
2013-01-21 05:40:37 +08:00
|
|
|
|
|
|
|
// Add a tab with the new view for the document
|
|
|
|
App::instance()->getMainWindow()->getWorkspace()->addView(view);
|
|
|
|
|
|
|
|
setActiveView(view);
|
|
|
|
view->getEditor()->setDefaultScroll();
|
2009-06-01 10:59:15 +08:00
|
|
|
}
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
void UIContext::onRemoveDocument(doc::Document* doc)
|
2009-06-01 10:59:15 +08:00
|
|
|
{
|
2014-07-29 11:53:24 +08:00
|
|
|
Context::onRemoveDocument(doc);
|
2009-06-01 10:59:15 +08:00
|
|
|
|
2013-03-28 08:19:35 +08:00
|
|
|
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
|
|
|
DocumentViews docViews;
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-03-28 08:19:35 +08:00
|
|
|
// Collect all views related to the document.
|
|
|
|
for (Workspace::iterator it=workspace->begin(); it != workspace->end(); ++it) {
|
|
|
|
WorkspaceView* view = *it;
|
|
|
|
if (DocumentView* docView = dynamic_cast<DocumentView*>(view)) {
|
2014-07-29 11:53:24 +08:00
|
|
|
if (docView->getDocument() == doc) {
|
2013-03-28 08:19:35 +08:00
|
|
|
docViews.push_back(docView);
|
|
|
|
}
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
}
|
2009-06-01 10:59:15 +08:00
|
|
|
|
2013-03-28 08:19:35 +08:00
|
|
|
for (DocumentViews::iterator it=docViews.begin(); it != docViews.end(); ++it) {
|
|
|
|
DocumentView* docView = *it;
|
|
|
|
workspace->removeView(docView);
|
|
|
|
delete docView;
|
|
|
|
}
|
2009-06-01 10:59:15 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 07:29:45 +08:00
|
|
|
void UIContext::onGetActiveLocation(DocumentLocation* location) const
|
2009-06-01 10:59:15 +08:00
|
|
|
{
|
2014-07-29 11:53:24 +08:00
|
|
|
DocumentView* view = activeView();
|
|
|
|
if (view)
|
|
|
|
view->getDocumentLocation(location);
|
2009-06-01 10:59:15 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|