mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-28 00:35:30 +00:00
Separate Options dialog in different sections
* Add ui::Panel widget
This commit is contained in:
parent
1f5ae8d75b
commit
0c250df97a
@ -1,82 +1,87 @@
|
||||
<!-- Aseprite -->
|
||||
<!-- Copyright (C) 2001-2014 by David Capello -->
|
||||
<gui>
|
||||
<window text="Options" id="options">
|
||||
<box vertical="true">
|
||||
<box horizontal="true">
|
||||
<box vertical="true">
|
||||
<vbox id="main_box">
|
||||
<hbox>
|
||||
<view maxsize="true">
|
||||
<listbox id="section_listbox">
|
||||
<listitem text="General" value="section_general" />
|
||||
<listitem text="Editor" value="section_editor" />
|
||||
<listitem text="Grid && Background" value="section_grid" />
|
||||
<listitem text="Undo" value="section_undo" />
|
||||
</listbox>
|
||||
</view>
|
||||
|
||||
<!-- Screen -->
|
||||
<panel id="panel">
|
||||
<vbox id="section_general">
|
||||
<separator text="General" horizontal="true" />
|
||||
<grid columns="2">
|
||||
<label text="Screen Scale:" />
|
||||
<combobox id="screen_scale" expansive="true" />
|
||||
</grid>
|
||||
</vbox>
|
||||
|
||||
<separator text="Screen:" horizontal="true" />
|
||||
<grid columns="2">
|
||||
<label text="Screen Scale:" />
|
||||
<combobox id="screen_scale" expansive="true" />
|
||||
</grid>
|
||||
<!-- Editor -->
|
||||
<vbox id="section_editor">
|
||||
<separator text="Editor" horizontal="true" />
|
||||
<check text="Smooth auto-scroll" id="smooth" />
|
||||
<check text="Show timeline automatically" id="autotimeline" tooltip="Show the timeline automatically when a new frame or layer is added." />
|
||||
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />
|
||||
<grid columns="2">
|
||||
<label text="Cursor:" />
|
||||
<box id="cursor_color_box" /><!-- custom widget -->
|
||||
</grid>
|
||||
</vbox>
|
||||
|
||||
<!-- Editor -->
|
||||
<!-- Grid & background -->
|
||||
<vbox id="section_grid">
|
||||
<separator text="Grid" horizontal="true" />
|
||||
<grid columns="2">
|
||||
<label text="Grid Color:" />
|
||||
<box id="grid_color_box" /><!-- custom widget -->
|
||||
|
||||
<separator text="Editor:" horizontal="true" />
|
||||
<check text="Smooth auto-scroll" id="smooth" />
|
||||
<check text="Show timeline automatically" id="autotimeline" tooltip="Show the timeline automatically when a new frame or layer is added." />
|
||||
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />
|
||||
<grid columns="2">
|
||||
<label text="Cursor:" />
|
||||
<box id="cursor_color_box" /><!-- custom widget -->
|
||||
<label text="Pixel Grid:" />
|
||||
<box id="pixel_grid_color_box" /><!-- custom widget -->
|
||||
</grid>
|
||||
|
||||
<label text="Grid Color:" />
|
||||
<box id="grid_color_box" /><!-- custom widget -->
|
||||
<separator text="Checked Background" horizontal="true" />
|
||||
<box horizontal="true">
|
||||
<label text="Size:" />
|
||||
<combobox id="checked_bg_size" expansive="true" />
|
||||
</box>
|
||||
<check text="Apply Zoom" id="checked_bg_zoom" />
|
||||
<grid columns="2">
|
||||
<label text="Color 1" />
|
||||
<box horizontal="true" id="checked_bg_color1_box" />
|
||||
<label text="Color 2" />
|
||||
<box horizontal="true" id="checked_bg_color2_box" />
|
||||
</grid>
|
||||
<button id="checked_bg_reset" text="Reset" />
|
||||
</vbox>
|
||||
|
||||
<label text="Pixel Grid:" />
|
||||
<box id="pixel_grid_color_box" /><!-- custom widget -->
|
||||
</grid>
|
||||
|
||||
<!-- Undo -->
|
||||
|
||||
<separator text="Undo:" horizontal="true" />
|
||||
<box horizontal="true">
|
||||
<label text="Undo Limit:" />
|
||||
<entry id="undo_size_limit" maxsize="4" tooltip="Limit of memory to be used for undo information per sprite. Specified in megabytes." />
|
||||
<label text="MB" />
|
||||
</box>
|
||||
|
||||
<box horizontal="true">
|
||||
<check id="undo_goto_modified" text="Go to modified frame/layer" tooltip="When it's enabled each time you undo/redo the current frame & layer will be modified to focus the undid/redid change." />
|
||||
</box>
|
||||
|
||||
</box>
|
||||
<separator vertical="true" />
|
||||
<box vertical="true">
|
||||
|
||||
<!-- Checked Background -->
|
||||
|
||||
<separator text="Checked Background:" horizontal="true" />
|
||||
<box horizontal="true">
|
||||
<label text="Size:" />
|
||||
<combobox id="checked_bg_size" expansive="true" />
|
||||
</box>
|
||||
<check text="Apply Zoom" id="checked_bg_zoom" />
|
||||
<grid columns="2">
|
||||
<label text="Color 1" />
|
||||
<box horizontal="true" id="checked_bg_color1_box" />
|
||||
<label text="Color 2" />
|
||||
<box horizontal="true" id="checked_bg_color2_box" />
|
||||
</grid>
|
||||
<button id="checked_bg_reset" text="Reset" />
|
||||
|
||||
</box>
|
||||
</box>
|
||||
<!-- Undo -->
|
||||
<vbox id="section_undo">
|
||||
<separator text="Undo" horizontal="true" />
|
||||
<box horizontal="true">
|
||||
<label text="Undo Limit:" />
|
||||
<entry id="undo_size_limit" maxsize="4" tooltip="Limit of memory to be used for undo information per sprite. Specified in megabytes." />
|
||||
<label text="MB" />
|
||||
</box>
|
||||
|
||||
<box horizontal="true">
|
||||
<check id="undo_goto_modified" text="Go to modified frame/layer" tooltip="When it's enabled each time you undo/redo the current frame & layer will be modified to focus the undid/redid change." />
|
||||
</box>
|
||||
</vbox>
|
||||
</panel>
|
||||
</hbox>
|
||||
<separator horizontal="true" />
|
||||
|
||||
<box horizontal="true">
|
||||
<hbox>
|
||||
<link id="locate_file" text="Locate File" />
|
||||
<boxfiller />
|
||||
<box horizontal="true" homogeneous="true">
|
||||
<hbox homogeneous="true">
|
||||
<button text="&OK" closewindow="true" id="button_ok" magnet="true" width="60" />
|
||||
<button text="&Cancel" closewindow="true" />
|
||||
</box>
|
||||
</box>
|
||||
</box>
|
||||
</window>
|
||||
</hbox>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</gui>
|
||||
|
@ -42,145 +42,126 @@ namespace app {
|
||||
|
||||
using namespace ui;
|
||||
|
||||
class OptionsCommand : public Command {
|
||||
class OptionsWindow : public Window {
|
||||
public:
|
||||
OptionsCommand();
|
||||
Command* clone() const OVERRIDE { return new OptionsCommand(*this); }
|
||||
OptionsWindow(Context* context)
|
||||
: Window(Window::WithTitleBar, "Options")
|
||||
, m_settings(context->settings())
|
||||
, m_docSettings(m_settings->getDocumentSettings(NULL))
|
||||
, m_checked_bg_color1(new ColorButton(RenderEngine::getCheckedBgColor1(), IMAGE_RGB))
|
||||
, m_checked_bg_color2(new ColorButton(RenderEngine::getCheckedBgColor2(), IMAGE_RGB))
|
||||
, m_pixelGridColor(new ColorButton(m_docSettings->getPixelGridColor(), IMAGE_RGB))
|
||||
, m_gridColor(new ColorButton(m_docSettings->getGridColor(), IMAGE_RGB))
|
||||
, m_cursorColor(new ColorButton(Editor::get_cursor_color(), IMAGE_RGB))
|
||||
{
|
||||
addChild(app::load_widget<Box>("options.xml", "main_box"));
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context);
|
||||
// Load the this widget
|
||||
app::finder(this)
|
||||
>> "section_listbox" >> m_section_listbox
|
||||
>> "panel" >> m_panel
|
||||
>> "smooth" >> m_check_smooth
|
||||
>> "autotimeline" >> m_check_autotimeline
|
||||
>> "show_scrollbars" >> m_show_scrollbars
|
||||
>> "cursor_color_box" >> m_cursor_color_box
|
||||
>> "grid_color_box" >> m_grid_color_box
|
||||
>> "pixel_grid_color_box" >> m_pixel_grid_color_box
|
||||
>> "checked_bg_size" >> m_checked_bg
|
||||
>> "checked_bg_zoom" >> m_checked_bg_zoom
|
||||
>> "checked_bg_color1_box" >> m_checked_bg_color1_box
|
||||
>> "checked_bg_color2_box" >> m_checked_bg_color2_box
|
||||
>> "checked_bg_reset" >> m_checked_bg_reset
|
||||
>> "undo_size_limit" >> m_undo_size_limit
|
||||
>> "undo_goto_modified" >> m_undo_goto_modified
|
||||
>> "screen_scale" >> m_screen_scale
|
||||
>> "locate_file" >> m_locate_file
|
||||
>> "button_ok" >> m_button_ok;
|
||||
|
||||
private:
|
||||
void onResetCheckedBg();
|
||||
void onLocateConfigFile();
|
||||
m_section_listbox->ChangeSelectedItem.connect(Bind<void>(&OptionsWindow::onChangeSection, this));
|
||||
m_cursor_color_box->addChild(m_cursorColor);
|
||||
|
||||
ComboBox* m_checked_bg;
|
||||
Widget* m_checked_bg_zoom;
|
||||
ColorButton* m_checked_bg_color1;
|
||||
ColorButton* m_checked_bg_color2;
|
||||
};
|
||||
// Grid color
|
||||
m_gridColor->setId("grid_color");
|
||||
m_grid_color_box->addChild(m_gridColor);
|
||||
|
||||
OptionsCommand::OptionsCommand()
|
||||
: Command("Options",
|
||||
"Options",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
// Pixel grid color
|
||||
m_pixelGridColor->setId("pixel_grid_color");
|
||||
m_pixel_grid_color_box->addChild(m_pixelGridColor);
|
||||
|
||||
void OptionsCommand::onExecute(Context* context)
|
||||
{
|
||||
// Load the window widget
|
||||
base::UniquePtr<Window> window(app::load_widget<Window>("options.xml", "options"));
|
||||
Widget* check_smooth = app::find_widget<Widget>(window, "smooth");
|
||||
Widget* check_autotimeline = app::find_widget<Widget>(window, "autotimeline");
|
||||
Widget* show_scrollbars = app::find_widget<Widget>(window, "show_scrollbars");
|
||||
Widget* cursor_color_box = app::find_widget<Widget>(window, "cursor_color_box");
|
||||
Widget* grid_color_box = app::find_widget<Widget>(window, "grid_color_box");
|
||||
Widget* pixel_grid_color_box = app::find_widget<Widget>(window, "pixel_grid_color_box");
|
||||
m_checked_bg = app::find_widget<ComboBox>(window, "checked_bg_size");
|
||||
m_checked_bg_zoom = app::find_widget<Widget>(window, "checked_bg_zoom");
|
||||
Widget* checked_bg_color1_box = app::find_widget<Widget>(window, "checked_bg_color1_box");
|
||||
Widget* checked_bg_color2_box = app::find_widget<Widget>(window, "checked_bg_color2_box");
|
||||
Button* checked_bg_reset = app::find_widget<Button>(window, "checked_bg_reset");
|
||||
Widget* undo_size_limit = app::find_widget<Widget>(window, "undo_size_limit");
|
||||
Widget* undo_goto_modified = app::find_widget<Widget>(window, "undo_goto_modified");
|
||||
ComboBox* screen_scale = app::find_widget<ComboBox>(window, "screen_scale");
|
||||
LinkLabel* locate_file = app::find_widget<LinkLabel>(window, "locate_file");
|
||||
Widget* button_ok = app::find_widget<Widget>(window, "button_ok");
|
||||
// Others
|
||||
if (get_config_bool("Options", "MoveSmooth", true))
|
||||
m_check_smooth->setSelected(true);
|
||||
|
||||
// Cursor color
|
||||
ColorButton* cursor_color = new ColorButton(Editor::get_cursor_color(), IMAGE_RGB);
|
||||
cursor_color->setId("cursor_color");
|
||||
cursor_color_box->addChild(cursor_color);
|
||||
if (get_config_bool("Options", "AutoShowTimeline", true))
|
||||
m_check_autotimeline->setSelected(true);
|
||||
|
||||
// Get global settings for documents
|
||||
ISettings* settings = context->settings();
|
||||
IDocumentSettings* docSettings = settings->getDocumentSettings(NULL);
|
||||
if (m_settings->getShowSpriteEditorScrollbars())
|
||||
m_show_scrollbars->setSelected(true);
|
||||
|
||||
// Grid color
|
||||
ColorButton* grid_color = new ColorButton(docSettings->getGridColor(), IMAGE_RGB);
|
||||
grid_color->setId("grid_color");
|
||||
grid_color_box->addChild(grid_color);
|
||||
// Checked background size
|
||||
m_screen_scale->addItem("1:1");
|
||||
m_screen_scale->addItem("2:1");
|
||||
m_screen_scale->addItem("3:1");
|
||||
m_screen_scale->addItem("4:1");
|
||||
m_screen_scale->setSelectedItemIndex(get_screen_scaling()-1);
|
||||
|
||||
// Pixel grid color
|
||||
ColorButton* pixel_grid_color = new ColorButton(docSettings->getPixelGridColor(), IMAGE_RGB);
|
||||
pixel_grid_color->setId("pixel_grid_color");
|
||||
pixel_grid_color_box->addChild(pixel_grid_color);
|
||||
// Checked background size
|
||||
m_checked_bg->addItem("16x16");
|
||||
m_checked_bg->addItem("8x8");
|
||||
m_checked_bg->addItem("4x4");
|
||||
m_checked_bg->addItem("2x2");
|
||||
m_checked_bg->setSelectedItemIndex((int)RenderEngine::getCheckedBgType());
|
||||
|
||||
// Others
|
||||
if (get_config_bool("Options", "MoveSmooth", true))
|
||||
check_smooth->setSelected(true);
|
||||
// Zoom checked background
|
||||
if (RenderEngine::getCheckedBgZoom())
|
||||
m_checked_bg_zoom->setSelected(true);
|
||||
|
||||
if (get_config_bool("Options", "AutoShowTimeline", true))
|
||||
check_autotimeline->setSelected(true);
|
||||
// Checked background colors
|
||||
m_checked_bg_color1_box->addChild(m_checked_bg_color1);
|
||||
m_checked_bg_color2_box->addChild(m_checked_bg_color2);
|
||||
|
||||
if (settings->getShowSpriteEditorScrollbars())
|
||||
show_scrollbars->setSelected(true);
|
||||
// Reset button
|
||||
m_checked_bg_reset->Click.connect(Bind<void>(&OptionsWindow::onResetCheckedBg, this));
|
||||
|
||||
// Checked background size
|
||||
screen_scale->addItem("1:1");
|
||||
screen_scale->addItem("2:1");
|
||||
screen_scale->addItem("3:1");
|
||||
screen_scale->addItem("4:1");
|
||||
screen_scale->setSelectedItemIndex(get_screen_scaling()-1);
|
||||
// Locate config file
|
||||
m_locate_file->Click.connect(Bind<void>(&OptionsWindow::onLocateConfigFile, this));
|
||||
|
||||
// Checked background size
|
||||
m_checked_bg->addItem("16x16");
|
||||
m_checked_bg->addItem("8x8");
|
||||
m_checked_bg->addItem("4x4");
|
||||
m_checked_bg->addItem("2x2");
|
||||
m_checked_bg->setSelectedItemIndex((int)RenderEngine::getCheckedBgType());
|
||||
// Undo limit
|
||||
m_undo_size_limit->setTextf("%d", get_config_int("Options", "UndoSizeLimit", 8));
|
||||
|
||||
// Zoom checked background
|
||||
if (RenderEngine::getCheckedBgZoom())
|
||||
m_checked_bg_zoom->setSelected(true);
|
||||
// Goto modified frame/layer on undo/redo
|
||||
if (get_config_bool("Options", "UndoGotoModified", true))
|
||||
m_undo_goto_modified->setSelected(true);
|
||||
|
||||
// Checked background colors
|
||||
m_checked_bg_color1 = new ColorButton(RenderEngine::getCheckedBgColor1(), IMAGE_RGB);
|
||||
m_checked_bg_color2 = new ColorButton(RenderEngine::getCheckedBgColor2(), IMAGE_RGB);
|
||||
m_section_listbox->selectIndex(0);
|
||||
}
|
||||
|
||||
checked_bg_color1_box->addChild(m_checked_bg_color1);
|
||||
checked_bg_color2_box->addChild(m_checked_bg_color2);
|
||||
bool ok() {
|
||||
return (getKiller() == m_button_ok);
|
||||
}
|
||||
|
||||
// Reset button
|
||||
checked_bg_reset->Click.connect(Bind<void>(&OptionsCommand::onResetCheckedBg, this));
|
||||
void saveConfig() {
|
||||
Editor::set_cursor_color(m_cursorColor->getColor());
|
||||
m_docSettings->setGridColor(m_gridColor->getColor());
|
||||
m_docSettings->setPixelGridColor(m_pixelGridColor->getColor());
|
||||
|
||||
// Locate config file
|
||||
locate_file->Click.connect(Bind<void>(&OptionsCommand::onLocateConfigFile, this));
|
||||
set_config_bool("Options", "MoveSmooth", m_check_smooth->isSelected());
|
||||
set_config_bool("Options", "AutoShowTimeline", m_check_autotimeline->isSelected());
|
||||
|
||||
// Undo limit
|
||||
undo_size_limit->setTextf("%d", get_config_int("Options", "UndoSizeLimit", 8));
|
||||
|
||||
// Goto modified frame/layer on undo/redo
|
||||
if (get_config_bool("Options", "UndoGotoModified", true))
|
||||
undo_goto_modified->setSelected(true);
|
||||
|
||||
// Show the window and wait the user to close it
|
||||
window->openWindowInForeground();
|
||||
|
||||
if (window->getKiller() == button_ok) {
|
||||
int undo_size_limit_value;
|
||||
|
||||
Editor::set_cursor_color(cursor_color->getColor());
|
||||
docSettings->setGridColor(grid_color->getColor());
|
||||
docSettings->setPixelGridColor(pixel_grid_color->getColor());
|
||||
|
||||
set_config_bool("Options", "MoveSmooth", check_smooth->isSelected());
|
||||
set_config_bool("Options", "AutoShowTimeline", check_autotimeline->isSelected());
|
||||
|
||||
settings->setShowSpriteEditorScrollbars(show_scrollbars->isSelected());
|
||||
m_settings->setShowSpriteEditorScrollbars(m_show_scrollbars->isSelected());
|
||||
|
||||
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)m_checked_bg->getSelectedItemIndex());
|
||||
RenderEngine::setCheckedBgZoom(m_checked_bg_zoom->isSelected());
|
||||
RenderEngine::setCheckedBgColor1(m_checked_bg_color1->getColor());
|
||||
RenderEngine::setCheckedBgColor2(m_checked_bg_color2->getColor());
|
||||
|
||||
undo_size_limit_value = undo_size_limit->getTextInt();
|
||||
int undo_size_limit_value;
|
||||
undo_size_limit_value = m_undo_size_limit->getTextInt();
|
||||
undo_size_limit_value = MID(1, undo_size_limit_value, 9999);
|
||||
set_config_int("Options", "UndoSizeLimit", undo_size_limit_value);
|
||||
set_config_bool("Options", "UndoGotoModified", undo_goto_modified->isSelected());
|
||||
set_config_bool("Options", "UndoGotoModified", m_undo_goto_modified->isSelected());
|
||||
|
||||
int new_screen_scaling = screen_scale->getSelectedItemIndex()+1;
|
||||
int new_screen_scaling = m_screen_scale->getSelectedItemIndex()+1;
|
||||
if (new_screen_scaling != get_screen_scaling()) {
|
||||
set_screen_scaling(new_screen_scaling);
|
||||
|
||||
@ -192,20 +173,77 @@ void OptionsCommand::onExecute(Context* context)
|
||||
// Save configuration
|
||||
flush_config_file();
|
||||
}
|
||||
|
||||
private:
|
||||
void onChangeSection() {
|
||||
ListItem* item = m_section_listbox->getSelectedChild();
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
m_panel->showChild(findChild(item->getValue().c_str()));
|
||||
}
|
||||
|
||||
void onResetCheckedBg() {
|
||||
// Default values
|
||||
m_checked_bg->setSelectedItemIndex((int)RenderEngine::CHECKED_BG_16X16);
|
||||
m_checked_bg_zoom->setSelected(true);
|
||||
m_checked_bg_color1->setColor(app::Color::fromRgb(128, 128, 128));
|
||||
m_checked_bg_color2->setColor(app::Color::fromRgb(192, 192, 192));
|
||||
}
|
||||
|
||||
void onLocateConfigFile() {
|
||||
app::launcher::open_folder(app::get_config_file());
|
||||
}
|
||||
|
||||
ISettings* m_settings;
|
||||
IDocumentSettings* m_docSettings;
|
||||
ListBox* m_section_listbox;
|
||||
Panel* m_panel;
|
||||
Widget* m_check_smooth;
|
||||
Widget* m_check_autotimeline;
|
||||
Widget* m_show_scrollbars;
|
||||
Widget* m_cursor_color_box;
|
||||
Widget* m_grid_color_box;
|
||||
Widget* m_pixel_grid_color_box;
|
||||
ComboBox* m_checked_bg;
|
||||
Widget* m_checked_bg_zoom;
|
||||
Widget* m_checked_bg_color1_box;
|
||||
Widget* m_checked_bg_color2_box;
|
||||
Button* m_checked_bg_reset;
|
||||
Widget* m_undo_size_limit;
|
||||
Widget* m_undo_goto_modified;
|
||||
ComboBox* m_screen_scale;
|
||||
LinkLabel* m_locate_file;
|
||||
ColorButton* m_checked_bg_color1;
|
||||
ColorButton* m_checked_bg_color2;
|
||||
ColorButton* m_pixelGridColor;
|
||||
ColorButton* m_gridColor;
|
||||
ColorButton* m_cursorColor;
|
||||
Button* m_button_ok;
|
||||
};
|
||||
|
||||
class OptionsCommand : public Command {
|
||||
public:
|
||||
OptionsCommand();
|
||||
Command* clone() const OVERRIDE { return new OptionsCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onExecute(Context* context);
|
||||
};
|
||||
|
||||
OptionsCommand::OptionsCommand()
|
||||
: Command("Options",
|
||||
"Options",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
void OptionsCommand::onResetCheckedBg()
|
||||
void OptionsCommand::onExecute(Context* context)
|
||||
{
|
||||
// Default values
|
||||
m_checked_bg->setSelectedItemIndex((int)RenderEngine::CHECKED_BG_16X16);
|
||||
m_checked_bg_zoom->setSelected(true);
|
||||
m_checked_bg_color1->setColor(app::Color::fromRgb(128, 128, 128));
|
||||
m_checked_bg_color2->setColor(app::Color::fromRgb(192, 192, 192));
|
||||
}
|
||||
|
||||
void OptionsCommand::onLocateConfigFile()
|
||||
{
|
||||
app::launcher::open_folder(app::get_config_file());
|
||||
OptionsWindow window(context);
|
||||
window.openWindowInForeground();
|
||||
if (window.ok())
|
||||
window.saveConfig();
|
||||
}
|
||||
|
||||
Command* CommandFactory::createOptionsCommand()
|
||||
|
@ -132,6 +132,10 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
||||
if (it != m_typeCreators.end()) {
|
||||
widget = it->second->createWidgetFromXml(elem);
|
||||
}
|
||||
// Oneof
|
||||
else if (elem_name == "panel") {
|
||||
widget = new Panel();
|
||||
}
|
||||
// Boxes
|
||||
else if (elem_name == "box") {
|
||||
bool horizontal = bool_attr_is_true(elem, "horizontal");
|
||||
@ -301,9 +305,14 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
||||
}
|
||||
/* listitem */
|
||||
else if (elem_name == "listitem") {
|
||||
const char *text = elem->Attribute("text");
|
||||
const char* text = elem->Attribute("text");
|
||||
const char* value = elem->Attribute("value");
|
||||
|
||||
widget = new ListItem(text ? TRANSLATE_ATTR(text): "");
|
||||
ListItem* listitem = new ListItem(text ? TRANSLATE_ATTR(text): "");
|
||||
if (value) {
|
||||
listitem->setValue(value);
|
||||
}
|
||||
widget = listitem;
|
||||
}
|
||||
/* splitter */
|
||||
else if (elem_name == "splitter") {
|
||||
|
@ -32,6 +32,7 @@ add_library(ui-lib
|
||||
overlay.cpp
|
||||
overlay_manager.cpp
|
||||
paint_event.cpp
|
||||
panel.cpp
|
||||
popup_window.cpp
|
||||
preferred_size_event.cpp
|
||||
property.cpp
|
||||
|
@ -18,10 +18,19 @@ namespace ui {
|
||||
public:
|
||||
ListItem(const std::string& text);
|
||||
|
||||
const std::string& getValue() { return m_value; }
|
||||
|
||||
void setValue(const std::string& value) {
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
protected:
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
std::string m_value;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
71
src/ui/panel.cpp
Normal file
71
src/ui/panel.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "ui/panel.h"
|
||||
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
Panel::Panel()
|
||||
: Widget(kPanelWidget)
|
||||
{
|
||||
}
|
||||
|
||||
void Panel::showChild(Widget* widget)
|
||||
{
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
if (!child->isDecorative())
|
||||
child->setVisible(child == widget);
|
||||
}
|
||||
layout();
|
||||
}
|
||||
|
||||
void Panel::onResize(ResizeEvent& ev)
|
||||
{
|
||||
// Copy the new position rectangle
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
// Set all the children to the same "cpos"
|
||||
gfx::Rect cpos = getChildrenBounds();
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
if (!child->isDecorative())
|
||||
child->setBounds(cpos);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
gfx::Size maxSize(0, 0);
|
||||
gfx::Size reqSize;
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
|
||||
if (!child->isDecorative()) {
|
||||
reqSize = child->getPreferredSize();
|
||||
|
||||
maxSize.w = MAX(maxSize.w, reqSize.w);
|
||||
maxSize.h = MAX(maxSize.h, reqSize.h);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasText())
|
||||
maxSize.w = MAX(maxSize.w, getTextWidth());
|
||||
|
||||
ev.setPreferredSize(
|
||||
this->border_width.l + maxSize.w + this->border_width.r,
|
||||
this->border_width.t + maxSize.h + this->border_width.b);
|
||||
}
|
||||
|
||||
} // namespace ui
|
29
src/ui/panel.h
Normal file
29
src/ui/panel.h
Normal file
@ -0,0 +1,29 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2014 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UI_PANEL_H_INCLUDED
|
||||
#define UI_PANEL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Panel : public Widget {
|
||||
public:
|
||||
Panel();
|
||||
|
||||
void showChild(Widget* widget);
|
||||
|
||||
protected:
|
||||
virtual void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
virtual void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
@ -44,6 +44,7 @@
|
||||
#include "ui/overlay.h"
|
||||
#include "ui/overlay_manager.h"
|
||||
#include "ui/paint_event.h"
|
||||
#include "ui/panel.h"
|
||||
#include "ui/popup_window.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/property.h"
|
||||
|
@ -27,18 +27,19 @@ namespace ui {
|
||||
kListBoxWidget,
|
||||
kListItemWidget,
|
||||
kManagerWidget,
|
||||
kMenuWidget,
|
||||
kMenuBarWidget,
|
||||
kMenuBoxWidget,
|
||||
kMenuItemWidget,
|
||||
kSplitterWidget,
|
||||
kMenuWidget,
|
||||
kPanelWidget,
|
||||
kRadioWidget,
|
||||
kSeparatorWidget,
|
||||
kSliderWidget,
|
||||
kSplitterWidget,
|
||||
kTextBoxWidget,
|
||||
kViewWidget,
|
||||
kViewScrollbarWidget,
|
||||
kViewViewportWidget,
|
||||
kViewWidget,
|
||||
kWindowWidget,
|
||||
|
||||
// User widgets.
|
||||
|
@ -4,8 +4,6 @@
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#define REDRAW_MOVEMENT
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user