mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-17 08:43:11 +00:00
Replace kResizeMessage message with ResizeEvent and Widget::onResize()
- Remove jwidget_set_rect() function.
This commit is contained in:
parent
3dbf6518f9
commit
01dfe4d52e
@ -117,9 +117,7 @@ protected:
|
||||
m_columns.setVisible(state);
|
||||
|
||||
gfx::Size reqSize = getPreferredSize();
|
||||
JRect rect = jrect_new(rc->x1, rc->y1, rc->x1+reqSize.w, rc->y1+reqSize.h);
|
||||
moveWindow(rect);
|
||||
jrect_free(rect);
|
||||
moveWindow(gfx::Rect(rc->x1, rc->y1, reqSize.w, reqSize.h));
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
@ -496,12 +496,8 @@ void PaletteEntryEditor::onMoreOptionsClick(Event& ev)
|
||||
reqSize.h += 4;
|
||||
|
||||
// Remove the space occupied by the "More options" panel
|
||||
{
|
||||
JRect rect = jrect_new(rc->x1, rc->y1,
|
||||
rc->x2, rc->y2 - reqSize.h);
|
||||
moveWindow(rect);
|
||||
jrect_free(rect);
|
||||
}
|
||||
moveWindow(gfx::Rect(rc->x1, rc->y1,
|
||||
jrect_w(rc), jrect_h(rc) - reqSize.h));
|
||||
}
|
||||
else {
|
||||
set_config_bool("PaletteEditor", "ShowMoreOptions", true);
|
||||
@ -512,15 +508,14 @@ void PaletteEntryEditor::onMoreOptionsClick(Event& ev)
|
||||
|
||||
// Add space for the "more_options" panel
|
||||
if (jrect_h(rc) < reqSize.h) {
|
||||
JRect rect = jrect_new(rc->x1, rc->y1,
|
||||
rc->x2, rc->y1 + reqSize.h);
|
||||
gfx::Rect rect(rc->x1, rc->y1,
|
||||
jrect_w(rc), reqSize.h);
|
||||
|
||||
// Show the expanded area inside the screen
|
||||
if (rect->y2 > JI_SCREEN_H)
|
||||
jrect_displace(rect, 0, JI_SCREEN_H - rect->y2);
|
||||
if (rect.y2() > JI_SCREEN_H)
|
||||
rect.offset(0, JI_SCREEN_H - rect.y2());
|
||||
|
||||
moveWindow(rect);
|
||||
jrect_free(rect);
|
||||
}
|
||||
else
|
||||
setBounds(getBounds()); // TODO layout() method is missing
|
||||
|
@ -126,17 +126,14 @@ void Console::printf(const char *format, ...)
|
||||
|
||||
/* update the textbox */
|
||||
if (!console_locked) {
|
||||
JRect rect = jrect_new(0, 0, JI_SCREEN_W*9/10, JI_SCREEN_H*6/10);
|
||||
console_locked = true;
|
||||
|
||||
wid_view->setVisible(true);
|
||||
|
||||
wid_console->remapWindow();
|
||||
jwidget_set_rect(wid_console, rect);
|
||||
wid_console->setBounds(gfx::Rect(0, 0, JI_SCREEN_W*9/10, JI_SCREEN_H*6/10));
|
||||
wid_console->centerWindow();
|
||||
wid_console->invalidate();
|
||||
|
||||
jrect_free(rect);
|
||||
}
|
||||
|
||||
text = wid_textbox->getText();
|
||||
|
@ -804,17 +804,15 @@ void SkinTheme::setDecorativeWidgetBounds(Widget* widget)
|
||||
{
|
||||
if (widget->getId() == kThemeCloseButtonId) {
|
||||
Widget* window = widget->getParent();
|
||||
JRect rect = jrect_new(0, 0, 0, 0);
|
||||
gfx::Rect rect(0, 0, 0, 0);
|
||||
|
||||
rect->x2 = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->w;
|
||||
rect->y2 = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->h;
|
||||
rect.w = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->w;
|
||||
rect.h = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->h;
|
||||
|
||||
jrect_displace(rect,
|
||||
window->rc->x2 - 3*jguiscale() - jrect_w(rect),
|
||||
window->rc->y1 + 3*jguiscale());
|
||||
rect.offset(window->rc->x2 - 3*jguiscale() - rect.w,
|
||||
window->rc->y1 + 3*jguiscale());
|
||||
|
||||
jwidget_set_rect(widget, rect);
|
||||
jrect_free(rect);
|
||||
widget->setBounds(rect);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ add_library(ui-lib
|
||||
property.cpp
|
||||
rect.cpp
|
||||
register_message.cpp
|
||||
resize_event.cpp
|
||||
scroll_bar.cpp
|
||||
separator.cpp
|
||||
slider.cpp
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
using namespace gfx;
|
||||
@ -26,19 +27,6 @@ Box::Box(int align)
|
||||
initTheme();
|
||||
}
|
||||
|
||||
bool Box::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
layoutBox(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Box::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
#define GET_CHILD_SIZE(w, h) \
|
||||
@ -101,12 +89,7 @@ void Box::onPreferredSize(PreferredSizeEvent& ev)
|
||||
ev.setPreferredSize(Size(w, h));
|
||||
}
|
||||
|
||||
void Box::onPaint(PaintEvent& ev)
|
||||
{
|
||||
getTheme()->paintBox(ev);
|
||||
}
|
||||
|
||||
void Box::layoutBox(JRect rect)
|
||||
void Box::onResize(ResizeEvent& ev)
|
||||
{
|
||||
#define FIXUP(x, y, w, h, l, t, r, b) \
|
||||
{ \
|
||||
@ -164,12 +147,13 @@ void Box::layoutBox(JRect rect)
|
||||
\
|
||||
w = MAX(1, child_width); \
|
||||
\
|
||||
if (this->getAlign() & JI_HORIZONTAL) \
|
||||
jrect_replace(&cpos, x, y, x+w, y+h); \
|
||||
gfx::Rect cpos; \
|
||||
if (getAlign() & JI_HORIZONTAL) \
|
||||
cpos = gfx::Rect(x, y, w, h); \
|
||||
else \
|
||||
jrect_replace(&cpos, y, x, y+h, x+w); \
|
||||
cpos = gfx::Rect(y, x, h, w); \
|
||||
\
|
||||
jwidget_set_rect(child, &cpos); \
|
||||
child->setBounds(cpos); \
|
||||
\
|
||||
x += child_width + this->child_spacing; \
|
||||
} \
|
||||
@ -177,7 +161,6 @@ void Box::layoutBox(JRect rect)
|
||||
} \
|
||||
}
|
||||
|
||||
struct jrect cpos;
|
||||
Widget* child;
|
||||
int nvis_children = 0;
|
||||
int nexpand_children = 0;
|
||||
@ -185,8 +168,8 @@ void Box::layoutBox(JRect rect)
|
||||
int width;
|
||||
int extra;
|
||||
int x, y, w, h;
|
||||
|
||||
jrect_copy(this->rc, rect);
|
||||
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
child = *it;
|
||||
@ -198,7 +181,7 @@ void Box::layoutBox(JRect rect)
|
||||
}
|
||||
}
|
||||
|
||||
Size reqSize = this->getPreferredSize();
|
||||
Size reqSize = getPreferredSize();
|
||||
|
||||
if (this->getAlign() & JI_HORIZONTAL) {
|
||||
FIXUP(x, y, w, h, l, t, r, b);
|
||||
@ -208,4 +191,9 @@ void Box::layoutBox(JRect rect)
|
||||
}
|
||||
}
|
||||
|
||||
void Box::onPaint(PaintEvent& ev)
|
||||
{
|
||||
getTheme()->paintBox(ev);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -19,12 +19,9 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
// Events
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
void layoutBox(JRect rect);
|
||||
};
|
||||
|
||||
class VBox : public Box
|
||||
|
@ -312,30 +312,9 @@ bool ComboBox::onProcessMessage(Message* msg)
|
||||
closeListBox();
|
||||
break;
|
||||
|
||||
case kResizeMessage: {
|
||||
JRect cbox = jrect_new_copy(&msg->setpos.rect);
|
||||
jrect_copy(this->rc, cbox);
|
||||
|
||||
// Button
|
||||
Size buttonSize = m_button->getPreferredSize();
|
||||
cbox->x1 = msg->setpos.rect.x2 - buttonSize.w;
|
||||
jwidget_set_rect(m_button, cbox);
|
||||
|
||||
// Entry
|
||||
cbox->x2 = cbox->x1;
|
||||
cbox->x1 = msg->setpos.rect.x1;
|
||||
jwidget_set_rect(m_entry, cbox);
|
||||
|
||||
jrect_free(cbox);
|
||||
return true;
|
||||
}
|
||||
|
||||
case kWinMoveMessage:
|
||||
if (m_window) {
|
||||
JRect rc = getListBoxPos();
|
||||
m_window->moveWindow(rc);
|
||||
jrect_free(rc);
|
||||
}
|
||||
if (m_window)
|
||||
m_window->moveWindow(getListBoxPos());
|
||||
break;
|
||||
|
||||
case kMouseDownMessage:
|
||||
@ -352,6 +331,21 @@ bool ComboBox::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void ComboBox::onResize(ResizeEvent& ev)
|
||||
{
|
||||
gfx::Rect bounds = ev.getBounds();
|
||||
setBoundsQuietly(bounds);
|
||||
|
||||
// Button
|
||||
Size buttonSize = m_button->getPreferredSize();
|
||||
m_button->setBounds(Rect(bounds.x2() - buttonSize.w, bounds.y,
|
||||
buttonSize.w, bounds.h));
|
||||
|
||||
// Entry
|
||||
m_entry->setBounds(Rect(bounds.x, bounds.y,
|
||||
bounds.w - buttonSize.w, bounds.h));
|
||||
}
|
||||
|
||||
void ComboBox::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
Size reqSize(0, 0);
|
||||
@ -491,9 +485,8 @@ void ComboBox::openListBox()
|
||||
|
||||
m_window->remapWindow();
|
||||
|
||||
JRect rc = getListBoxPos();
|
||||
m_window->positionWindow(rc->x1, rc->y1);
|
||||
jrect_free(rc);
|
||||
gfx::Rect rc = getListBoxPos();
|
||||
m_window->positionWindow(rc.x, rc.y);
|
||||
|
||||
getManager()->addMessageFilter(kMouseDownMessage, this);
|
||||
|
||||
@ -524,14 +517,16 @@ void ComboBox::switchListBox()
|
||||
closeListBox();
|
||||
}
|
||||
|
||||
JRect ComboBox::getListBoxPos()
|
||||
gfx::Rect ComboBox::getListBoxPos() const
|
||||
{
|
||||
JRect rc = jrect_new(m_entry->rc->x1,
|
||||
m_entry->rc->y2,
|
||||
m_button->rc->x2,
|
||||
m_entry->rc->y2+jrect_h(m_window->rc));
|
||||
if (rc->y2 > JI_SCREEN_H)
|
||||
jrect_displace(rc, 0, -(jrect_h(rc)+jrect_h(m_entry->rc)));
|
||||
gfx::Rect rc(gfx::Point(m_entry->rc->x1,
|
||||
m_entry->rc->y2),
|
||||
gfx::Point(m_button->rc->x2,
|
||||
m_entry->rc->y2+jrect_h(m_window->rc)));
|
||||
|
||||
if (rc.y2() > JI_SCREEN_H)
|
||||
rc.offset(0, -(rc.h+jrect_h(m_entry->rc)));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,14 @@ namespace ui {
|
||||
void openListBox();
|
||||
void closeListBox();
|
||||
void switchListBox();
|
||||
JRect getListBoxPos();
|
||||
gfx::Rect getListBoxPos() const;
|
||||
|
||||
// Signals
|
||||
Signal0<void> Change;
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
virtual void onChange();
|
||||
|
||||
|
107
src/ui/grid.cpp
107
src/ui/grid.cpp
@ -16,6 +16,7 @@
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
@ -94,72 +95,22 @@ void Grid::addChildInCell(Widget* child, int hspan, int vspan, int align)
|
||||
}
|
||||
}
|
||||
|
||||
bool Grid::onProcessMessage(Message* msg)
|
||||
void Grid::onResize(ResizeEvent& ev)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
setGridPosition(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Grid::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
w = h = 0;
|
||||
|
||||
calculateSize();
|
||||
|
||||
// Calculate the total
|
||||
sumStripSize(m_colstrip, w);
|
||||
sumStripSize(m_rowstrip, h);
|
||||
|
||||
w += this->border_width.l + this->border_width.r;
|
||||
h += this->border_width.t + this->border_width.b;
|
||||
|
||||
ev.setPreferredSize(Size(w, h));
|
||||
}
|
||||
|
||||
void Grid::onPaint(PaintEvent& ev)
|
||||
{
|
||||
getTheme()->paintGrid(ev);
|
||||
}
|
||||
|
||||
void Grid::sumStripSize(const std::vector<Strip>& strip, int& size)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
size = 0;
|
||||
for (i=j=0; i<(int)strip.size(); ++i) {
|
||||
if (strip[i].size > 0) {
|
||||
size += strip[i].size;
|
||||
if (++j > 1)
|
||||
size += this->child_spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Grid::setGridPosition(JRect rect)
|
||||
{
|
||||
JRect cpos = jrect_new(0, 0, 0, 0);
|
||||
gfx::Rect rect = ev.getBounds();
|
||||
int pos_x, pos_y;
|
||||
Size reqSize;
|
||||
int x, y, w, h;
|
||||
int col, row;
|
||||
|
||||
jrect_copy(this->rc, rect);
|
||||
setBoundsQuietly(rect);
|
||||
|
||||
calculateSize();
|
||||
distributeSize(rect);
|
||||
|
||||
pos_y = rect->y1 + this->border_width.t;
|
||||
pos_y = rect.y + this->border_width.t;
|
||||
for (row=0; row<(int)m_rowstrip.size(); ++row) {
|
||||
pos_x = rect->x1 + this->border_width.l;
|
||||
pos_x = rect.x + this->border_width.l;
|
||||
|
||||
for (col=0; col<(int)m_colstrip.size(); ++col) {
|
||||
Cell* cell = m_cells[row][col];
|
||||
@ -199,8 +150,7 @@ void Grid::setGridPosition(JRect rect)
|
||||
h = reqSize.h;
|
||||
}
|
||||
|
||||
jrect_replace(cpos, x, y, x+w, y+h);
|
||||
jwidget_set_rect(cell->child, cpos);
|
||||
cell->child->setBounds(Rect(x, y, w, h));
|
||||
}
|
||||
|
||||
if (m_colstrip[col].size > 0)
|
||||
@ -210,8 +160,43 @@ void Grid::setGridPosition(JRect rect)
|
||||
if (m_rowstrip[row].size > 0)
|
||||
pos_y += m_rowstrip[row].size + this->child_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
jrect_free(cpos);
|
||||
void Grid::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
w = h = 0;
|
||||
|
||||
calculateSize();
|
||||
|
||||
// Calculate the total
|
||||
sumStripSize(m_colstrip, w);
|
||||
sumStripSize(m_rowstrip, h);
|
||||
|
||||
w += this->border_width.l + this->border_width.r;
|
||||
h += this->border_width.t + this->border_width.b;
|
||||
|
||||
ev.setPreferredSize(Size(w, h));
|
||||
}
|
||||
|
||||
void Grid::onPaint(PaintEvent& ev)
|
||||
{
|
||||
getTheme()->paintGrid(ev);
|
||||
}
|
||||
|
||||
void Grid::sumStripSize(const std::vector<Strip>& strip, int& size)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
size = 0;
|
||||
for (i=j=0; i<(int)strip.size(); ++i) {
|
||||
if (strip[i].size > 0) {
|
||||
size += strip[i].size;
|
||||
if (++j > 1)
|
||||
size += this->child_spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Grid::calculateCellSize(int start, int span, const std::vector<Strip>& strip, int& size)
|
||||
@ -377,13 +362,13 @@ void Grid::expandStrip(std::vector<Strip>& colstrip,
|
||||
} while (more_span);
|
||||
}
|
||||
|
||||
void Grid::distributeSize(JRect rect)
|
||||
void Grid::distributeSize(const gfx::Rect& rect)
|
||||
{
|
||||
if (m_rowstrip.size() == 0)
|
||||
return;
|
||||
|
||||
distributeStripSize(m_colstrip, jrect_w(rect), this->border_width.l + this->border_width.r, m_same_width_columns);
|
||||
distributeStripSize(m_rowstrip, jrect_h(rect), this->border_width.t + this->border_width.b, false);
|
||||
distributeStripSize(m_colstrip, rect.w, this->border_width.l + this->border_width.r, m_same_width_columns);
|
||||
distributeStripSize(m_rowstrip, rect.h, this->border_width.t + this->border_width.b, false);
|
||||
}
|
||||
|
||||
void Grid::distributeStripSize(std::vector<Strip>& colstrip,
|
||||
|
@ -24,7 +24,7 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
// Events
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
|
||||
@ -46,7 +46,6 @@ namespace ui {
|
||||
};
|
||||
|
||||
void sumStripSize(const std::vector<Strip>& strip, int& size);
|
||||
void setGridPosition(JRect rect);
|
||||
void calculateCellSize(int start, int span, const std::vector<Strip>& strip, int& size);
|
||||
void calculateSize();
|
||||
void calculateStripSize(std::vector<Strip>& colstrip,
|
||||
@ -54,7 +53,7 @@ namespace ui {
|
||||
void expandStrip(std::vector<Strip>& colstrip,
|
||||
std::vector<Strip>& rowstrip,
|
||||
void (Grid::*incCol)(int, int));
|
||||
void distributeSize(JRect rect);
|
||||
void distributeSize(const gfx::Rect& rect);
|
||||
void distributeStripSize(std::vector<Strip>& colstrip,
|
||||
int rect_size, int border_size, bool same_width);
|
||||
bool putWidgetInCell(Widget* child, int hspan, int vspan, int align);
|
||||
|
@ -68,7 +68,6 @@ TEST(JGrid, Expand2ndWidget)
|
||||
Grid* grid = new Grid(2, false);
|
||||
Widget* w1 = new Widget(kGenericWidget);
|
||||
Widget* w2 = new Widget(kGenericWidget);
|
||||
JRect rect;
|
||||
|
||||
jwidget_set_min_size(w1, 20, 20);
|
||||
jwidget_set_min_size(w2, 10, 10);
|
||||
@ -82,9 +81,7 @@ TEST(JGrid, Expand2ndWidget)
|
||||
EXPECT_EQ(20, reqSize.h);
|
||||
|
||||
// Test layout
|
||||
rect = jrect_new(0, 0, 40, 20);
|
||||
jwidget_set_rect(grid, rect);
|
||||
jrect_free(rect);
|
||||
grid->setBounds(gfx::Rect(0, 0, 40, 20));
|
||||
|
||||
EXPECT_EQ(0, w1->rc->x1);
|
||||
EXPECT_EQ(0, w1->rc->y1);
|
||||
@ -104,7 +101,6 @@ TEST(JGrid, SameWidth2x1Grid)
|
||||
Grid* grid = new Grid(2, true);
|
||||
Widget* w1 = new Widget(kGenericWidget);
|
||||
Widget* w2 = new Widget(kGenericWidget);
|
||||
JRect rect;
|
||||
|
||||
jwidget_set_min_size(w1, 20, 20);
|
||||
jwidget_set_min_size(w2, 10, 10);
|
||||
@ -118,9 +114,7 @@ TEST(JGrid, SameWidth2x1Grid)
|
||||
EXPECT_EQ(20, reqSize.h);
|
||||
|
||||
// Test layout
|
||||
rect = jrect_new(0, 0, 60, 20);
|
||||
jwidget_set_rect(grid, rect);
|
||||
jrect_free(rect);
|
||||
grid->setBounds(gfx::Rect(0, 0, 60, 20));
|
||||
|
||||
EXPECT_EQ(0, w1->rc->x1);
|
||||
EXPECT_EQ(30, w2->rc->x1);
|
||||
@ -171,7 +165,6 @@ TEST(JGrid, Intrincate3x3Grid)
|
||||
Widget* w2 = new Widget(kGenericWidget);
|
||||
Widget* w3 = new Widget(kGenericWidget);
|
||||
Widget* w4 = new Widget(kGenericWidget);
|
||||
JRect rect;
|
||||
|
||||
jwidget_set_min_size(w1, 10, 10);
|
||||
jwidget_set_min_size(w2, 10, 10);
|
||||
@ -190,9 +183,7 @@ TEST(JGrid, Intrincate3x3Grid)
|
||||
EXPECT_EQ(22, reqSize.h);
|
||||
|
||||
// Test layout
|
||||
rect = jrect_new(0, 0, 100, 100);
|
||||
jwidget_set_rect(grid, rect);
|
||||
jrect_free(rect);
|
||||
grid->setBounds(gfx::Rect(0, 0, 100, 100));
|
||||
|
||||
EXPECT_EQ(0, w1->rc->x1);
|
||||
EXPECT_EQ(0, w1->rc->y1);
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "ui/property.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/register_message.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/save_layout_event.h"
|
||||
#include "ui/scroll_bar.h"
|
||||
#include "ui/separator.h"
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "ui/listitem.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/view.h"
|
||||
@ -124,10 +125,6 @@ bool ListBox::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
layoutListBox(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
case kPaintMessage:
|
||||
this->getTheme()->draw_listbox(this, &msg->draw.rect);
|
||||
return true;
|
||||
@ -259,6 +256,22 @@ bool ListBox::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void ListBox::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
Rect cpos = getChildrenBounds();
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
|
||||
cpos.h = child->getPreferredSize().h;
|
||||
child->setBounds(cpos);
|
||||
|
||||
cpos.y += jrect_h(child->rc) + this->child_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
void ListBox::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int w = 0, h = 0;
|
||||
@ -286,26 +299,4 @@ void ListBox::onDoubleClickItem()
|
||||
DoubleClickItem();
|
||||
}
|
||||
|
||||
void ListBox::layoutListBox(JRect rect)
|
||||
{
|
||||
Size reqSize;
|
||||
JRect cpos;
|
||||
|
||||
jrect_copy(this->rc, rect);
|
||||
cpos = jwidget_get_child_rect(this);
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
|
||||
reqSize = child->getPreferredSize();
|
||||
|
||||
cpos->y2 = cpos->y1+reqSize.h;
|
||||
jwidget_set_rect(child, cpos);
|
||||
|
||||
cpos->y1 += jrect_h(child->rc) + this->child_spacing;
|
||||
}
|
||||
|
||||
jrect_free(cpos);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -35,12 +35,10 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
virtual bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
virtual void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
virtual void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
virtual void onChangeSelectedItem();
|
||||
virtual void onDoubleClickItem();
|
||||
|
||||
private:
|
||||
void layoutListBox(JRect rect);
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/view.h"
|
||||
|
||||
@ -29,19 +30,6 @@ bool ListItem::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage: {
|
||||
JRect crect;
|
||||
|
||||
jrect_copy(this->rc, &msg->setpos.rect);
|
||||
crect = jwidget_get_child_rect(this);
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it)
|
||||
jwidget_set_rect(*it, crect);
|
||||
|
||||
jrect_free(crect);
|
||||
return true;
|
||||
}
|
||||
|
||||
case kPaintMessage:
|
||||
this->getTheme()->draw_listitem(this, &msg->draw.rect);
|
||||
return true;
|
||||
@ -50,6 +38,15 @@ bool ListItem::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void ListItem::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
Rect crect = getChildrenBounds();
|
||||
UI_FOREACH_WIDGET(getChildren(), it)
|
||||
(*it)->setBounds(crect);
|
||||
}
|
||||
|
||||
void ListItem::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int w = 0, h = 0;
|
||||
|
@ -19,6 +19,7 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
};
|
||||
|
||||
|
@ -883,10 +883,6 @@ bool Manager::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
layoutManager(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
case kKeyDownMessage:
|
||||
case kKeyUpMessage: {
|
||||
msg->key.propagate_to_children = true;
|
||||
@ -919,6 +915,24 @@ bool Manager::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Manager::onResize(ResizeEvent& ev)
|
||||
{
|
||||
gfx::Rect old_pos = getBounds();
|
||||
gfx::Rect new_pos = ev.getBounds();
|
||||
setBoundsQuietly(new_pos);
|
||||
|
||||
// Offset for all windows
|
||||
int dx = new_pos.x - old_pos.x;
|
||||
int dy = new_pos.y - old_pos.y;
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
gfx::Rect cpos = child->getBounds();
|
||||
cpos.offset(dx, dy);
|
||||
child->setBounds(cpos);
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::onPaint(PaintEvent& ev)
|
||||
{
|
||||
getTheme()->paintDesktop(ev);
|
||||
@ -963,30 +977,6 @@ void Manager::onPreferredSize(PreferredSizeEvent& ev)
|
||||
ev.setPreferredSize(gfx::Size(w, h));
|
||||
}
|
||||
|
||||
void Manager::layoutManager(JRect rect)
|
||||
{
|
||||
JRect cpos, old_pos;
|
||||
int x, y;
|
||||
|
||||
old_pos = jrect_new_copy(this->rc);
|
||||
jrect_copy(this->rc, rect);
|
||||
|
||||
// Offset for all windows
|
||||
x = this->rc->x1 - old_pos->x1;
|
||||
y = this->rc->y1 - old_pos->y1;
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
|
||||
cpos = jwidget_get_rect(child);
|
||||
jrect_displace(cpos, x, y);
|
||||
jwidget_set_rect(child, cpos);
|
||||
jrect_free(cpos);
|
||||
}
|
||||
|
||||
jrect_free(old_pos);
|
||||
}
|
||||
|
||||
void Manager::pumpQueue()
|
||||
{
|
||||
#ifdef LIMIT_DISPATCH_TIME
|
||||
@ -1033,7 +1023,6 @@ void Manager::pumpQueue()
|
||||
"kCloseAppMessage",
|
||||
"kPaintMessage",
|
||||
"kTimerMessage",
|
||||
"kResizeMessage",
|
||||
"kWinMoveMessage",
|
||||
"kQueueProcessingMessage",
|
||||
|
||||
|
@ -74,13 +74,13 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onBroadcastMouseMessage(WidgetsList& targets) OVERRIDE;
|
||||
virtual LayoutIO* onGetLayoutIO();
|
||||
|
||||
private:
|
||||
void layoutManager(JRect rect);
|
||||
void pumpQueue();
|
||||
void generateSetCursorMessage();
|
||||
static void removeWidgetFromDests(Widget* widget, Message* msg);
|
||||
|
@ -294,10 +294,6 @@ bool Menu::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
set_position(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
case kPaintMessage:
|
||||
getTheme()->draw_menu(this, &msg->draw.rect);
|
||||
return true;
|
||||
@ -307,6 +303,31 @@ bool Menu::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Menu::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
Rect cpos = getChildrenBounds();
|
||||
bool isBar = (getParent()->type == kMenuBarWidget);
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
Size reqSize = child->getPreferredSize();
|
||||
|
||||
if (isBar)
|
||||
cpos.w = reqSize.w;
|
||||
else
|
||||
cpos.h = reqSize.h;
|
||||
|
||||
child->setBounds(cpos);
|
||||
|
||||
if (isBar)
|
||||
cpos.x += cpos.w;
|
||||
else
|
||||
cpos.y += cpos.h;
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
Size size(0, 0);
|
||||
@ -331,46 +352,12 @@ void Menu::onPreferredSize(PreferredSizeEvent& ev)
|
||||
ev.setPreferredSize(size);
|
||||
}
|
||||
|
||||
void Menu::set_position(JRect rect)
|
||||
{
|
||||
Size reqSize;
|
||||
Widget* child;
|
||||
JRect cpos;
|
||||
|
||||
jrect_copy(this->rc, rect);
|
||||
cpos = jwidget_get_child_rect(this);
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
child = *it;
|
||||
|
||||
reqSize = child->getPreferredSize();
|
||||
|
||||
if (this->getParent()->type == kMenuBarWidget)
|
||||
cpos->x2 = cpos->x1+reqSize.w;
|
||||
else
|
||||
cpos->y2 = cpos->y1+reqSize.h;
|
||||
|
||||
jwidget_set_rect(child, cpos);
|
||||
|
||||
if (this->getParent()->type == kMenuBarWidget)
|
||||
cpos->x1 += jrect_w(cpos);
|
||||
else
|
||||
cpos->y1 += jrect_h(cpos);
|
||||
}
|
||||
|
||||
jrect_free(cpos);
|
||||
}
|
||||
|
||||
bool MenuBox::onProcessMessage(Message* msg)
|
||||
{
|
||||
Menu* menu = MenuBox::getMenu();
|
||||
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
set_position(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
case kMouseMoveMessage:
|
||||
/* isn't pressing a button? */
|
||||
if (!msg->mouse.flags && !get_base(this)->was_clicked)
|
||||
@ -657,6 +644,14 @@ bool MenuBox::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void MenuBox::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
if (Menu* menu = getMenu())
|
||||
menu->setBounds(getChildrenBounds());
|
||||
}
|
||||
|
||||
void MenuBox::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
Size size(0, 0);
|
||||
@ -670,14 +665,6 @@ void MenuBox::onPreferredSize(PreferredSizeEvent& ev)
|
||||
ev.setPreferredSize(size);
|
||||
}
|
||||
|
||||
void MenuBox::set_position(JRect rect)
|
||||
{
|
||||
jrect_copy(this->rc, rect);
|
||||
|
||||
if (Menu* menu = getMenu())
|
||||
menu->setBounds(getChildrenBounds());
|
||||
}
|
||||
|
||||
bool MenuItem::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
@ -35,6 +35,7 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
virtual bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
virtual void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
virtual void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
@ -42,7 +43,6 @@ namespace ui {
|
||||
m_menuitem = ownerMenuItem;
|
||||
}
|
||||
|
||||
void set_position(JRect rect);
|
||||
void closeAll();
|
||||
|
||||
MenuItem* getHighlightedItem();
|
||||
@ -74,11 +74,11 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
virtual bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
virtual void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
virtual void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
MenuBaseData* createBase();
|
||||
|
||||
private:
|
||||
void set_position(JRect rect);
|
||||
void closePopup();
|
||||
|
||||
MenuBaseData* m_base;
|
||||
|
@ -17,7 +17,6 @@ namespace ui {
|
||||
kCloseAppMessage, // The user wants to close the entire application.
|
||||
kPaintMessage, // Widget needs be repainted.
|
||||
kTimerMessage, // A timer timeout.
|
||||
kResizeMessage, // Set position.
|
||||
kWinMoveMessage, // Window movement.
|
||||
kQueueProcessingMessage, // Only sent to manager which indicate
|
||||
// the last message in the queue.
|
||||
|
22
src/ui/resize_event.cpp
Normal file
22
src/ui/resize_event.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// ASEPRITE gui library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
//
|
||||
// This source file is distributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
using namespace gfx;
|
||||
|
||||
namespace ui {
|
||||
|
||||
ResizeEvent::ResizeEvent(Widget* source, const gfx::Rect& bounds)
|
||||
: Event(source)
|
||||
, m_bounds(bounds)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace ui
|
30
src/ui/resize_event.h
Normal file
30
src/ui/resize_event.h
Normal file
@ -0,0 +1,30 @@
|
||||
// ASEPRITE gui library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
//
|
||||
// This source file is distributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UI_RESIZE_EVENT_H_INCLUDED
|
||||
#define UI_RESIZE_EVENT_H_INCLUDED
|
||||
|
||||
#include "gfx/rect.h"
|
||||
#include "ui/event.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Widget;
|
||||
|
||||
class ResizeEvent : public Event
|
||||
{
|
||||
public:
|
||||
ResizeEvent(Widget* source, const gfx::Rect& bounds);
|
||||
|
||||
const gfx::Rect& getBounds() { return m_bounds; }
|
||||
|
||||
private:
|
||||
gfx::Rect m_bounds;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
@ -11,6 +11,7 @@
|
||||
#include "ui/load_layout_event.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/save_layout_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
@ -49,10 +50,6 @@ bool Splitter::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
layoutMembers(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
case kMouseDownMessage:
|
||||
if (isEnabled()) {
|
||||
Widget* c1, *c2;
|
||||
@ -121,8 +118,7 @@ bool Splitter::onProcessMessage(Message* msg)
|
||||
}
|
||||
}
|
||||
|
||||
jwidget_set_rect(this, this->rc);
|
||||
invalidate();
|
||||
layout();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@ -181,6 +177,55 @@ bool Splitter::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Splitter::onResize(ResizeEvent& ev)
|
||||
{
|
||||
#define FIXUP(x, y, w, h, l, t, r, b) \
|
||||
do { \
|
||||
avail = rect.w - this->child_spacing; \
|
||||
\
|
||||
pos.x = rect.x; \
|
||||
pos.y = rect.y; \
|
||||
switch (m_type) { \
|
||||
case ByPercentage: \
|
||||
pos.w = avail*m_pos/100; \
|
||||
break; \
|
||||
case ByPixel: \
|
||||
pos.w = m_pos; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
/* TODO uncomment this to make a restricted splitter */ \
|
||||
/* pos.w = MID(reqSize1.w, pos.w, avail-reqSize2.w); */ \
|
||||
pos.h = rect.h; \
|
||||
\
|
||||
child1->setBounds(pos); \
|
||||
gfx::Rect child1Pos = child1->getBounds(); \
|
||||
\
|
||||
pos.x = child1Pos.x + child1Pos.w + this->child_spacing; \
|
||||
pos.y = rect.y; \
|
||||
pos.w = avail - child1Pos.w; \
|
||||
pos.h = rect.h; \
|
||||
\
|
||||
child2->setBounds(pos); \
|
||||
} while(0)
|
||||
|
||||
gfx::Rect rect(ev.getBounds());
|
||||
gfx::Rect pos(0, 0, 0, 0);
|
||||
int avail;
|
||||
|
||||
setBoundsQuietly(rect);
|
||||
|
||||
if (getChildren().size() == 2) {
|
||||
Widget* child1 = getChildren()[0];
|
||||
Widget* child2 = getChildren()[1];
|
||||
|
||||
if (this->getAlign() & JI_HORIZONTAL)
|
||||
FIXUP(x, y, w, h, l, t, r, b);
|
||||
else
|
||||
FIXUP(y, x, h, w, t, l, b, r);
|
||||
}
|
||||
}
|
||||
|
||||
void Splitter::onPaint(PaintEvent& ev)
|
||||
{
|
||||
getTheme()->drawSplitter(ev);
|
||||
@ -258,54 +303,4 @@ void Splitter::onSaveLayout(SaveLayoutEvent& ev)
|
||||
(*it)->saveLayout();
|
||||
}
|
||||
|
||||
void Splitter::layoutMembers(JRect rect)
|
||||
{
|
||||
#define FIXUP(x, y, w, h, l, t, r, b) \
|
||||
do { \
|
||||
avail = jrect_##w(this->rc) - this->child_spacing; \
|
||||
\
|
||||
pos->x##1 = this->rc->x##1; \
|
||||
pos->y##1 = this->rc->y##1; \
|
||||
switch (m_type) { \
|
||||
case ByPercentage: \
|
||||
pos->x##2 = pos->x##1 + avail*m_pos/100; \
|
||||
break; \
|
||||
case ByPixel: \
|
||||
pos->x##2 = pos->x##1 + m_pos; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
/* TODO uncomment this to make a restricted splitter */ \
|
||||
/* pos->w = MID(reqSize1.w, pos->w, avail-reqSize2.w); */ \
|
||||
pos->y##2 = pos->y##1 + jrect_##h(this->rc); \
|
||||
\
|
||||
jwidget_set_rect(child1, pos); \
|
||||
\
|
||||
pos->x##1 = child1->rc->x##1 + jrect_##w(child1->rc) \
|
||||
+ this->child_spacing; \
|
||||
pos->y##1 = this->rc->y##1; \
|
||||
pos->x##2 = pos->x##1 + avail - jrect_##w(child1->rc); \
|
||||
pos->y##2 = pos->y##1 + jrect_##h(this->rc); \
|
||||
\
|
||||
jwidget_set_rect(child2, pos); \
|
||||
} while(0)
|
||||
|
||||
JRect pos = jrect_new(0, 0, 0, 0);
|
||||
int avail;
|
||||
|
||||
jrect_copy(this->rc, rect);
|
||||
|
||||
if (getChildren().size() == 2) {
|
||||
Widget* child1 = getChildren()[0];
|
||||
Widget* child2 = getChildren()[1];
|
||||
|
||||
if (this->getAlign() & JI_HORIZONTAL)
|
||||
FIXUP(x, y, w, h, l, t, r, b);
|
||||
else
|
||||
FIXUP(y, x, h, w, t, l, b, r);
|
||||
}
|
||||
|
||||
jrect_free(pos);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -25,14 +25,13 @@ namespace ui {
|
||||
protected:
|
||||
// Events
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onLoadLayout(LoadLayoutEvent& ev) OVERRIDE;
|
||||
void onSaveLayout(SaveLayoutEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
void layoutMembers(JRect rect);
|
||||
|
||||
Type m_type;
|
||||
double m_pos;
|
||||
};
|
||||
|
@ -136,9 +136,7 @@ void SetDisplay(she::Display* display)
|
||||
// Update default-manager size
|
||||
if ((jrect_w(manager->rc) != JI_SCREEN_W ||
|
||||
jrect_h(manager->rc) != JI_SCREEN_H)) {
|
||||
JRect rect = jrect_new(0, 0, JI_SCREEN_W, JI_SCREEN_H);
|
||||
jwidget_set_rect(manager, rect);
|
||||
jrect_free(rect);
|
||||
manager->setBounds(gfx::Rect(0, 0, JI_SCREEN_W, JI_SCREEN_H));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/view.h"
|
||||
@ -84,14 +85,12 @@ void View::setScrollableSize(const Size& sz)
|
||||
((sz.w > jrect_##w(m_viewport.rc) \
|
||||
- m_viewport.border_width.l \
|
||||
- m_viewport.border_width.r) && \
|
||||
(BAR_SIZE < jrect_##w(pos)) && (BAR_SIZE < jrect_##h(pos)))
|
||||
|
||||
JRect pos, rect;
|
||||
(BAR_SIZE < pos.w) && (BAR_SIZE < pos.h))
|
||||
|
||||
m_scrollbar_h.setSize(sz.w);
|
||||
m_scrollbar_v.setSize(sz.h);
|
||||
|
||||
pos = jwidget_get_child_rect(this);
|
||||
gfx::Rect pos = getChildrenBounds();
|
||||
|
||||
// Setup scroll-bars
|
||||
removeChild(&m_scrollbar_h);
|
||||
@ -99,53 +98,45 @@ void View::setScrollableSize(const Size& sz)
|
||||
|
||||
if (m_hasBars) {
|
||||
if (CHECK(w, h, l, t, r, b)) {
|
||||
pos->y2 -= BAR_SIZE;
|
||||
pos.h -= BAR_SIZE;
|
||||
addChild(&m_scrollbar_h);
|
||||
|
||||
if (CHECK(h, w, t, l, b, r)) {
|
||||
pos->x2 -= BAR_SIZE;
|
||||
pos.w -= BAR_SIZE;
|
||||
if (CHECK(w, h, l, t, r, b))
|
||||
addChild(&m_scrollbar_v);
|
||||
else {
|
||||
pos->x2 += BAR_SIZE;
|
||||
pos->y2 += BAR_SIZE;
|
||||
pos.w += BAR_SIZE;
|
||||
pos.h += BAR_SIZE;
|
||||
removeChild(&m_scrollbar_h);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (CHECK(h, w, t, l, b, r)) {
|
||||
pos->x2 -= BAR_SIZE;
|
||||
pos.w -= BAR_SIZE;
|
||||
addChild(&m_scrollbar_v);
|
||||
|
||||
if (CHECK(w, h, l, t, r, b)) {
|
||||
pos->y2 -= BAR_SIZE;
|
||||
pos.h -= BAR_SIZE;
|
||||
if (CHECK(h, w, t, l, b, r))
|
||||
addChild(&m_scrollbar_h);
|
||||
else {
|
||||
pos->x2 += BAR_SIZE;
|
||||
pos->y2 += BAR_SIZE;
|
||||
pos.w += BAR_SIZE;
|
||||
pos.h += BAR_SIZE;
|
||||
removeChild(&m_scrollbar_v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasChild(&m_scrollbar_h)) {
|
||||
rect = jrect_new(pos->x1, pos->y2,
|
||||
pos->x1+jrect_w(pos), pos->y2+BAR_SIZE);
|
||||
jwidget_set_rect(&m_scrollbar_h, rect);
|
||||
jrect_free(rect);
|
||||
|
||||
m_scrollbar_h.setBounds(gfx::Rect(pos.x, pos.y2(), pos.w, BAR_SIZE));
|
||||
m_scrollbar_h.setVisible(true);
|
||||
}
|
||||
else
|
||||
m_scrollbar_h.setVisible(false);
|
||||
|
||||
if (hasChild(&m_scrollbar_v)) {
|
||||
rect = jrect_new(pos->x2, pos->y1,
|
||||
pos->x2+BAR_SIZE, pos->y1+jrect_h(pos));
|
||||
jwidget_set_rect(&m_scrollbar_v, rect);
|
||||
jrect_free(rect);
|
||||
|
||||
m_scrollbar_v.setBounds(gfx::Rect(pos.x2(), pos.y, BAR_SIZE, pos.h));
|
||||
m_scrollbar_v.setVisible(true);
|
||||
}
|
||||
else
|
||||
@ -154,10 +145,8 @@ void View::setScrollableSize(const Size& sz)
|
||||
|
||||
// Setup viewport
|
||||
invalidate();
|
||||
jwidget_set_rect(&m_viewport, pos);
|
||||
m_viewport.setBounds(pos);
|
||||
setViewScroll(getViewScroll()); // Setup the same scroll-point
|
||||
|
||||
jrect_free(pos);
|
||||
}
|
||||
|
||||
Size View::getVisibleSize()
|
||||
@ -186,8 +175,7 @@ void View::setViewScroll(const Point& pt)
|
||||
m_scrollbar_h.setPos(newScroll.x);
|
||||
m_scrollbar_v.setPos(newScroll.y);
|
||||
|
||||
jwidget_set_rect(&m_viewport, m_viewport.rc);
|
||||
invalidate();
|
||||
m_viewport.layout();
|
||||
}
|
||||
|
||||
void View::updateView()
|
||||
@ -239,11 +227,6 @@ bool View::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
jrect_copy(this->rc, &msg->setpos.rect);
|
||||
updateView();
|
||||
return true;
|
||||
|
||||
case kFocusEnterMessage:
|
||||
case kFocusLeaveMessage:
|
||||
// TODO This is theme specific stuff
|
||||
@ -259,6 +242,12 @@ bool View::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void View::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
updateView();
|
||||
}
|
||||
|
||||
void View::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
Size viewSize = m_viewport.getPreferredSize();
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
protected:
|
||||
// Events
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "gfx/size.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/preferred_size_event.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "ui/theme.h"
|
||||
#include "ui/view.h"
|
||||
#include "ui/viewport.h"
|
||||
@ -24,16 +25,31 @@ Viewport::Viewport()
|
||||
initTheme();
|
||||
}
|
||||
|
||||
bool Viewport::onProcessMessage(Message* msg)
|
||||
void Viewport::onResize(ResizeEvent& ev)
|
||||
{
|
||||
switch (msg->type) {
|
||||
Rect rect = ev.getBounds();
|
||||
setBoundsQuietly(rect);
|
||||
|
||||
case kResizeMessage:
|
||||
set_position(&msg->setpos.rect);
|
||||
return true;
|
||||
Point scroll = static_cast<View*>(this->getParent())->getViewScroll();
|
||||
|
||||
Rect cpos(0, 0, 0, 0);
|
||||
cpos.x = rect.x + this->border_width.l - scroll.x;
|
||||
cpos.y = rect.y + this->border_width.t - scroll.y;
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
Size reqSize = child->getPreferredSize();
|
||||
|
||||
cpos.w = MAX(reqSize.w, rect.w
|
||||
- this->border_width.l
|
||||
- this->border_width.r);
|
||||
|
||||
cpos.h = MAX(reqSize.h, rect.h
|
||||
- this->border_width.t
|
||||
- this->border_width.b);
|
||||
|
||||
child->setBounds(cpos);
|
||||
}
|
||||
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Viewport::onPreferredSize(PreferredSizeEvent& ev)
|
||||
@ -61,35 +77,4 @@ Size Viewport::calculateNeededSize()
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
void Viewport::set_position(JRect rect)
|
||||
{
|
||||
Size reqSize;
|
||||
JRect cpos;
|
||||
|
||||
jrect_copy(this->rc, rect);
|
||||
|
||||
Point scroll = static_cast<View*>(this->getParent())->getViewScroll();
|
||||
|
||||
cpos = jrect_new(0, 0, 0, 0);
|
||||
cpos->x1 = this->rc->x1 + this->border_width.l - scroll.x;
|
||||
cpos->y1 = this->rc->y1 + this->border_width.t - scroll.y;
|
||||
|
||||
UI_FOREACH_WIDGET(getChildren(), it) {
|
||||
Widget* child = *it;
|
||||
reqSize = child->getPreferredSize();
|
||||
|
||||
cpos->x2 = cpos->x1 + MAX(reqSize.w, jrect_w(this->rc)
|
||||
- this->border_width.l
|
||||
- this->border_width.r);
|
||||
|
||||
cpos->y2 = cpos->y1 + MAX(reqSize.h, jrect_h(this->rc)
|
||||
- this->border_width.t
|
||||
- this->border_width.b);
|
||||
|
||||
jwidget_set_rect(child, cpos);
|
||||
}
|
||||
|
||||
jrect_free(cpos);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -21,12 +21,9 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
// Events
|
||||
bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
void set_position(JRect rect);
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
@ -519,7 +519,7 @@ void Widget::insertChild(int index, Widget* child)
|
||||
|
||||
void Widget::layout()
|
||||
{
|
||||
jwidget_set_rect(this, rc);
|
||||
setBounds(getBounds());
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@ -567,18 +567,9 @@ void Widget::setDecorativeWidgetBounds()
|
||||
onSetDecorativeWidgetBounds();
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/* position and geometry */
|
||||
|
||||
Rect Widget::getBounds() const
|
||||
{
|
||||
return Rect(rc->x1, rc->y1, jrect_w(rc), jrect_h(rc));
|
||||
}
|
||||
|
||||
Rect Widget::getClientBounds() const
|
||||
{
|
||||
return Rect(0, 0, jrect_w(rc), jrect_h(rc));
|
||||
}
|
||||
// ===============================================================
|
||||
// POSITION & GEOMETRY
|
||||
// ===============================================================
|
||||
|
||||
Rect Widget::getChildrenBounds() const
|
||||
{
|
||||
@ -590,8 +581,14 @@ Rect Widget::getChildrenBounds() const
|
||||
|
||||
void Widget::setBounds(const Rect& rc)
|
||||
{
|
||||
jrect jrc = { rc.x, rc.y, rc.x+rc.w, rc.y+rc.h };
|
||||
jwidget_set_rect(this, &jrc);
|
||||
ResizeEvent ev(this, rc);
|
||||
onResize(ev);
|
||||
}
|
||||
|
||||
void Widget::setBoundsQuietly(const gfx::Rect& rc)
|
||||
{
|
||||
jrect jrc = { rc.x, rc.y, rc.x2(), rc.y2() };
|
||||
jrect_copy(this->rc, &jrc);
|
||||
}
|
||||
|
||||
Border Widget::getBorder() const
|
||||
@ -882,18 +879,6 @@ void jwidget_set_border(Widget* widget, int l, int t, int r, int b)
|
||||
widget->invalidate();
|
||||
}
|
||||
|
||||
void jwidget_set_rect(Widget* widget, JRect rect)
|
||||
{
|
||||
Message* msg;
|
||||
|
||||
ASSERT_VALID_WIDGET(widget);
|
||||
|
||||
msg = jmessage_new(kResizeMessage);
|
||||
jrect_copy(&msg->setpos.rect, rect);
|
||||
widget->sendMessage(msg);
|
||||
jmessage_free(msg);
|
||||
}
|
||||
|
||||
void jwidget_set_min_size(Widget* widget, int w, int h)
|
||||
{
|
||||
ASSERT_VALID_WIDGET(widget);
|
||||
@ -1265,18 +1250,6 @@ bool Widget::onProcessMessage(Message* msg)
|
||||
return ev.isPainted();
|
||||
}
|
||||
|
||||
case kResizeMessage: {
|
||||
jrect_copy(this->rc, &msg->setpos.rect);
|
||||
JRect cpos = jwidget_get_child_rect(this);
|
||||
|
||||
// Set all the children to the same "cpos".
|
||||
UI_FOREACH_WIDGET(getChildren(), it)
|
||||
jwidget_set_rect(*it, cpos);
|
||||
|
||||
jrect_free(cpos);
|
||||
return true;
|
||||
}
|
||||
|
||||
case kKeyDownMessage:
|
||||
case kKeyUpMessage:
|
||||
if (msg->key.propagate_to_children) {
|
||||
@ -1354,6 +1327,16 @@ void Widget::onSaveLayout(SaveLayoutEvent& ev)
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void Widget::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
// Set all the children to the same "cpos".
|
||||
gfx::Rect cpos = getChildrenBounds();
|
||||
UI_FOREACH_WIDGET(getChildren(), it)
|
||||
(*it)->setBounds(cpos);
|
||||
}
|
||||
|
||||
void Widget::onPaint(PaintEvent& ev)
|
||||
{
|
||||
// Do nothing
|
||||
|
@ -34,6 +34,7 @@ namespace ui {
|
||||
class Manager;
|
||||
class PaintEvent;
|
||||
class PreferredSizeEvent;
|
||||
class ResizeEvent;
|
||||
class SaveLayoutEvent;
|
||||
class Theme;
|
||||
class Window;
|
||||
@ -53,7 +54,6 @@ namespace ui {
|
||||
void jwidget_noborders(Widget* widget);
|
||||
void jwidget_set_border(Widget* widget, int value);
|
||||
void jwidget_set_border(Widget* widget, int l, int t, int r, int b);
|
||||
void jwidget_set_rect(Widget* widget, JRect rect);
|
||||
void jwidget_set_min_size(Widget* widget, int w, int h);
|
||||
void jwidget_set_max_size(Widget* widget, int w, int h);
|
||||
|
||||
@ -250,11 +250,25 @@ namespace ui {
|
||||
// POSITION & GEOMETRY
|
||||
// ===============================================================
|
||||
|
||||
gfx::Rect getBounds() const;
|
||||
gfx::Rect getClientBounds() const;
|
||||
gfx::Rect getBounds() const {
|
||||
return gfx::Rect(rc->x1, rc->y1, jrect_w(rc), jrect_h(rc));
|
||||
}
|
||||
|
||||
gfx::Rect getClientBounds() const {
|
||||
return gfx::Rect(0, 0, jrect_w(rc), jrect_h(rc));
|
||||
}
|
||||
|
||||
gfx::Rect getChildrenBounds() const;
|
||||
|
||||
// Sets the bounds of the widget generating a onResize() event.
|
||||
void setBounds(const gfx::Rect& rc);
|
||||
|
||||
// Sets the bounds of the widget without generating any kind of
|
||||
// event. This member function must be used if you override
|
||||
// onResize() and want to change the size of the widget without
|
||||
// generating recursive onResize() events.
|
||||
void setBoundsQuietly(const gfx::Rect& rc);
|
||||
|
||||
gfx::Border getBorder() const;
|
||||
void setBorder(const gfx::Border& border);
|
||||
|
||||
@ -335,6 +349,7 @@ namespace ui {
|
||||
virtual void onPreferredSize(PreferredSizeEvent& ev);
|
||||
virtual void onLoadLayout(LoadLayoutEvent& ev);
|
||||
virtual void onSaveLayout(SaveLayoutEvent& ev);
|
||||
virtual void onResize(ResizeEvent& ev);
|
||||
virtual void onPaint(PaintEvent& ev);
|
||||
virtual void onBroadcastMouseMessage(WidgetsList& targets);
|
||||
virtual void onInitTheme(InitThemeEvent& ev);
|
||||
|
@ -176,21 +176,13 @@ void Window::onHitTest(HitTestEvent& ev)
|
||||
|
||||
void Window::remapWindow()
|
||||
{
|
||||
Size reqSize;
|
||||
JRect rect;
|
||||
|
||||
if (m_isAutoRemap) {
|
||||
m_isAutoRemap = false;
|
||||
this->setVisible(true);
|
||||
}
|
||||
|
||||
reqSize = this->getPreferredSize();
|
||||
|
||||
rect = jrect_new(this->rc->x1, this->rc->y1,
|
||||
this->rc->x1+reqSize.w,
|
||||
this->rc->y1+reqSize.h);
|
||||
jwidget_set_rect(this, rect);
|
||||
jrect_free(rect);
|
||||
setBounds(Rect(Point(this->rc->x1, this->rc->y1),
|
||||
getPreferredSize()));
|
||||
|
||||
// load layout
|
||||
loadLayout();
|
||||
@ -211,19 +203,15 @@ void Window::centerWindow()
|
||||
|
||||
void Window::positionWindow(int x, int y)
|
||||
{
|
||||
JRect rect;
|
||||
|
||||
if (m_isAutoRemap)
|
||||
remapWindow();
|
||||
|
||||
rect = jrect_new(x, y, x+jrect_w(this->rc), y+jrect_h(this->rc));
|
||||
jwidget_set_rect(this, rect);
|
||||
jrect_free(rect);
|
||||
setBounds(Rect(x, y, jrect_w(this->rc), jrect_h(this->rc)));
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void Window::moveWindow(JRect rect)
|
||||
void Window::moveWindow(const gfx::Rect& rect)
|
||||
{
|
||||
moveWindow(rect, true);
|
||||
}
|
||||
@ -276,10 +264,6 @@ bool Window::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
windowSetPosition(&msg->setpos.rect);
|
||||
return true;
|
||||
|
||||
case kOpenMessage:
|
||||
m_killer = NULL;
|
||||
break;
|
||||
@ -335,11 +319,9 @@ bool Window::onProcessMessage(Message* msg)
|
||||
if (m_hitTest == HitTestCaption) {
|
||||
int x = click_pos->x1 + (msg->mouse.x - press_x);
|
||||
int y = click_pos->y1 + (msg->mouse.y - press_y);
|
||||
JRect rect = jrect_new(x, y,
|
||||
x+jrect_w(this->rc),
|
||||
y+jrect_h(this->rc));
|
||||
moveWindow(rect, true);
|
||||
jrect_free(rect);
|
||||
moveWindow(gfx::Rect(x, y,
|
||||
jrect_w(this->rc),
|
||||
jrect_h(this->rc)), true);
|
||||
}
|
||||
else {
|
||||
int x, y, w, h;
|
||||
@ -388,13 +370,8 @@ bool Window::onProcessMessage(Message* msg)
|
||||
else
|
||||
y = this->rc->y1;
|
||||
|
||||
{
|
||||
JRect rect = jrect_new(x, y, x+w, y+h);
|
||||
moveWindow(rect, false);
|
||||
jrect_free(rect);
|
||||
|
||||
invalidate();
|
||||
}
|
||||
moveWindow(gfx::Rect(x, y, w, h), false);
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -455,6 +432,11 @@ bool Window::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Window::onResize(ResizeEvent& ev)
|
||||
{
|
||||
windowSetPosition(ev.getBounds());
|
||||
}
|
||||
|
||||
void Window::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
Widget* manager = getManager();
|
||||
@ -511,10 +493,10 @@ void Window::onSetText()
|
||||
initTheme();
|
||||
}
|
||||
|
||||
void Window::windowSetPosition(JRect rect)
|
||||
void Window::windowSetPosition(const gfx::Rect& rect)
|
||||
{
|
||||
// Copy the new position rectangle
|
||||
jrect_copy(this->rc, rect);
|
||||
setBoundsQuietly(rect);
|
||||
Rect cpos = getChildrenBounds();
|
||||
|
||||
// Set all the children to the same "cpos"
|
||||
@ -534,7 +516,7 @@ void Window::limitSize(int *w, int *h)
|
||||
*h = MAX(*h, this->border_width.t+this->border_width.b);
|
||||
}
|
||||
|
||||
void Window::moveWindow(JRect rect, bool use_blit)
|
||||
void Window::moveWindow(const gfx::Rect& rect, bool use_blit)
|
||||
{
|
||||
#define FLAGS (DrawableRegionFlags)(kCutTopWindows | kUseChildArea)
|
||||
|
||||
@ -564,18 +546,17 @@ void Window::moveWindow(JRect rect, bool use_blit)
|
||||
getDrawableRegion(old_drawable_region, FLAGS);
|
||||
|
||||
// If the size of the window changes...
|
||||
if (jrect_w(old_pos) != jrect_w(rect) ||
|
||||
jrect_h(old_pos) != jrect_h(rect)) {
|
||||
// We have to change the whole positions sending kResizeMessage
|
||||
// messages...
|
||||
if (jrect_w(old_pos) != rect.w ||
|
||||
jrect_h(old_pos) != rect.h) {
|
||||
// We have to change the position of all children.
|
||||
windowSetPosition(rect);
|
||||
}
|
||||
else {
|
||||
// We can just displace all the widgets by a delta (new_position -
|
||||
// old_position)...
|
||||
displace_widgets(this,
|
||||
rect->x1 - old_pos->x1,
|
||||
rect->y1 - old_pos->y1);
|
||||
rect.x - old_pos->x1,
|
||||
rect.y - old_pos->y1);
|
||||
}
|
||||
|
||||
// Get the new drawable region of the window (it's new because we
|
||||
|
@ -34,7 +34,7 @@ namespace ui {
|
||||
void remapWindow();
|
||||
void centerWindow();
|
||||
void positionWindow(int x, int y);
|
||||
void moveWindow(JRect rect);
|
||||
void moveWindow(const gfx::Rect& rect);
|
||||
|
||||
void openWindow();
|
||||
void openWindowInForeground();
|
||||
@ -56,6 +56,7 @@ namespace ui {
|
||||
|
||||
protected:
|
||||
virtual bool onProcessMessage(Message* msg) OVERRIDE;
|
||||
virtual void onResize(ResizeEvent& ev) OVERRIDE;
|
||||
virtual void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
|
||||
virtual void onPaint(PaintEvent& ev) OVERRIDE;
|
||||
virtual void onBroadcastMouseMessage(WidgetsList& targets) OVERRIDE;
|
||||
@ -66,10 +67,10 @@ namespace ui {
|
||||
virtual void onHitTest(HitTestEvent& ev);
|
||||
|
||||
private:
|
||||
void windowSetPosition(JRect rect);
|
||||
void windowSetPosition(const gfx::Rect& rect);
|
||||
int getAction(int x, int y);
|
||||
void limitSize(int* w, int* h);
|
||||
void moveWindow(JRect rect, bool use_blit);
|
||||
void moveWindow(const gfx::Rect& rect, bool use_blit);
|
||||
|
||||
Widget* m_killer;
|
||||
bool m_isDesktop : 1;
|
||||
|
@ -23,14 +23,13 @@
|
||||
#include "modules/editors.h"
|
||||
#include "skin/skin_theme.h"
|
||||
#include "ui/message.h"
|
||||
#include "ui/resize_event.h"
|
||||
#include "widgets/editor/editor.h"
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
using namespace ui;
|
||||
|
||||
using namespace ui;
|
||||
|
||||
EditorView::EditorView(EditorView::Type type)
|
||||
: View()
|
||||
, m_type(type)
|
||||
@ -49,13 +48,6 @@ bool EditorView::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
// This avoid the displacement of the widgets in the viewport
|
||||
|
||||
jrect_copy(this->rc, &msg->setpos.rect);
|
||||
updateView();
|
||||
return true;
|
||||
|
||||
case kPaintMessage:
|
||||
{
|
||||
Widget* viewport = getViewport();
|
||||
@ -93,3 +85,11 @@ bool EditorView::onProcessMessage(Message* msg)
|
||||
|
||||
return View::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void EditorView::onResize(ResizeEvent& ev)
|
||||
{
|
||||
// This avoid the displacement of the widgets in the viewport
|
||||
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
updateView();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) OVERRIDE;
|
||||
void onResize(ui::ResizeEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
|
@ -78,20 +78,18 @@ protected:
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
||||
Widget* window = getParent();
|
||||
JRect rect = jrect_new(0, 0, 0, 0);
|
||||
gfx::Rect rect(0, 0, 0, 0);
|
||||
gfx::Size playSize = theme->get_part_size(PART_WINDOW_PLAY_BUTTON_NORMAL);
|
||||
gfx::Size closeSize = theme->get_part_size(PART_WINDOW_CLOSE_BUTTON_NORMAL);
|
||||
|
||||
rect->x2 = playSize.w;
|
||||
rect->y2 = playSize.h;
|
||||
rect.w = playSize.w;
|
||||
rect.h = playSize.h;
|
||||
|
||||
jrect_displace(rect,
|
||||
window->rc->x2 - 3*jguiscale()
|
||||
- playSize.w - 1*jguiscale() - closeSize.w,
|
||||
window->rc->y1 + 3*jguiscale());
|
||||
rect.offset(window->rc->x2 - 3*jguiscale()
|
||||
- playSize.w - 1*jguiscale() - closeSize.w,
|
||||
window->rc->y1 + 3*jguiscale());
|
||||
|
||||
jwidget_set_rect(this, rect);
|
||||
jrect_free(rect);
|
||||
setBounds(rect);
|
||||
}
|
||||
|
||||
bool onProcessMessage(Message* msg) OVERRIDE
|
||||
|
@ -202,20 +202,6 @@ bool PaletteView::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
if (!m_isUpdatingColumns) {
|
||||
m_isUpdatingColumns = true;
|
||||
View* view = View::getView(this);
|
||||
if (view) {
|
||||
int columns =
|
||||
(view->getViewportBounds().w-this->child_spacing*2)
|
||||
/ (m_boxsize+this->child_spacing);
|
||||
setColumns(MID(1, columns, Palette::MaxColors));
|
||||
}
|
||||
m_isUpdatingColumns = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case kPaintMessage: {
|
||||
div_t d = div(Palette::MaxColors, m_columns);
|
||||
int cols = m_columns;
|
||||
@ -340,6 +326,23 @@ bool PaletteView::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void PaletteView::onResize(ui::ResizeEvent& ev)
|
||||
{
|
||||
if (!m_isUpdatingColumns) {
|
||||
m_isUpdatingColumns = true;
|
||||
View* view = View::getView(this);
|
||||
if (view) {
|
||||
int columns =
|
||||
(view->getViewportBounds().w-this->child_spacing*2)
|
||||
/ (m_boxsize+this->child_spacing);
|
||||
setColumns(MID(1, columns, Palette::MaxColors));
|
||||
}
|
||||
m_isUpdatingColumns = false;
|
||||
}
|
||||
|
||||
Widget::onResize(ev);
|
||||
}
|
||||
|
||||
void PaletteView::onPreferredSize(ui::PreferredSizeEvent& ev)
|
||||
{
|
||||
gfx::Size sz;
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) OVERRIDE;
|
||||
void onResize(ui::ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(ui::PreferredSizeEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
|
@ -472,30 +472,6 @@ bool StatusBar::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
jrect_copy(this->rc, &msg->setpos.rect);
|
||||
{
|
||||
JRect rc = jrect_new_copy(this->rc);
|
||||
rc->x1 = rc->x2 - m_notificationsBox->getPreferredSize().w;
|
||||
jwidget_set_rect(m_notificationsBox, rc);
|
||||
jrect_free(rc);
|
||||
}
|
||||
{
|
||||
JRect rc = jrect_new_copy(this->rc);
|
||||
rc->x2 -= jrect_w(rc)/4 + 4*jguiscale();
|
||||
jwidget_set_rect(m_commandsBox, rc);
|
||||
jrect_free(rc);
|
||||
}
|
||||
{
|
||||
JRect rc = jrect_new_copy(this->rc);
|
||||
Size reqSize = m_movePixelsBox->getPreferredSize();
|
||||
rc->x1 = rc->x2 - reqSize.w;
|
||||
rc->x2 -= this->border_width.r;
|
||||
jwidget_set_rect(m_movePixelsBox, rc);
|
||||
jrect_free(rc);
|
||||
}
|
||||
return true;
|
||||
|
||||
case kPaintMessage: {
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
ui::Color text_color = theme->getColor(ThemeColor::Text);
|
||||
@ -816,6 +792,25 @@ bool StatusBar::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void StatusBar::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
|
||||
Rect rc = ev.getBounds();
|
||||
rc.x = rc.x2() - m_notificationsBox->getPreferredSize().w;
|
||||
m_notificationsBox->setBounds(rc);
|
||||
|
||||
rc = ev.getBounds();
|
||||
rc.w -= rc.w/4 + 4*jguiscale();
|
||||
m_commandsBox->setBounds(rc);
|
||||
|
||||
rc = ev.getBounds();
|
||||
Size reqSize = m_movePixelsBox->getPreferredSize();
|
||||
rc.x = rc.x2() - reqSize.w;
|
||||
rc.w = reqSize.w;
|
||||
m_movePixelsBox->setBounds(rc);
|
||||
}
|
||||
|
||||
void StatusBar::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
int s = 4*jguiscale() + jwidget_get_text_height(this) + 4*jguiscale();
|
||||
|
@ -104,6 +104,7 @@ public:
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) OVERRIDE;
|
||||
void onResize(ui::ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(ui::PreferredSizeEvent& ev) OVERRIDE;
|
||||
|
||||
private:
|
||||
|
@ -244,11 +244,6 @@ bool Tabs::onProcessMessage(Message* msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
|
||||
case kResizeMessage:
|
||||
jrect_copy(this->rc, &msg->setpos.rect);
|
||||
setScrollX(m_scrollX);
|
||||
return true;
|
||||
|
||||
case kPaintMessage: {
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
|
||||
@ -430,6 +425,12 @@ bool Tabs::onProcessMessage(Message* msg)
|
||||
return Widget::onProcessMessage(msg);
|
||||
}
|
||||
|
||||
void Tabs::onResize(ResizeEvent& ev)
|
||||
{
|
||||
setBoundsQuietly(ev.getBounds());
|
||||
setScrollX(m_scrollX);
|
||||
}
|
||||
|
||||
void Tabs::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
||||
@ -607,19 +608,13 @@ void Tabs::setScrollX(int scroll_x)
|
||||
m_button_left->setEnabled(m_scrollX > 0);
|
||||
m_button_right->setEnabled(m_scrollX < max_x);
|
||||
|
||||
/* setup the position of each button */
|
||||
{
|
||||
JRect rect = jwidget_get_rect(this);
|
||||
JRect box = jrect_new(rect->x2-ARROW_W*2, rect->y1,
|
||||
rect->x2-ARROW_W, rect->y2-2);
|
||||
jwidget_set_rect(m_button_left, box);
|
||||
// Setup the position of each button
|
||||
gfx::Rect rect = getBounds();
|
||||
gfx::Rect box(rect.x2()-ARROW_W*2, rect.y, ARROW_W, rect.h-2);
|
||||
m_button_left->setBounds(box);
|
||||
|
||||
jrect_moveto(box, box->x1+ARROW_W, box->y1);
|
||||
jwidget_set_rect(m_button_right, box);
|
||||
|
||||
jrect_free(box);
|
||||
jrect_free(rect);
|
||||
}
|
||||
box.x += ARROW_W;
|
||||
m_button_right->setBounds(box);
|
||||
}
|
||||
// Remove buttons
|
||||
else if (HAS_ARROWS(this)) {
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) OVERRIDE;
|
||||
void onResize(ui::ResizeEvent& ev) OVERRIDE;
|
||||
void onPreferredSize(ui::PreferredSizeEvent& ev) OVERRIDE;
|
||||
void onInitTheme(ui::InitThemeEvent& ev) OVERRIDE;
|
||||
void onSetText() OVERRIDE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user