Convert jbox widget to Box class.

This commit is contained in:
David Capello 2011-01-24 19:48:09 -03:00
parent e32d8dc633
commit d8a3d27c0f
22 changed files with 125 additions and 118 deletions

View File

@ -49,7 +49,7 @@ AboutCommand::AboutCommand()
void AboutCommand::onExecute(Context* context)
{
FramePtr frame(new Frame(false, "About " PACKAGE));
Widget* box1 = jbox_new(JI_VERTICAL);
Box* box1 = new Box(JI_VERTICAL);
Widget* grid = jgrid_new(2, false);
Label* title = new Label(PACKAGE " v" VERSION);
Label* subtitle = new Label("Animated sprites editor && pixel art tool");
@ -61,9 +61,9 @@ void AboutCommand::onExecute(Context* context)
Label* author2_desc = new Label("| Skin and Graphics");
Label* author3 = new Label("Trent Gamblin");
Label* author3_desc = new Label("| MAC OS X builds");
Widget* bottom_box1 = jbox_new(JI_HORIZONTAL);
Widget* bottom_box2 = jbox_new(JI_HORIZONTAL);
Widget* bottom_box3 = jbox_new(JI_HORIZONTAL);
Box* bottom_box1 = new Box(JI_HORIZONTAL);
Box* bottom_box2 = new Box(JI_HORIZONTAL);
Box* bottom_box3 = new Box(JI_HORIZONTAL);
Label* copyright = new Label(COPYRIGHT);
Label* website = new LinkLabel(WEBSITE);
Button* close_button = new Button("&Close");

View File

@ -64,9 +64,9 @@ void LayerPropertiesCommand::onExecute(Context* context)
Layer* layer = sprite->getCurrentLayer();
FramePtr window(new Frame(false, "Layer Properties"));
Widget* box1 = jbox_new(JI_VERTICAL);
Widget* box2 = jbox_new(JI_HORIZONTAL);
Widget* box3 = jbox_new(JI_HORIZONTAL + JI_HOMOGENEOUS);
Box* box1 = new Box(JI_VERTICAL);
Box* box2 = new Box(JI_HORIZONTAL);
Box* box3 = new Box(JI_HORIZONTAL + JI_HOMOGENEOUS);
Widget* label_name = new Label("Name:");
Entry* entry_name = new Entry(256, layer->getName().c_str());
Button* button_ok = new Button("&OK");

View File

@ -23,7 +23,6 @@
#include "base/bind.h"
#include "gui/button.h"
#include "gui/frame.h"
#include "gui/jbox.h"
#include "gui/jhook.h"
#include "gui/jlist.h"
#include "gui/jlistbox.h"

View File

@ -24,7 +24,6 @@
#include "gui/button.h"
#include "gui/entry.h"
#include "gui/frame.h"
#include "gui/jbox.h"
#include "gui/jhook.h"
#include "gui/widget.h"

View File

@ -19,13 +19,12 @@
#include "config.h"
#include "base/bind.h"
#include "gui/jbox.h"
#include "gui/button.h"
#include "gui/frame.h"
#include "gui/jhook.h"
#include "gui/label.h"
#include "gui/slider.h"
#include "gui/widget.h"
#include "gui/frame.h"
#include "app/color.h"
#include "commands/command.h"

View File

@ -23,9 +23,9 @@
#include "app/color_utils.h"
#include "base/bind.h"
#include "core/cfg.h"
#include "gui/box.h"
#include "gui/button.h"
#include "gui/frame.h"
#include "gui/jbox.h"
#include "gui/jhook.h"
#include "gui/label.h"
#include "gui/slider.h"
@ -53,7 +53,7 @@ static void mask_preview(Sprite* sprite);
void dialogs_mask_color(Sprite* sprite)
{
JWidget box1, box2, box3, box4;
Box* box1, *box2, *box3, *box4;
Widget* label_color;
Button* button_1;
Button* button_2;
@ -70,10 +70,10 @@ void dialogs_mask_color(Sprite* sprite)
return;
FramePtr window(new Frame(false, "Mask by Color"));
box1 = jbox_new(JI_VERTICAL);
box2 = jbox_new(JI_HORIZONTAL);
box3 = jbox_new(JI_HORIZONTAL);
box4 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
box1 = new Box(JI_VERTICAL);
box2 = new Box(JI_HORIZONTAL);
box3 = new Box(JI_HORIZONTAL);
box4 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
label_color = new Label("Color:");
button_color = new ColorButton
(get_config_color("MaskColor", "Color",

View File

@ -41,8 +41,8 @@ static void delete_command(Button* widget, RepoDlg* repo_dlg);
void ji_show_repo_dlg(RepoDlg *repo_dlg)
{
Frame* window = new Frame(false, repo_dlg->title);
Widget* box1 = jbox_new(JI_HORIZONTAL);
Widget* box2 = jbox_new(JI_VERTICAL);
Box* box1 = new Box(JI_HORIZONTAL);
Box* box2 = new Box(JI_VERTICAL);
Widget* view = jview_new();
repo_dlg->listbox = jlistbox_new();
repo_dlg->button_use = new Button(repo_dlg->use_text);

View File

@ -2,6 +2,7 @@
# Copyright (C) 2001-2011 David Capello
add_library(gui-lib
box.cpp
button.cpp
component.cpp
entry.cpp
@ -9,7 +10,6 @@ add_library(gui-lib
frame.cpp
jaccel.cpp
jalert.cpp
jbox.cpp
jclipboard.cpp
jcombobox.cpp
jcustom_label.cpp

View File

@ -9,11 +9,12 @@
#include "config.h"
#include "gfx/size.h"
#include "gui/box.h"
#include "gui/jlist.h"
#include "gui/jmessage.h"
#include "gui/jrect.h"
#include "gui/preferred_size_event.h"
#include "gui/theme.h"
#include "gui/widget.h"
using namespace gfx;
@ -21,72 +22,64 @@ static bool box_msg_proc(JWidget widget, JMessage msg);
static void box_request_size(JWidget widget, int *w, int *h);
static void box_set_position(JWidget widget, JRect rect);
JWidget jbox_new(int align)
Box::Box(int align)
: Widget(JI_BOX)
{
Widget* widget = new Widget(JI_BOX);
jwidget_add_hook(widget, JI_BOX, box_msg_proc, NULL);
widget->setAlign(align);
jwidget_init_theme(widget);
return widget;
setAlign(align);
jwidget_init_theme(this);
}
static bool box_msg_proc(JWidget widget, JMessage msg)
bool Box::onProcessMessage(JMessage msg)
{
switch (msg->type) {
case JM_REQSIZE:
box_request_size(widget, &msg->reqsize.w, &msg->reqsize.h);
return true;
case JM_SETPOS:
box_set_position(widget, &msg->setpos.rect);
box_set_position(&msg->setpos.rect);
return true;
case JM_DRAW:
widget->getTheme()->draw_box(widget, &msg->draw.rect);
getTheme()->draw_box(this, &msg->draw.rect);
return true;
}
return false;
return Widget::onProcessMessage(msg);
}
static void box_request_size(JWidget widget, int *w, int *h)
void Box::onPreferredSize(PreferredSizeEvent& ev)
{
#define GET_CHILD_SIZE(w, h) \
{ \
if (widget->getAlign() & JI_HOMOGENEOUS) \
*w = MAX(*w, reqSize.w); \
if (getAlign() & JI_HOMOGENEOUS) \
w = MAX(w, reqSize.w); \
else \
*w += reqSize.w; \
w += reqSize.w; \
\
*h = MAX(*h, reqSize.h); \
h = MAX(h, reqSize.h); \
}
#define FINAL_SIZE(w) \
{ \
if (widget->getAlign() & JI_HOMOGENEOUS) \
*w *= nvis_children; \
if (getAlign() & JI_HOMOGENEOUS) \
w *= nvis_children; \
\
*w += widget->child_spacing * (nvis_children-1); \
w += child_spacing * (nvis_children-1); \
}
int nvis_children;
int w, h, nvis_children;
JWidget child;
JLink link;
nvis_children = 0;
JI_LIST_FOR_EACH(widget->children, link) {
JI_LIST_FOR_EACH(this->children, link) {
child = (JWidget)link->data;
if (!(child->flags & JI_HIDDEN))
nvis_children++;
}
w = h = 0;
*w = *h = 0;
JI_LIST_FOR_EACH(widget->children, link) {
JI_LIST_FOR_EACH(this->children, link) {
child = (JWidget)link->data;
if (child->flags & JI_HIDDEN)
@ -94,7 +87,7 @@ static void box_request_size(JWidget widget, int *w, int *h)
Size reqSize = child->getPreferredSize();
if (widget->getAlign() & JI_HORIZONTAL) {
if (this->getAlign() & JI_HORIZONTAL) {
GET_CHILD_SIZE(w, h);
}
else {
@ -103,7 +96,7 @@ static void box_request_size(JWidget widget, int *w, int *h)
}
if (nvis_children > 0) {
if (widget->getAlign() & JI_HORIZONTAL) {
if (this->getAlign() & JI_HORIZONTAL) {
FINAL_SIZE(w);
}
else {
@ -111,24 +104,26 @@ static void box_request_size(JWidget widget, int *w, int *h)
}
}
*w += widget->border_width.l + widget->border_width.r;
*h += widget->border_width.t + widget->border_width.b;
w += border_width.l + border_width.r;
h += border_width.t + border_width.b;
ev.setPreferredSize(Size(w, h));
}
static void box_set_position(JWidget widget, JRect rect)
void Box::box_set_position(JRect rect)
{
#define FIXUP(x, y, w, h, l, t, r, b) \
{ \
if (nvis_children > 0) { \
if (widget->getAlign() & JI_HOMOGENEOUS) { \
width = (jrect_##w(widget->rc) \
- widget->border_width.l \
- widget->border_width.r \
- widget->child_spacing * (nvis_children - 1)); \
if (getAlign() & JI_HOMOGENEOUS) { \
width = (jrect_##w(this->rc) \
- this->border_width.l \
- this->border_width.r \
- this->child_spacing * (nvis_children - 1)); \
extra = width / nvis_children; \
} \
else if (nexpand_children > 0) { \
width = jrect_##w(widget->rc) - reqSize.w; \
width = jrect_##w(this->rc) - reqSize.w; \
extra = width / nexpand_children; \
} \
else { \
@ -136,17 +131,17 @@ static void box_set_position(JWidget widget, JRect rect)
extra = 0; \
} \
\
x = widget->rc->x##1 + widget->border_width.l; \
y = widget->rc->y##1 + widget->border_width.t; \
h = MAX(1, jrect_##h(widget->rc) \
- widget->border_width.t \
- widget->border_width.b); \
\
JI_LIST_FOR_EACH(widget->children, link) { \
x = this->rc->x##1 + this->border_width.l; \
y = this->rc->y##1 + this->border_width.t; \
h = MAX(1, jrect_##h(this->rc) \
- this->border_width.t \
- this->border_width.b); \
\
JI_LIST_FOR_EACH(this->children, link) { \
child = (JWidget)link->data; \
\
if (!(child->flags & JI_HIDDEN)) { \
if (widget->getAlign() & JI_HOMOGENEOUS) { \
if (this->getAlign() & JI_HOMOGENEOUS) { \
if (nvis_children == 1) \
child_width = width; \
else \
@ -173,21 +168,21 @@ static void box_set_position(JWidget widget, JRect rect)
\
w = MAX(1, child_width); \
\
if (widget->getAlign() & JI_HORIZONTAL) \
if (this->getAlign() & JI_HORIZONTAL) \
jrect_replace(&cpos, x, y, x+w, y+h); \
else \
jrect_replace(&cpos, y, x, y+h, x+w); \
\
jwidget_set_rect(child, &cpos); \
\
x += child_width + widget->child_spacing; \
x += child_width + this->child_spacing; \
} \
} \
} \
}
struct jrect cpos;
JWidget child;
Widget* child;
int nvis_children = 0;
int nexpand_children = 0;
int child_width;
@ -196,9 +191,9 @@ static void box_set_position(JWidget widget, JRect rect)
int extra;
int x, y, w, h;
jrect_copy(widget->rc, rect);
jrect_copy(this->rc, rect);
JI_LIST_FOR_EACH(widget->children, link) {
JI_LIST_FOR_EACH(this->children, link) {
child = (JWidget)link->data;
if (!(child->flags & JI_HIDDEN)) {
@ -208,9 +203,9 @@ static void box_set_position(JWidget widget, JRect rect)
}
}
Size reqSize = widget->getPreferredSize();
Size reqSize = this->getPreferredSize();
if (widget->getAlign() & JI_HORIZONTAL) {
if (this->getAlign() & JI_HORIZONTAL) {
FIXUP(x, y, w, h, l, t, r, b);
}
else {

26
src/gui/box.h Normal file
View File

@ -0,0 +1,26 @@
// ASE gui library
// Copyright (C) 2001-2011 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef GUI_BOX_H_INCLUDED
#define GUI_BOX_H_INCLUDED
#include "gui/widget.h"
class Box : public Widget
{
public:
Box(int align);
protected:
// Events
bool onProcessMessage(JMessage msg);
void onPreferredSize(PreferredSizeEvent& ev);
private:
void box_set_position(JRect rect);
};
#endif

View File

@ -120,7 +120,8 @@ int jalert(const char *format, ...)
static Frame* create_alert(char *buf, JList *labels, JList *buttons)
{
JWidget box1, box2, grid, box3, box4, box5;
Box* box1, *box2, *box3, *box4, *box5;
Widget* grid;
Frame* window = NULL;
bool title = true;
bool label = false;
@ -193,18 +194,18 @@ static Frame* create_alert(char *buf, JList *labels, JList *buttons)
}
if (window) {
box1 = jbox_new(JI_VERTICAL);
box2 = jbox_new(JI_VERTICAL);
box1 = new Box(JI_VERTICAL);
box2 = new Box(JI_VERTICAL);
grid = jgrid_new(1, false);
box3 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
box3 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
/* to identify by the user */
box2->setName("labels");
box3->setName("buttons");
/* pseudo separators (only to fill blank space) */
box4 = jbox_new(0);
box5 = jbox_new(0);
box4 = new Box(0);
box5 = new Box(0);
jwidget_expansive(box4, true);
jwidget_expansive(box5, true);

View File

@ -1,14 +0,0 @@
// ASE gui library
// Copyright (C) 2001-2011 David Capello
//
// This source file is ditributed under a BSD-like license, please
// read LICENSE.txt for more information.
#ifndef GUI_JBOX_H_INCLUDED
#define GUI_JBOX_H_INCLUDED
#include "gui/jbase.h"
JWidget jbox_new(int align);
#endif

View File

@ -7,13 +7,13 @@
#ifndef GUI_JINETE_H_INCLUDED
#define GUI_JINETE_H_INCLUDED
#include "gui/box.h"
#include "gui/button.h"
#include "gui/entry.h"
#include "gui/frame.h"
#include "gui/jaccel.h"
#include "gui/jalert.h"
#include "gui/jbase.h"
#include "gui/jbox.h"
#include "gui/jclipboard.h"
#include "gui/jcombobox.h"
#include "gui/jcustom_label.h"

View File

@ -12,6 +12,7 @@
struct BITMAP;
struct FONT;
class Box;
class ButtonBase;
class Entry;
class Slider;
@ -46,7 +47,7 @@ public:
virtual int color_selected() = 0;
virtual int color_background() = 0;
virtual void draw_box(JWidget widget, JRect clip) = 0;
virtual void draw_box(Box* widget, JRect clip) = 0;
virtual void draw_button(ButtonBase* widget, JRect clip) = 0;
virtual void draw_check(ButtonBase* widget, JRect clip) = 0;
virtual void draw_entry(Entry* widget, JRect clip) = 0;

View File

@ -611,7 +611,7 @@ int SkinTheme::color_background()
return COLOR_BACKGROUND;
}
void SkinTheme::draw_box(JWidget widget, JRect clip)
void SkinTheme::draw_box(Box* widget, JRect clip)
{
jdraw_rectfill(clip, BGCOLOR);
}

View File

@ -420,7 +420,7 @@ public:
int color_selected();
int color_background();
void draw_box(JWidget widget, JRect clip);
void draw_box(Box* widget, JRect clip);
void draw_button(ButtonBase* widget, JRect clip);
void draw_check(ButtonBase* widget, JRect clip);
void draw_entry(Entry* widget, JRect clip);

View File

@ -86,7 +86,7 @@ Frame* colorselector_new()
Frame* window = new PopupFrame(NULL, false);
Widget* grid1 = jgrid_new(2, false);
Widget* grid2 = jgrid_new(5, false);
Widget* models_box = jbox_new(JI_HORIZONTAL);
Box* models_box = new Box(JI_HORIZONTAL);
PalEdit* pal = new PalEdit(false);
Label* idx = new Label("None");
Widget* child;

View File

@ -22,8 +22,8 @@
#include <stdarg.h>
#include "base/bind.h"
#include "gui/box.h"
#include "gui/button.h"
#include "gui/jbox.h"
#include "gui/jhook.h"
#include "gui/jlist.h"
#include "gui/jsystem.h"
@ -39,8 +39,8 @@ static bool radio_change_hook(JWidget vbox);
JWidget group_button_new(int w, int h, int first_selected, ...)
{
JWidget vbox = jbox_new(JI_VERTICAL | JI_HOMOGENEOUS);
JWidget hbox = NULL;
Box* vbox = new Box(JI_VERTICAL | JI_HOMOGENEOUS);
Box* hbox = NULL;
RadioButton* radio;
int x, y, icon;
va_list ap;
@ -53,7 +53,7 @@ JWidget group_button_new(int w, int h, int first_selected, ...)
for (y=0; y<h; y++) {
if (w > 1) {
hbox = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
hbox = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
jwidget_noborders(hbox);
}

View File

@ -104,9 +104,9 @@ StatusBar::StatusBar()
// Construct the commands box
{
Widget* box1 = jbox_new(JI_HORIZONTAL);
Widget* box2 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
Widget* box3 = jbox_new(JI_HORIZONTAL);
Box* box1 = new Box(JI_HORIZONTAL);
Box* box2 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
Box* box3 = new Box(JI_HORIZONTAL);
m_slider = new Slider(0, 255, 255);
setup_mini_look(m_slider);
@ -140,10 +140,10 @@ StatusBar::StatusBar()
// Construct move-pixels box
{
Widget* filler = jbox_new(JI_HORIZONTAL);
Box* filler = new Box(JI_HORIZONTAL);
jwidget_expansive(filler, true);
m_movePixelsBox = jbox_new(JI_HORIZONTAL);
m_movePixelsBox = new Box(JI_HORIZONTAL);
m_transparentLabel = new Label("Transparent Color:");
m_transparentColor = new ColorButton(Color::fromMask(), IMAGE_RGB);

View File

@ -23,6 +23,7 @@
#include "gui/jbase.h"
#include "gui/widget.h"
class Box;
class Button;
class ColorButton;
class Frame;
@ -100,7 +101,7 @@ private:
Button* m_b_last; // Go to last frame
// Box with move-pixels commands (when the user drag-and-drop selected pixels using the editor)
Widget* m_movePixelsBox;
Box* m_movePixelsBox;
Widget* m_transparentLabel;
ColorButton* m_transparentColor;

View File

@ -24,8 +24,8 @@
#include "base/bind.h"
#include "core/cfg.h"
#include "effect/effect.h"
#include "gui/box.h"
#include "gui/button.h"
#include "gui/jbox.h"
#include "gui/jhook.h"
#include "gui/theme.h"
#include "gui/widget.h"
@ -54,7 +54,7 @@ JWidget target_button_new(int imgtype, bool with_channels)
}
int default_targets = 0;
JWidget vbox, hbox;
Box* vbox, *hbox;
CheckBox* r = NULL;
CheckBox* g = NULL;
CheckBox* b = NULL;
@ -63,8 +63,8 @@ JWidget target_button_new(int imgtype, bool with_channels)
CheckBox* index = NULL;
Button* images = NULL;
vbox = jbox_new(JI_VERTICAL);
hbox = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
vbox = new Box(JI_VERTICAL);
hbox = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
jwidget_noborders(vbox);
jwidget_noborders(hbox);

View File

@ -93,9 +93,9 @@ static Widget* convert_xmlelement_to_widget(TiXmlElement* elem, Widget* root)
bool vertical = bool_attr_is_true(elem, "vertical");
bool homogeneous = bool_attr_is_true(elem, "homogeneous");
widget = jbox_new((horizontal ? JI_HORIZONTAL:
vertical ? JI_VERTICAL: 0) |
(homogeneous ? JI_HOMOGENEOUS: 0));
widget = new Box((horizontal ? JI_HORIZONTAL:
vertical ? JI_VERTICAL: 0) |
(homogeneous ? JI_HOMOGENEOUS: 0));
}
/* button */
else if (ustrcmp(elem_name, "button") == 0) {