Change Window() ctor to avoid ambiguity (DesktopWindow, WithoutTitleBar, or WithTitleBar)

In this way we know at the moment of the creation of the window if it
will need the close button.

Issue #280.
https://github.com/aseprite/aseprite/pull/6
This commit is contained in:
David Capello 2013-11-23 17:47:57 -03:00
parent 7dc8e548be
commit ad0b28bd63
21 changed files with 35 additions and 33 deletions

View File

@ -47,7 +47,7 @@ AboutCommand::AboutCommand()
void AboutCommand::onExecute(Context* context) void AboutCommand::onExecute(Context* context)
{ {
base::UniquePtr<Window> window(new Window(false, "About " PACKAGE)); base::UniquePtr<Window> window(new Window(Window::WithTitleBar, "About " PACKAGE));
Box* box1 = new Box(JI_VERTICAL); Box* box1 = new Box(JI_VERTICAL);
Grid* grid = new Grid(2, false); Grid* grid = new Grid(2, false);
Label* title = new Label(PACKAGE " v" VERSION); Label* title = new Label(PACKAGE " v" VERSION);

View File

@ -55,7 +55,7 @@ class CanvasSizeWindow : public Window
{ {
public: public:
CanvasSizeWindow(int left, int top, int right, int bottom) CanvasSizeWindow(int left, int top, int right, int bottom)
: Window(false, "Canvas Size") : Window(WithTitleBar, "Canvas Size")
, m_editor(current_editor) , m_editor(current_editor)
, m_rect(-left, -top, , m_rect(-left, -top,
current_editor->getSprite()->getWidth() + left + right, current_editor->getSprite()->getWidth() + left + right,

View File

@ -36,7 +36,7 @@ using namespace ui;
class DeveloperConsole : public Window { class DeveloperConsole : public Window {
public: public:
DeveloperConsole() DeveloperConsole()
: Window(false, "Developer Console") : Window(WithTitleBar, "Developer Console")
, m_vbox(JI_VERTICAL) , m_vbox(JI_VERTICAL)
{ {
m_vbox.addChild(&m_docs); m_vbox.addChild(&m_docs);

View File

@ -55,7 +55,7 @@ class ExportSpriteSheetWindow : public Window {
public: public:
ExportSpriteSheetWindow(Context* context) ExportSpriteSheetWindow(Context* context)
: Window(false, "Export Sprite Sheet") : Window(WithTitleBar, "Export Sprite Sheet")
, m_context(context) , m_context(context)
, m_document(context->getActiveDocument()) , m_document(context->getActiveDocument())
, m_grid(4, false) , m_grid(4, false)

View File

@ -58,7 +58,7 @@ class ImportSpriteSheetWindow : public Window,
public SelectBoxDelegate { public SelectBoxDelegate {
public: public:
ImportSpriteSheetWindow(Context* context) ImportSpriteSheetWindow(Context* context)
: Window(false, "Import Sprite Sheet") : Window(WithTitleBar, "Import Sprite Sheet")
, m_context(context) , m_context(context)
, m_document(NULL) , m_document(NULL)
, m_grid(4, false) , m_grid(4, false)

View File

@ -62,7 +62,7 @@ void LayerPropertiesCommand::onExecute(Context* context)
const ContextReader reader(context); const ContextReader reader(context);
const Layer* layer = reader.layer(); const Layer* layer = reader.layer();
base::UniquePtr<Window> window(new Window(false, "Layer Properties")); base::UniquePtr<Window> window(new Window(Window::WithTitleBar, "Layer Properties"));
Box* box1 = new Box(JI_VERTICAL); Box* box1 = new Box(JI_VERTICAL);
Box* box2 = new Box(JI_HORIZONTAL); Box* box2 = new Box(JI_HORIZONTAL);
Box* box3 = new Box(JI_HORIZONTAL + JI_HOMOGENEOUS); Box* box3 = new Box(JI_HORIZONTAL + JI_HOMOGENEOUS);

View File

@ -100,7 +100,7 @@ void MaskByColorCommand::onExecute(Context* context)
if (!image) if (!image)
return; return;
base::UniquePtr<Window> window(new Window(false, "Mask by Color")); base::UniquePtr<Window> window(new Window(Window::WithTitleBar, "Mask by Color"));
box1 = new Box(JI_VERTICAL); box1 = new Box(JI_VERTICAL);
box2 = new Box(JI_HORIZONTAL); box2 = new Box(JI_HORIZONTAL);
box3 = new Box(JI_HORIZONTAL); box3 = new Box(JI_HORIZONTAL);

View File

@ -243,7 +243,7 @@ void PaletteEditorCommand::onExecute(Context* context)
// Based on ColorSelector class. // Based on ColorSelector class.
PaletteEntryEditor::PaletteEntryEditor() PaletteEntryEditor::PaletteEntryEditor()
: Window(false, "Palette Editor (F4)") : Window(WithTitleBar, "Palette Editor (F4)")
, m_vbox(JI_VERTICAL) , m_vbox(JI_VERTICAL)
, m_topBox(JI_HORIZONTAL) , m_topBox(JI_HORIZONTAL)
, m_bottomBox(JI_HORIZONTAL) , m_bottomBox(JI_HORIZONTAL)

View File

@ -38,7 +38,7 @@ FilterWindow::FilterWindow(const char* title, const char* cfgSection,
WithChannels withChannels, WithChannels withChannels,
WithTiled withTiled, WithTiled withTiled,
TiledMode tiledMode) TiledMode tiledMode)
: Window(false, title) : Window(WithTitleBar, title)
, m_cfgSection(cfgSection) , m_cfgSection(cfgSection)
, m_filterMgr(filterMgr) , m_filterMgr(filterMgr)
, m_hbox(JI_HORIZONTAL) , m_hbox(JI_HORIZONTAL)

View File

@ -54,7 +54,7 @@ Console::Console()
console_counter > 1) console_counter > 1)
return; return;
else { else {
Window* window = new Window(false, "Errors Console"); Window* window = new Window(Window::WithTitleBar, "Errors Console");
Grid* grid = new Grid(1, false); Grid* grid = new Grid(1, false);
View* view = new View(); View* view = new View();
TextBox* textbox = new TextBox("", JI_WORDWRAP); TextBox* textbox = new TextBox("", JI_WORDWRAP);

View File

@ -194,7 +194,7 @@ public:
}; };
FileSelector::FileSelector() FileSelector::FileSelector()
: Window(false, "") : Window(WithTitleBar, "")
{ {
app::WidgetLoader loader; app::WidgetLoader loader;
loader.addWidgetType("filenameentry", new CustomFileNameEntryCreator); loader.addWidgetType("filenameentry", new CustomFileNameEntryCreator);

View File

@ -49,7 +49,7 @@ namespace app {
using namespace ui; using namespace ui;
MainWindow::MainWindow() MainWindow::MainWindow()
: Window(true, "") : Window(DesktopWindow)
, m_lastSplitterPos(0.0) , m_lastSplitterPos(0.0)
, m_lastTimelineSplitterPos(75.0) , m_lastTimelineSplitterPos(75.0)
, m_advancedMode(false) , m_advancedMode(false)

View File

@ -110,7 +110,7 @@ private:
}; };
MiniEditorWindow::MiniEditorWindow() MiniEditorWindow::MiniEditorWindow()
: Window(false, "Mini-Editor") : Window(WithTitleBar, "Mini-Editor")
, m_docView(NULL) , m_docView(NULL)
, m_playButton(new MiniPlayButton()) , m_playButton(new MiniPlayButton())
, m_playTimer(10) , m_playTimer(10)

View File

@ -385,15 +385,14 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
/* window */ /* window */
else if (elem_name == "window") { else if (elem_name == "window") {
const char *text = elem->Attribute("text"); const char *text = elem->Attribute("text");
bool desktop = bool_attr_is_true(elem, "desktop");
if (text) { if (desktop)
bool desktop = bool_attr_is_true(elem, "desktop"); widget = new Window(Window::DesktopWindow);
else if (text)
if (desktop) widget = new Window(Window::WithTitleBar, TRANSLATE_ATTR(text));
widget = new Window(true, ""); else
else widget = new Window(Window::WithoutTitleBar);
widget = new Window(false, TRANSLATE_ATTR(text));
}
} }
/* colorpicker */ /* colorpicker */
else if (elem_name == "colorpicker") { else if (elem_name == "colorpicker") {

View File

@ -42,7 +42,7 @@
namespace ui { namespace ui {
Alert::Alert() Alert::Alert()
: Window(false, "") : Window(WithTitleBar)
{ {
// Do nothing // Do nothing
} }

View File

@ -474,7 +474,7 @@ void ComboBox::onButtonClick(Event& ev)
void ComboBox::openListBox() void ComboBox::openListBox()
{ {
if (!m_window) { if (!m_window) {
m_window = new Window(false, ""); m_window = new Window(Window::WithoutTitleBar);
View* view = new View(); View* view = new View();
m_listbox = new ComboBoxListBox(this); m_listbox = new ComboBoxListBox(this);
m_window->setOnTop(true); m_window->setOnTop(true);

View File

@ -90,7 +90,7 @@ class CustomizedWindowForMenuBox : public Window
{ {
public: public:
CustomizedWindowForMenuBox(MenuBox* menubox) CustomizedWindowForMenuBox(MenuBox* menubox)
: Window(false, "") : Window(WithoutTitleBar, "")
{ {
setMoveable(false); // Can't move the window setMoveable(false); // Can't move the window
addChild(menubox); addChild(menubox);
@ -272,7 +272,7 @@ void Menu::showPopup(int x, int y)
} while (jmouse_b(0) != kButtonNone); } while (jmouse_b(0) != kButtonNone);
// New window and new menu-box // New window and new menu-box
Window* window = new Window(false, ""); Window* window = new Window(Window::WithoutTitleBar);
MenuBox* menubox = new MenuBox(); MenuBox* menubox = new MenuBox();
MenuBaseData* base = menubox->createBase(); MenuBaseData* base = menubox->createBase();
base->was_clicked = true; base->was_clicked = true;

View File

@ -22,7 +22,7 @@ namespace ui {
using namespace gfx; using namespace gfx;
PopupWindow::PopupWindow(const base::string& text, bool close_on_buttonpressed) PopupWindow::PopupWindow(const base::string& text, bool close_on_buttonpressed)
: Window(false, text) : Window(WithTitleBar, text)
{ {
m_close_on_buttonpressed = close_on_buttonpressed; m_close_on_buttonpressed = close_on_buttonpressed;
m_filtering = false; m_filtering = false;

View File

@ -152,7 +152,7 @@ void TooltipManager::onTick()
// TipWindow // TipWindow
TipWindow::TipWindow(const char *text, bool close_on_buttonpressed) TipWindow::TipWindow(const char *text, bool close_on_buttonpressed)
: Window(false, text) : Window(WithTitleBar, text)
{ {
m_close_on_buttonpressed = close_on_buttonpressed; m_close_on_buttonpressed = close_on_buttonpressed;
m_filtering = false; m_filtering = false;

View File

@ -33,21 +33,22 @@ enum {
static gfx::Point clickedMousePos; static gfx::Point clickedMousePos;
static gfx::Rect* clickedWindowPos = NULL; static gfx::Rect* clickedWindowPos = NULL;
Window::Window(bool desktop, const base::string& text) Window::Window(Type type, const base::string& text)
: Widget(kWindowWidget) : Widget(kWindowWidget)
{ {
m_killer = NULL; m_killer = NULL;
m_isDesktop = desktop; m_isDesktop = (type == DesktopWindow);
m_isMoveable = !desktop; m_isMoveable = !m_isDesktop;
m_isSizeable = !desktop; m_isSizeable = !m_isDesktop;
m_isOnTop = false; m_isOnTop = false;
m_isWantFocus = true; m_isWantFocus = true;
m_isForeground = false; m_isForeground = false;
m_isAutoRemap = true; m_isAutoRemap = true;
setVisible(false); setVisible(false);
setText(text);
setAlign(JI_LEFT | JI_MIDDLE); setAlign(JI_LEFT | JI_MIDDLE);
if (type == WithTitleBar)
setText(text);
initTheme(); initTheme();
} }

View File

@ -20,7 +20,9 @@ namespace ui {
class Window : public Widget class Window : public Widget
{ {
public: public:
Window(bool isDesktop, const base::string& text); enum Type { DesktopWindow, WithTitleBar, WithoutTitleBar };
explicit Window(Type type, const base::string& text = "");
~Window(); ~Window();
Widget* getKiller(); Widget* getKiller();