mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 19:20:09 +00:00
Refactor: Change jseparator widget to Separator class.
This commit is contained in:
parent
38b5e35351
commit
777e276632
@ -53,8 +53,8 @@ void AboutCommand::onExecute(Context* context)
|
||||
Grid* grid = new Grid(2, false);
|
||||
Label* title = new Label(PACKAGE " v" VERSION);
|
||||
Label* subtitle = new Label("Animated sprite editor && pixel art tool");
|
||||
Widget* authors_separator1 = ji_separator_new("Authors:", JI_HORIZONTAL | JI_TOP);
|
||||
Widget* authors_separator2 = ji_separator_new(NULL, JI_HORIZONTAL);
|
||||
Separator* authors_separator1 = new Separator("Authors:", JI_HORIZONTAL | JI_TOP);
|
||||
Separator* authors_separator2 = new Separator(NULL, JI_HORIZONTAL);
|
||||
Label* author1 = new LinkLabel("http://dacap.com.ar/", "David Capello");
|
||||
Label* author1_desc = new Label("| Programming");
|
||||
Label* author2 = new LinkLabel("http://ilkke.blogspot.com/", "Ilija Melentijevic");
|
||||
|
@ -135,7 +135,7 @@ void Alert::processString(char* buf, std::vector<Widget*>& labels, std::vector<W
|
||||
labels.push_back(label);
|
||||
}
|
||||
else if (separator) {
|
||||
labels.push_back(ji_separator_new(NULL, JI_HORIZONTAL));
|
||||
labels.push_back(new Separator(NULL, JI_HORIZONTAL));
|
||||
}
|
||||
else if (button) {
|
||||
char button_name[256];
|
||||
|
@ -6,59 +6,54 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gui/separator.h"
|
||||
|
||||
#include "gfx/size.h"
|
||||
#include "gui/list.h"
|
||||
#include "gui/message.h"
|
||||
#include "gui/rect.h"
|
||||
#include "gui/preferred_size_event.h"
|
||||
#include "gui/theme.h"
|
||||
#include "gui/widget.h"
|
||||
|
||||
using namespace gfx;
|
||||
|
||||
static bool separator_msg_proc(JWidget widget, Message* msg);
|
||||
|
||||
JWidget ji_separator_new(const char* text, int align)
|
||||
Separator::Separator(const char* text, int align)
|
||||
: Widget(JI_SEPARATOR)
|
||||
{
|
||||
Widget* widget = new Widget(JI_SEPARATOR);
|
||||
|
||||
jwidget_add_hook(widget, JI_SEPARATOR, separator_msg_proc, NULL);
|
||||
widget->setAlign(align);
|
||||
widget->setText(text);
|
||||
widget->initTheme();
|
||||
|
||||
return widget;
|
||||
setAlign(align);
|
||||
setText(text);
|
||||
initTheme();
|
||||
}
|
||||
|
||||
static bool separator_msg_proc(JWidget widget, Message* msg)
|
||||
bool Separator::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_REQSIZE: {
|
||||
Size maxSize(0, 0);
|
||||
Size reqSize;
|
||||
JWidget child;
|
||||
JLink link;
|
||||
|
||||
JI_LIST_FOR_EACH(widget->children, link) {
|
||||
child = (JWidget)link->data;
|
||||
|
||||
reqSize = child->getPreferredSize();
|
||||
maxSize.w = MAX(maxSize.w, reqSize.w);
|
||||
maxSize.h = MAX(maxSize.h, reqSize.h);
|
||||
}
|
||||
|
||||
if (widget->hasText())
|
||||
maxSize.w = MAX(maxSize.w, jwidget_get_text_length(widget));
|
||||
|
||||
msg->reqsize.w = widget->border_width.l + maxSize.w + widget->border_width.r;
|
||||
msg->reqsize.h = widget->border_width.t + maxSize.h + widget->border_width.b;
|
||||
return true;
|
||||
}
|
||||
|
||||
case JM_DRAW:
|
||||
widget->getTheme()->draw_separator(widget, &msg->draw.rect);
|
||||
getTheme()->draw_separator(this, &msg->draw.rect);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Separator::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
Size maxSize(0, 0);
|
||||
JLink link;
|
||||
|
||||
JI_LIST_FOR_EACH(this->children, link) {
|
||||
Widget* child = (Widget*)link->data;
|
||||
|
||||
Size reqSize = child->getPreferredSize();
|
||||
maxSize.w = MAX(maxSize.w, reqSize.w);
|
||||
maxSize.h = MAX(maxSize.h, reqSize.h);
|
||||
}
|
||||
|
||||
if (hasText())
|
||||
maxSize.w = MAX(maxSize.w, jwidget_get_text_length(this));
|
||||
|
||||
int w = this->border_width.l + maxSize.w + this->border_width.r;
|
||||
int h = this->border_width.t + maxSize.h + this->border_width.b;
|
||||
|
||||
ev.setPreferredSize(Size(w, h));
|
||||
}
|
||||
|
@ -7,8 +7,17 @@
|
||||
#ifndef GUI_SEPARATOR_H_INCLUDED
|
||||
#define GUI_SEPARATOR_H_INCLUDED
|
||||
|
||||
#include "gui/base.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "gui/widget.h"
|
||||
|
||||
JWidget ji_separator_new(const char *text, int align);
|
||||
class Separator : public Widget
|
||||
{
|
||||
public:
|
||||
Separator(const char* text, int align);
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -304,7 +304,7 @@ static Widget* convert_xmlelem_to_menuitem(TiXmlElement* elem)
|
||||
{
|
||||
// is it a <separator>?
|
||||
if (strcmp(elem->Value(), "separator") == 0)
|
||||
return ji_separator_new(NULL, JI_HORIZONTAL);
|
||||
return new Separator(NULL, JI_HORIZONTAL);
|
||||
|
||||
const char* command_name = elem->Attribute("command");
|
||||
Command* command =
|
||||
@ -361,7 +361,7 @@ static Widget* create_invalid_version_menuitem()
|
||||
subMenu->addChild(new MenuItem2(PACKAGE " is using a customized gui.xml (maybe from your HOME directory).", NULL, NULL));
|
||||
subMenu->addChild(new MenuItem2("You should update your customized gui.xml file to the new version to get", NULL, NULL));
|
||||
subMenu->addChild(new MenuItem2("the latest commands available.", NULL, NULL));
|
||||
subMenu->addChild(ji_separator_new(NULL, JI_HORIZONTAL));
|
||||
subMenu->addChild(new Separator(NULL, JI_HORIZONTAL));
|
||||
subMenu->addChild(new MenuItem2("You can bypass this validation adding the correct version", NULL, NULL));
|
||||
subMenu->addChild(new MenuItem2("number in <gui version=\"" VERSION "\"> element.", NULL, NULL));
|
||||
menuitem->setSubmenu(subMenu);
|
||||
|
@ -285,13 +285,13 @@ static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root)
|
||||
bool horizontal = bool_attr_is_true(elem, "horizontal");
|
||||
bool vertical = bool_attr_is_true(elem, "vertical");
|
||||
|
||||
widget = ji_separator_new(text ? TRANSLATE_ATTR(text): NULL,
|
||||
(horizontal ? JI_HORIZONTAL: 0) |
|
||||
(vertical ? JI_VERTICAL: 0) |
|
||||
(center ? JI_CENTER:
|
||||
(right ? JI_RIGHT: JI_LEFT)) |
|
||||
(middle ? JI_MIDDLE:
|
||||
(bottom ? JI_BOTTOM: JI_TOP)));
|
||||
widget = new Separator(text ? TRANSLATE_ATTR(text): NULL,
|
||||
(horizontal ? JI_HORIZONTAL: 0) |
|
||||
(vertical ? JI_VERTICAL: 0) |
|
||||
(center ? JI_CENTER:
|
||||
(right ? JI_RIGHT: JI_LEFT)) |
|
||||
(middle ? JI_MIDDLE:
|
||||
(bottom ? JI_BOTTOM: JI_TOP)));
|
||||
}
|
||||
/* slider */
|
||||
else if (ustrcmp(elem_name, "slider") == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user