mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-11 09:40:42 +00:00
Move display flip logic to ui library (ui::Manager class)
This commit is contained in:
parent
46fa7e18cf
commit
dd94925cf7
@ -525,7 +525,7 @@ void App::run()
|
||||
sendCrash.search();
|
||||
|
||||
// Run the GUI main message loop
|
||||
gui_run();
|
||||
ui::Manager::getDefault()->run();
|
||||
}
|
||||
|
||||
// Start shell to execute scripts.
|
||||
|
@ -16,8 +16,6 @@
|
||||
#include "app/ini_file.h"
|
||||
#include "app/launcher.h"
|
||||
#include "app/load_widget.h"
|
||||
#include "app/modules/editors.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/pref/preferences.h"
|
||||
#include "app/resource_finder.h"
|
||||
#include "app/send_crash.h"
|
||||
@ -27,6 +25,7 @@
|
||||
#include "base/path.h"
|
||||
#include "doc/image.h"
|
||||
#include "render/render.h"
|
||||
#include "she/display.h"
|
||||
#include "she/system.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
@ -233,8 +232,12 @@ public:
|
||||
"||&OK", warnings.c_str());
|
||||
}
|
||||
|
||||
if (reset_screen)
|
||||
gui_setup_screen();
|
||||
if (reset_screen) {
|
||||
ui::Manager* manager = ui::Manager::getDefault();
|
||||
she::Display* display = manager->getDisplay();
|
||||
display->setScale(newScreenScale);
|
||||
manager->setDisplay(display);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "base/thread.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/system.h"
|
||||
|
||||
namespace app {
|
||||
@ -87,9 +88,7 @@ void UndoCommand::onExecute(Context* context)
|
||||
current_editor->drawSpriteClipped(
|
||||
gfx::Region(gfx::Rect(0, 0, sprite->width(), sprite->height())));
|
||||
|
||||
ui::dirty_display_flag = true;
|
||||
gui_feedback();
|
||||
|
||||
current_editor->getManager()->flipDisplay();
|
||||
base::this_thread::sleep_for(0.01);
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ class CustomizedGuiManager : public Manager
|
||||
protected:
|
||||
bool onProcessMessage(Message* msg) override;
|
||||
LayoutIO* onGetLayoutIO() override { return this; }
|
||||
void onNewDisplayConfiguration() override;
|
||||
|
||||
// LayoutIO implementation
|
||||
std::string loadLayout(Widget* widget) override;
|
||||
@ -154,8 +155,6 @@ int init_module_gui()
|
||||
if (maximized)
|
||||
main_display->maximize();
|
||||
|
||||
gui_setup_screen();
|
||||
|
||||
// Set graphics options for next time
|
||||
save_gui_config();
|
||||
|
||||
@ -214,47 +213,6 @@ void update_screen_for_document(const Document* document)
|
||||
}
|
||||
}
|
||||
|
||||
void gui_run()
|
||||
{
|
||||
manager->run();
|
||||
}
|
||||
|
||||
void gui_feedback()
|
||||
{
|
||||
OverlayManager* overlays = OverlayManager::instance();
|
||||
|
||||
ui::update_cursor_overlay();
|
||||
|
||||
// Avoid updating a non-dirty screen over and over again.
|
||||
#if 0 // TODO It doesn't work yet
|
||||
if (!dirty_display_flag)
|
||||
return;
|
||||
#endif
|
||||
|
||||
// Draw overlays.
|
||||
overlays->captureOverlappedAreas();
|
||||
overlays->drawOverlays();
|
||||
|
||||
if (!manager->getDisplay()->flip()) {
|
||||
// In case that the display was resized.
|
||||
gui_setup_screen();
|
||||
}
|
||||
else
|
||||
overlays->restoreOverlappedAreas();
|
||||
|
||||
dirty_display_flag = false;
|
||||
}
|
||||
|
||||
// Refresh the UI display, font, etc.
|
||||
void gui_setup_screen()
|
||||
{
|
||||
main_display->setScale(get_screen_scale());
|
||||
ui::set_display(main_display);
|
||||
manager->layout();
|
||||
|
||||
save_gui_config();
|
||||
}
|
||||
|
||||
void load_window_pos(Widget* window, const char *section)
|
||||
{
|
||||
// Default position
|
||||
@ -397,10 +355,6 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
||||
}
|
||||
break;
|
||||
|
||||
case kQueueProcessingMessage:
|
||||
gui_feedback();
|
||||
break;
|
||||
|
||||
case kKeyDownMessage: {
|
||||
#ifdef _DEBUG
|
||||
// Left Shift+Ctrl+Q generates a crash (useful to test the anticrash feature)
|
||||
@ -516,6 +470,12 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
||||
return Manager::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void CustomizedGuiManager::onNewDisplayConfiguration()
|
||||
{
|
||||
Manager::onNewDisplayConfiguration();
|
||||
save_gui_config();
|
||||
}
|
||||
|
||||
std::string CustomizedGuiManager::loadLayout(Widget* widget)
|
||||
{
|
||||
if (widget->getRoot() == NULL)
|
||||
|
@ -37,10 +37,6 @@ namespace app {
|
||||
|
||||
void update_screen_for_document(const Document* document);
|
||||
|
||||
void gui_run();
|
||||
void gui_feedback();
|
||||
void gui_setup_screen();
|
||||
|
||||
void load_window_pos(ui::Widget* window, const char *section);
|
||||
void save_window_pos(ui::Widget* window, const char *section);
|
||||
|
||||
|
@ -790,7 +790,8 @@ void Editor::flashCurrentLayer()
|
||||
|
||||
drawSpriteClipped(gfx::Region(
|
||||
gfx::Rect(0, 0, m_sprite->width(), m_sprite->height())));
|
||||
gui_feedback();
|
||||
|
||||
getManager()->flipDisplay();
|
||||
|
||||
m_document->setExtraCelBlendMode(BlendMode::NORMAL);
|
||||
m_document->destroyExtraCel();
|
||||
|
@ -147,6 +147,8 @@ void Manager::setDisplay(she::Display* display)
|
||||
{
|
||||
m_display = display;
|
||||
m_eventQueue = she::instance()->eventQueue();
|
||||
|
||||
onNewDisplayConfiguration();
|
||||
}
|
||||
|
||||
void Manager::setClipboard(she::Clipboard* clipboard)
|
||||
@ -169,6 +171,24 @@ void Manager::run()
|
||||
loop.pumpMessages();
|
||||
}
|
||||
|
||||
void Manager::flipDisplay()
|
||||
{
|
||||
OverlayManager* overlays = OverlayManager::instance();
|
||||
|
||||
update_cursor_overlay();
|
||||
|
||||
// Draw overlays.
|
||||
overlays->captureOverlappedAreas();
|
||||
overlays->drawOverlays();
|
||||
|
||||
if (!m_display->flip()) {
|
||||
// In case that the display was resized.
|
||||
onNewDisplayConfiguration();
|
||||
}
|
||||
else
|
||||
overlays->restoreOverlappedAreas();
|
||||
}
|
||||
|
||||
bool Manager::generateMessages()
|
||||
{
|
||||
// First check: there are windows to manage?
|
||||
@ -454,6 +474,7 @@ void Manager::dispatchMessages()
|
||||
get_mouse_position(), _internal_get_mouse_buttons()));
|
||||
|
||||
pumpQueue();
|
||||
flipDisplay();
|
||||
}
|
||||
|
||||
void Manager::addToGarbage(Widget* widget)
|
||||
@ -1020,6 +1041,20 @@ LayoutIO* Manager::onGetLayoutIO()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Manager::onNewDisplayConfiguration()
|
||||
{
|
||||
if (m_display) {
|
||||
int w = m_display->width() / m_display->scale();
|
||||
int h = m_display->height() / m_display->scale();
|
||||
if ((getBounds().w != w ||
|
||||
getBounds().h != h)) {
|
||||
setBounds(gfx::Rect(0, 0, w, h));
|
||||
}
|
||||
}
|
||||
|
||||
_internal_set_mouse_display(m_display);
|
||||
}
|
||||
|
||||
void Manager::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int w = 0, h = 0;
|
||||
@ -1131,8 +1166,6 @@ void Manager::pumpQueue()
|
||||
gfx::Rect oldClip = surface->getClipBounds();
|
||||
|
||||
if (surface->intersectClipRect(paintMsg->rect())) {
|
||||
dirty_display_flag = true;
|
||||
|
||||
#ifdef REPORT_EVENTS
|
||||
std::cout << " - clip("
|
||||
<< paintMsg->rect().x << ", "
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
// Copyright (C) 2001-2013, 2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -39,8 +39,12 @@ namespace ui {
|
||||
void setDisplay(she::Display* display);
|
||||
void setClipboard(she::Clipboard* clipboard);
|
||||
|
||||
// Executes the main message loop.
|
||||
void run();
|
||||
|
||||
// Refreshes the real display with the UI content.
|
||||
void flipDisplay();
|
||||
|
||||
// Returns true if there are messages in the queue to be
|
||||
// distpatched through jmanager_dispatch_messages().
|
||||
bool generateMessages();
|
||||
@ -90,6 +94,7 @@ namespace ui {
|
||||
void onPreferredSize(PreferredSizeEvent& ev) override;
|
||||
void onBroadcastMouseMessage(WidgetsList& targets) override;
|
||||
virtual LayoutIO* onGetLayoutIO();
|
||||
virtual void onNewDisplayConfiguration();
|
||||
|
||||
private:
|
||||
void generateSetCursorMessage(const gfx::Point& mousePos);
|
||||
|
@ -24,8 +24,6 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
bool dirty_display_flag = true;
|
||||
|
||||
// Current mouse cursor type.
|
||||
|
||||
static CursorType mouse_cursor_type = kNoCursor;
|
||||
@ -140,8 +138,6 @@ static void update_mouse_cursor()
|
||||
// Hide the overlay if we are using a native cursor.
|
||||
update_mouse_overlay(NULL);
|
||||
}
|
||||
|
||||
dirty_display_flag = true;
|
||||
}
|
||||
|
||||
int init_system()
|
||||
@ -152,7 +148,7 @@ int init_system()
|
||||
|
||||
void exit_system()
|
||||
{
|
||||
set_display(NULL);
|
||||
_internal_set_mouse_display(NULL);
|
||||
update_mouse_overlay(NULL);
|
||||
}
|
||||
|
||||
@ -161,27 +157,13 @@ int clock()
|
||||
return she::clock_value();
|
||||
}
|
||||
|
||||
void set_display(she::Display* display)
|
||||
void _internal_set_mouse_display(she::Display* display)
|
||||
{
|
||||
CursorType cursor = get_mouse_cursor();
|
||||
|
||||
set_mouse_cursor(kNoCursor);
|
||||
mouse_display = display;
|
||||
|
||||
if (display) {
|
||||
Manager* manager = Manager::getDefault();
|
||||
if (manager) {
|
||||
manager->setDisplay(display);
|
||||
|
||||
// Update default-manager size
|
||||
if ((manager->getBounds().w != ui::display_w() ||
|
||||
manager->getBounds().h != ui::display_h())) {
|
||||
manager->setBounds(gfx::Rect(0, 0, ui::display_w(), ui::display_h()));
|
||||
}
|
||||
}
|
||||
|
||||
if (display)
|
||||
set_mouse_cursor(cursor); // Restore mouse cursor
|
||||
}
|
||||
}
|
||||
|
||||
int display_w()
|
||||
@ -208,7 +190,6 @@ void update_cursor_overlay()
|
||||
|
||||
if (newPos != mouse_cursor_overlay->getPosition()) {
|
||||
mouse_cursor_overlay->moveOverlay(newPos);
|
||||
dirty_display_flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
// Copyright (C) 2001-2013, 2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -19,11 +19,6 @@ namespace ui {
|
||||
|
||||
class Widget;
|
||||
|
||||
// Simple flag to indicate that something in the screen was modified
|
||||
// so a flip to the real screen is needed.
|
||||
extern bool dirty_display_flag;
|
||||
|
||||
void set_display(she::Display* display);
|
||||
int display_w();
|
||||
int display_h();
|
||||
|
||||
@ -44,6 +39,7 @@ namespace ui {
|
||||
void hide_mouse_cursor();
|
||||
void show_mouse_cursor();
|
||||
|
||||
void _internal_set_mouse_display(she::Display* display);
|
||||
void _internal_no_mouse_position();
|
||||
void _internal_set_mouse_position(const gfx::Point& newPos);
|
||||
void _internal_set_mouse_buttons(MouseButtons buttons);
|
||||
|
Loading…
x
Reference in New Issue
Block a user