Save fg/bg color selector dialog positions between sessions (fix #1249)

This commit is contained in:
David Capello 2016-09-08 15:34:09 -03:00
parent 92db283cbc
commit efe31b02d9
8 changed files with 90 additions and 38 deletions

View File

@ -202,6 +202,8 @@ ColorBar::ColorBar(int align)
addChild(fgBox);
addChild(bgBox);
m_fgColor.setId("fg_color");
m_bgColor.setId("bg_color");
m_fgColor.setExpansive(true);
m_bgColor.setExpansive(true);

View File

@ -25,6 +25,7 @@
#include "doc/layer.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "gfx/rect_io.h"
#include "ui/size_hint_event.h"
#include "ui/ui.h"
@ -105,6 +106,11 @@ bool ColorButton::onProcessMessage(Message* msg)
{
switch (msg->type()) {
case kOpenMessage:
if (!m_windowDefaultBounds.isEmpty())
openSelectorDialog();
break;
case kCloseMessage:
if (m_window && m_window->isVisible())
m_window->closeWindow(NULL);
@ -236,34 +242,64 @@ void ColorButton::onClick(Event& ev)
}
}
void ColorButton::onLoadLayout(ui::LoadLayoutEvent& ev)
{
if (m_canPinSelector) {
bool pinned = false;
ev.stream() >> pinned;
if (ev.stream() && pinned)
ev.stream() >> m_windowDefaultBounds;
}
}
void ColorButton::onSaveLayout(ui::SaveLayoutEvent& ev)
{
if (m_canPinSelector && m_window && m_window->isPinned())
ev.stream() << 1 << ' ' << m_window->bounds();
else
ev.stream() << 0;
}
void ColorButton::openSelectorDialog()
{
int x, y;
bool pinned = (!m_windowDefaultBounds.isEmpty());
if (m_window == NULL) {
m_window = new ColorPopup(m_canPinSelector);
m_window->ColorChange.connect(&ColorButton::onWindowColorChange, this);
}
if (pinned)
m_window->setPinned(true);
m_window->setColor(m_color, ColorPopup::ChangeType);
m_window->openWindow();
x = MID(0, bounds().x, ui::display_w()-m_window->bounds().w);
if (bounds().y2() <= ui::display_h()-m_window->bounds().h)
y = MAX(0, bounds().y2());
else
y = MAX(0, bounds().y-m_window->bounds().h);
m_window->positionWindow(x, y);
gfx::Rect winBounds = m_windowDefaultBounds;
if (!pinned) {
winBounds = m_window->bounds();
winBounds.x = MID(0, bounds().x, ui::display_w()-winBounds.w);
if (bounds().y2() <= ui::display_h()-winBounds.h)
winBounds.y = MAX(0, bounds().y2());
else
winBounds.y = MAX(0, bounds().y-winBounds.h);
}
winBounds.x = MID(0, winBounds.x, ui::display_w()-winBounds.w);
winBounds.y = MID(0, winBounds.y, ui::display_h()-winBounds.h);
m_window->setBounds(winBounds);
m_window->manager()->dispatchMessages();
m_window->layout();
// Setup the hot-region
gfx::Rect rc = bounds().createUnion(m_window->bounds());
rc.enlarge(8);
gfx::Region rgn(rc);
static_cast<PopupWindow*>(m_window)->setHotRegion(rgn);
if (!pinned) {
gfx::Rect rc = bounds().createUnion(m_window->bounds());
rc.enlarge(8);
gfx::Region rgn(rc);
static_cast<PopupWindow*>(m_window)->setHotRegion(rgn);
}
m_windowDefaultBounds = gfx::Rect();
}
void ColorButton::closeSelectorDialog()

View File

@ -45,6 +45,8 @@ namespace app {
void onSizeHint(ui::SizeHintEvent& ev) override;
void onPaint(ui::PaintEvent& ev) override;
void onClick(ui::Event& ev) override;
void onLoadLayout(ui::LoadLayoutEvent& ev) override;
void onSaveLayout(ui::SaveLayoutEvent& ev) override;
private:
void openSelectorDialog();
@ -55,6 +57,7 @@ namespace app {
app::Color m_color;
PixelFormat m_pixelFormat;
ColorPopup* m_window;
gfx::Rect m_windowDefaultBounds;
bool m_dependOnLayer;
bool m_canPinSelector;
};

View File

@ -45,6 +45,14 @@ bool PopupWindowPin::showPin(bool state)
m_pin.setVisible(state);
}
void PopupWindowPin::setPinned(bool pinned)
{
m_pin.setSelected(pinned);
Event ev(this);
onPinClick(ev);
}
void PopupWindowPin::onPinClick(Event& ev)
{
if (m_pin.isSelected()) {
@ -62,14 +70,11 @@ bool PopupWindowPin::onProcessMessage(Message* msg)
{
switch (msg->type()) {
case kOpenMessage:
m_pin.setSelected(false);
makeFixed();
break;
case kCloseMessage:
m_pin.setSelected(false);
case kOpenMessage: {
if (!isPinned())
makeFixed();
break;
}
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -18,6 +18,8 @@ namespace app {
PopupWindowPin(const std::string& text, ClickBehavior clickBehavior);
bool showPin(bool state);
bool isPinned() const { return m_pin.isSelected(); }
void setPinned(bool pinned);
protected:
virtual bool onProcessMessage(ui::Message* msg) override;

View File

@ -1,4 +1,4 @@
Copyright (c) 2001-2014 David Capello
Copyright (c) 2001-2016 David Capello
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -1,5 +1,5 @@
// Aseprite Gfx Library
// Copyright (C) 2001-2014 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -13,8 +13,7 @@
namespace gfx {
inline std::ostream& operator<<(std::ostream& os, const Rect& rect)
{
inline std::ostream& operator<<(std::ostream& os, const Rect& rect) {
return os << "("
<< rect.x << ", "
<< rect.y << ", "
@ -22,6 +21,22 @@ namespace gfx {
<< rect.h << ")";
}
inline std::istream& operator>>(std::istream& in, Rect& rect) {
while (in && in.get() != '(')
;
if (!in)
return in;
char chr;
in >> rect.x >> chr
>> rect.y >> chr
>> rect.w >> chr
>> rect.h >> chr;
return in;
}
}
#endif

View File

@ -1,5 +1,5 @@
// Aseprite Gfx Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -10,24 +10,13 @@
#include <gtest/gtest.h>
#include "gfx/region.h"
#include "gfx/point.h"
#include "gfx/rect_io.h"
#include "gfx/region.h"
using namespace std;
using namespace gfx;
namespace gfx {
ostream& operator<<(ostream& os, const Rect& rect) {
return os << "("
<< rect.x << ", "
<< rect.y << ", "
<< rect.w << ", "
<< rect.h << ")";
}
}
ostream& operator<<(ostream& os, const Region& rgn)
{
os << "{";