mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-16 05:42:32 +00:00
Save fg/bg color selector dialog positions between sessions (fix #1249)
This commit is contained in:
parent
92db283cbc
commit
efe31b02d9
@ -202,6 +202,8 @@ ColorBar::ColorBar(int align)
|
|||||||
addChild(fgBox);
|
addChild(fgBox);
|
||||||
addChild(bgBox);
|
addChild(bgBox);
|
||||||
|
|
||||||
|
m_fgColor.setId("fg_color");
|
||||||
|
m_bgColor.setId("bg_color");
|
||||||
m_fgColor.setExpansive(true);
|
m_fgColor.setExpansive(true);
|
||||||
m_bgColor.setExpansive(true);
|
m_bgColor.setExpansive(true);
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/site.h"
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
#include "gfx/rect_io.h"
|
||||||
#include "ui/size_hint_event.h"
|
#include "ui/size_hint_event.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
@ -105,6 +106,11 @@ bool ColorButton::onProcessMessage(Message* msg)
|
|||||||
{
|
{
|
||||||
switch (msg->type()) {
|
switch (msg->type()) {
|
||||||
|
|
||||||
|
case kOpenMessage:
|
||||||
|
if (!m_windowDefaultBounds.isEmpty())
|
||||||
|
openSelectorDialog();
|
||||||
|
break;
|
||||||
|
|
||||||
case kCloseMessage:
|
case kCloseMessage:
|
||||||
if (m_window && m_window->isVisible())
|
if (m_window && m_window->isVisible())
|
||||||
m_window->closeWindow(NULL);
|
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()
|
void ColorButton::openSelectorDialog()
|
||||||
{
|
{
|
||||||
int x, y;
|
bool pinned = (!m_windowDefaultBounds.isEmpty());
|
||||||
|
|
||||||
if (m_window == NULL) {
|
if (m_window == NULL) {
|
||||||
m_window = new ColorPopup(m_canPinSelector);
|
m_window = new ColorPopup(m_canPinSelector);
|
||||||
m_window->ColorChange.connect(&ColorButton::onWindowColorChange, this);
|
m_window->ColorChange.connect(&ColorButton::onWindowColorChange, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pinned)
|
||||||
|
m_window->setPinned(true);
|
||||||
|
|
||||||
m_window->setColor(m_color, ColorPopup::ChangeType);
|
m_window->setColor(m_color, ColorPopup::ChangeType);
|
||||||
m_window->openWindow();
|
m_window->openWindow();
|
||||||
|
|
||||||
x = MID(0, bounds().x, ui::display_w()-m_window->bounds().w);
|
gfx::Rect winBounds = m_windowDefaultBounds;
|
||||||
if (bounds().y2() <= ui::display_h()-m_window->bounds().h)
|
if (!pinned) {
|
||||||
y = MAX(0, bounds().y2());
|
winBounds = m_window->bounds();
|
||||||
else
|
winBounds.x = MID(0, bounds().x, ui::display_w()-winBounds.w);
|
||||||
y = MAX(0, bounds().y-m_window->bounds().h);
|
if (bounds().y2() <= ui::display_h()-winBounds.h)
|
||||||
|
winBounds.y = MAX(0, bounds().y2());
|
||||||
m_window->positionWindow(x, y);
|
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->manager()->dispatchMessages();
|
||||||
m_window->layout();
|
m_window->layout();
|
||||||
|
|
||||||
// Setup the hot-region
|
// Setup the hot-region
|
||||||
gfx::Rect rc = bounds().createUnion(m_window->bounds());
|
if (!pinned) {
|
||||||
rc.enlarge(8);
|
gfx::Rect rc = bounds().createUnion(m_window->bounds());
|
||||||
gfx::Region rgn(rc);
|
rc.enlarge(8);
|
||||||
static_cast<PopupWindow*>(m_window)->setHotRegion(rgn);
|
gfx::Region rgn(rc);
|
||||||
|
static_cast<PopupWindow*>(m_window)->setHotRegion(rgn);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_windowDefaultBounds = gfx::Rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorButton::closeSelectorDialog()
|
void ColorButton::closeSelectorDialog()
|
||||||
|
@ -45,6 +45,8 @@ namespace app {
|
|||||||
void onSizeHint(ui::SizeHintEvent& ev) override;
|
void onSizeHint(ui::SizeHintEvent& ev) override;
|
||||||
void onPaint(ui::PaintEvent& ev) override;
|
void onPaint(ui::PaintEvent& ev) override;
|
||||||
void onClick(ui::Event& ev) override;
|
void onClick(ui::Event& ev) override;
|
||||||
|
void onLoadLayout(ui::LoadLayoutEvent& ev) override;
|
||||||
|
void onSaveLayout(ui::SaveLayoutEvent& ev) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void openSelectorDialog();
|
void openSelectorDialog();
|
||||||
@ -55,6 +57,7 @@ namespace app {
|
|||||||
app::Color m_color;
|
app::Color m_color;
|
||||||
PixelFormat m_pixelFormat;
|
PixelFormat m_pixelFormat;
|
||||||
ColorPopup* m_window;
|
ColorPopup* m_window;
|
||||||
|
gfx::Rect m_windowDefaultBounds;
|
||||||
bool m_dependOnLayer;
|
bool m_dependOnLayer;
|
||||||
bool m_canPinSelector;
|
bool m_canPinSelector;
|
||||||
};
|
};
|
||||||
|
@ -45,6 +45,14 @@ bool PopupWindowPin::showPin(bool state)
|
|||||||
m_pin.setVisible(state);
|
m_pin.setVisible(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PopupWindowPin::setPinned(bool pinned)
|
||||||
|
{
|
||||||
|
m_pin.setSelected(pinned);
|
||||||
|
|
||||||
|
Event ev(this);
|
||||||
|
onPinClick(ev);
|
||||||
|
}
|
||||||
|
|
||||||
void PopupWindowPin::onPinClick(Event& ev)
|
void PopupWindowPin::onPinClick(Event& ev)
|
||||||
{
|
{
|
||||||
if (m_pin.isSelected()) {
|
if (m_pin.isSelected()) {
|
||||||
@ -62,14 +70,11 @@ bool PopupWindowPin::onProcessMessage(Message* msg)
|
|||||||
{
|
{
|
||||||
switch (msg->type()) {
|
switch (msg->type()) {
|
||||||
|
|
||||||
case kOpenMessage:
|
case kOpenMessage: {
|
||||||
m_pin.setSelected(false);
|
if (!isPinned())
|
||||||
makeFixed();
|
makeFixed();
|
||||||
break;
|
|
||||||
|
|
||||||
case kCloseMessage:
|
|
||||||
m_pin.setSelected(false);
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (C) 2001-2016 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
// the End-User License Agreement for Aseprite.
|
// the End-User License Agreement for Aseprite.
|
||||||
@ -18,6 +18,8 @@ namespace app {
|
|||||||
PopupWindowPin(const std::string& text, ClickBehavior clickBehavior);
|
PopupWindowPin(const std::string& text, ClickBehavior clickBehavior);
|
||||||
|
|
||||||
bool showPin(bool state);
|
bool showPin(bool state);
|
||||||
|
bool isPinned() const { return m_pin.isSelected(); }
|
||||||
|
void setPinned(bool pinned);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool onProcessMessage(ui::Message* msg) override;
|
virtual bool onProcessMessage(ui::Message* msg) override;
|
||||||
|
@ -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
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Gfx Library
|
// 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.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -13,8 +13,7 @@
|
|||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& os, const Rect& rect)
|
inline std::ostream& operator<<(std::ostream& os, const Rect& rect) {
|
||||||
{
|
|
||||||
return os << "("
|
return os << "("
|
||||||
<< rect.x << ", "
|
<< rect.x << ", "
|
||||||
<< rect.y << ", "
|
<< rect.y << ", "
|
||||||
@ -22,6 +21,22 @@ namespace gfx {
|
|||||||
<< rect.h << ")";
|
<< 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
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Gfx Library
|
// 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.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -10,24 +10,13 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "gfx/region.h"
|
|
||||||
#include "gfx/point.h"
|
#include "gfx/point.h"
|
||||||
|
#include "gfx/rect_io.h"
|
||||||
|
#include "gfx/region.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gfx;
|
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)
|
ostream& operator<<(ostream& os, const Region& rgn)
|
||||||
{
|
{
|
||||||
os << "{";
|
os << "{";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user