Permalink
Browse files

Replace ui::jregion with gfx::Region class

This is an old TODO item, and it's the first step to finally
get rid of JRect and struct jrect.
  • Loading branch information...
dacap committed Jan 14, 2013
1 parent 6332b1a commit eacd0c7642bfbcc18cfd4e16d47757afda98fa1c
View
@@ -53,7 +53,6 @@
* About Signals/Slots: Add some field in slots to avoid disconnecting
them from dead signals.
* Replace JRect & jrect with gfx::Rect.
-* Create gfx::Region to replace JRegion & jregion.
* editors_ -> MultiEditors class widget
* convert all widgets to classes:
* match UI library design with Vaca library.
@@ -32,7 +32,6 @@
#include "raster/stock.h"
#include "ui/manager.h"
#include "ui/rect.h"
-#include "ui/region.h"
#include "ui/view.h"
#include "ui/widget.h"
#include "undo_transaction.h"
@@ -256,28 +255,21 @@ void FilterManagerImpl::applyToTarget()
void FilterManagerImpl::flush()
{
if (m_row >= 0) {
- JRegion reg1, reg2;
- struct jrect rect;
- Editor* editor = current_editor;
-
- reg1 = jregion_new(NULL, 0);
+ gfx::Rect rect;
+ Editor* editor = current_editor;
editor->editorToScreen(m_x+m_offset_x,
m_y+m_offset_y+m_row-1,
- &rect.x1, &rect.y1);
- rect.x2 = rect.x1 + (m_w << editor->getZoom());
- rect.y2 = rect.y1 + (1 << editor->getZoom());
-
- reg2 = jregion_new(&rect, 1);
- jregion_union(reg1, reg1, reg2);
- jregion_free(reg2);
+ &rect.x, &rect.y);
+ rect.w = (m_w << editor->getZoom());
+ rect.h = (1 << editor->getZoom());
- reg2 = jwidget_get_drawable_region(editor, JI_GDR_CUTTOPWINDOWS);
- jregion_intersect(reg1, reg1, reg2);
- jregion_free(reg2);
+ gfx::Region reg1(rect);
+ gfx::Region reg2;
+ editor->getDrawableRegion(reg2, Widget::kCutTopWindows);
+ reg1.createIntersection(reg1, reg2);
editor->invalidateRegion(reg1);
- jregion_free(reg1);
}
}
View
@@ -1383,10 +1383,10 @@ void AnimationEditor::setScroll(int x, int y, bool use_refresh_region)
int old_scroll_y = 0;
int max_scroll_x;
int max_scroll_y;
- JRegion region = NULL;
+ Region region;
if (use_refresh_region) {
- region = jwidget_get_drawable_region(this, JI_GDR_CUTTOPWINDOWS);
+ getDrawableRegion(region, kCutTopWindows);
old_scroll_x = m_scroll_x;
old_scroll_y = m_scroll_y;
}
@@ -1404,51 +1404,36 @@ void AnimationEditor::setScroll(int x, int y, bool use_refresh_region)
int new_scroll_y = m_scroll_y;
int dx = old_scroll_x - new_scroll_x;
int dy = old_scroll_y - new_scroll_y;
- JRegion reg1 = jregion_new(NULL, 0);
- JRegion reg2 = jregion_new(NULL, 0);
- JRect rect2 = jrect_new(0, 0, 0, 0);
+ Rect rect2;
+ Region reg1;
jmouse_hide();
// Scroll layers.
- jrect_replace(rect2,
- this->rc->x1,
- this->rc->y1 + HDRSIZE,
- this->rc->x1 + m_separator_x,
- this->rc->y2);
- jregion_reset(reg2, rect2);
- jregion_copy(reg1, region);
- jregion_intersect(reg1, reg1, reg2);
- this->scrollRegion(reg1, 0, dy);
+ rect2 = Rect(this->rc->x1,
+ this->rc->y1 + HDRSIZE,
+ m_separator_x,
+ this->rc->y2 - (this->rc->y1 + HDRSIZE));
+ reg1.createIntersection(region, Region(rect2));
+ scrollRegion(reg1, 0, dy);
// Scroll header-frame.
- jrect_replace(rect2,
- this->rc->x1 + m_separator_x + m_separator_w,
- this->rc->y1,
- this->rc->x2,
- this->rc->y1 + HDRSIZE);
- jregion_reset(reg2, rect2);
- jregion_copy(reg1, region);
- jregion_intersect(reg1, reg1, reg2);
- this->scrollRegion(reg1, dx, 0);
+ rect2 = Rect(this->rc->x1 + m_separator_x + m_separator_w,
+ this->rc->y1,
+ this->rc->x2 - (this->rc->x1 + m_separator_x + m_separator_w),
+ HDRSIZE);
+ reg1.createIntersection(region, Region(rect2));
+ scrollRegion(reg1, dx, 0);
// Scroll cels.
- jrect_replace(rect2,
- this->rc->x1 + m_separator_x + m_separator_w,
- this->rc->y1 + HDRSIZE,
- this->rc->x2,
- this->rc->y2);
- jregion_reset(reg2, rect2);
- jregion_copy(reg1, region);
- jregion_intersect(reg1, reg1, reg2);
- this->scrollRegion(reg1, dx, dy);
+ rect2 = Rect(this->rc->x1 + m_separator_x + m_separator_w,
+ this->rc->y1 + HDRSIZE,
+ this->rc->x2 - (this->rc->x1 + m_separator_x + m_separator_w),
+ this->rc->y2 - (this->rc->y1 + HDRSIZE));
+ reg1.createIntersection(region, Region(rect2));
+ scrollRegion(reg1, dx, dy);
jmouse_show();
-
- jregion_free(region);
- jregion_free(reg1);
- jregion_free(reg2);
- jrect_free(rect2);
}
}
View
@@ -577,7 +577,7 @@ Cursor* SkinTheme::getCursor(CursorType type)
}
}
-void SkinTheme::init_widget(Widget* widget)
+void SkinTheme::initWidget(Widget* widget)
{
#define BORDER(n) \
widget->border_width.l = (n); \
@@ -781,12 +781,12 @@ void SkinTheme::init_widget(Widget* widget)
}
}
-JRegion SkinTheme::get_window_mask(Widget* widget)
+void SkinTheme::getWindowMask(Widget* widget, Region& region)
{
- return jregion_new(widget->rc, 1);
+ region = widget->getBounds();
}
-void SkinTheme::map_decorative_widget(Widget* widget)
+void SkinTheme::mapDecorativeWidget(Widget* widget)
{
if (widget->getId() == kThemeCloseButtonId) {
Widget* window = widget->getParent();
View
@@ -119,9 +119,9 @@ class SkinTheme : public ui::Theme
void reload_fonts();
ui::Cursor* getCursor(ui::CursorType type);
- void init_widget(ui::Widget* widget);
- ui::JRegion get_window_mask(ui::Widget* widget);
- void map_decorative_widget(ui::Widget* widget);
+ void initWidget(ui::Widget* widget);
+ void getWindowMask(ui::Widget* widget, gfx::Region& region);
+ void mapDecorativeWidget(ui::Widget* widget);
void paintDesktop(ui::PaintEvent& ev);
void paintBox(ui::PaintEvent& ev);
View
@@ -36,7 +36,6 @@ add_library(ui-lib
preferred_size_event.cpp
property.cpp
rect.cpp
- region.cpp
scroll_bar.cpp
separator.cpp
slider.cpp
View
@@ -32,7 +32,6 @@
namespace ui {
struct jrect;
- struct jregion;
// Alignment.
#define JI_HORIZONTAL 0x0001
@@ -134,14 +133,9 @@ namespace ui {
JM_REGISTERED_MESSAGES
};
- // Flags for jwidget_get_drawable_region.
-#define JI_GDR_CUTTOPWINDOWS 1 // Cut areas where are windows on top.
-#define JI_GDR_USECHILDAREA 2 // Use areas where are children.
-
typedef unsigned int JID;
typedef struct jrect* JRect;
- typedef struct jregion* JRegion;
class GuiSystem {
public:
View
@@ -14,7 +14,6 @@
#include "ui/font.h"
#include "ui/intern.h"
#include "ui/rect.h"
-#include "ui/region.h"
#include "ui/system.h"
#include "ui/widget.h"
@@ -154,33 +153,33 @@ void jdraw_text(BITMAP* bmp, FONT* font, const char *s, int x, int y,
}
}
-void ji_move_region(JRegion region, int dx, int dy)
+void ji_move_region(const Region& region, int dx, int dy)
{
- int c, nrects = JI_REGION_NUM_RECTS(region);
- JRect rc;
+ size_t nrects = region.size();
// Blit directly screen to screen.
if (is_linear_bitmap(ji_screen) && nrects == 1) {
- rc = JI_REGION_RECTS(region);
- blit(ji_screen, ji_screen,
- rc->x1, rc->y1,
- rc->x1+dx, rc->y1+dy, jrect_w(rc), jrect_h(rc));
+ Rect rc = region[0];
+ blit(ji_screen, ji_screen, rc.x, rc.y, rc.x+dx, rc.y+dy, rc.w, rc.h);
}
// Blit saving areas and copy them.
else if (nrects > 1) {
std::vector<BITMAP*> images(nrects);
+ Region::const_iterator it, begin=region.begin(), end=region.end();
BITMAP* bmp;
+ int c;
- for (c=0, rc=JI_REGION_RECTS(region); c<nrects; ++c, ++rc) {
- bmp = create_bitmap(jrect_w(rc), jrect_h(rc));
- blit(ji_screen, bmp,
- rc->x1, rc->y1, 0, 0, bmp->w, bmp->h);
+ for (c=0, it=begin; it != end; ++it, ++c) {
+ const Rect& rc = *it;
+ bmp = create_bitmap(rc.w, rc.h);
+ blit(ji_screen, bmp, rc.x, rc.y, 0, 0, bmp->w, bmp->h);
images[c] = bmp;
}
- for (c=0, rc=JI_REGION_RECTS(region); c<nrects; ++c, ++rc) {
+ for (c=0, it=begin; it != end; ++it, ++c) {
+ const Rect& rc = *it;
bmp = images[c];
- blit(bmp, ji_screen, 0, 0, rc->x1+dx, rc->y1+dy, bmp->w, bmp->h);
+ blit(bmp, ji_screen, 0, 0, rc.x+dx, rc.y+dy, bmp->w, bmp->h);
destroy_bitmap(bmp);
}
}
View
@@ -8,6 +8,7 @@
#define UI_DRAW_H_INCLUDED
#include "gfx/rect.h"
+#include "gfx/region.h"
#include "ui/base.h"
#include "ui/color.h"
@@ -34,7 +35,7 @@ namespace ui {
void jdraw_inverted_sprite(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
- void ji_move_region(JRegion region, int dx, int dy);
+ void ji_move_region(const gfx::Region& region, int dx, int dy);
} // namespace ui
View
@@ -44,7 +44,6 @@
#include "ui/preferred_size_event.h"
#include "ui/property.h"
#include "ui/rect.h"
-#include "ui/region.h"
#include "ui/save_layout_event.h"
#include "ui/scroll_bar.h"
#include "ui/separator.h"
View
@@ -824,15 +824,13 @@ void Manager::_openWindow(Window* window)
void Manager::_closeWindow(Window* window, bool redraw_background)
{
Message* msg;
- JRegion reg1;
+ gfx::Region reg1;
if (!hasChild(window))
return;
if (redraw_background)
- reg1 = jwidget_get_region(window);
- else
- reg1 = NULL;
+ window->getRegion(reg1);
// Close all windows to this desktop
if (window->is_desktop()) {
@@ -841,9 +839,9 @@ void Manager::_closeWindow(Window* window, bool redraw_background)
if (child == window)
break;
else {
- JRegion reg2 = jwidget_get_region(window);
- jregion_union(reg1, reg1, reg2);
- jregion_free(reg2);
+ gfx::Region reg2;
+ window->getRegion(reg2);
+ reg1.createUnion(reg1, reg2);
_closeWindow(child, false);
}
@@ -872,10 +870,7 @@ void Manager::_closeWindow(Window* window, bool redraw_background)
removeChild(window);
// Redraw background.
- if (reg1) {
- invalidateRegion(reg1);
- jregion_free(reg1);
- }
+ invalidateRegion(reg1);
// Maybe the window is in the "new_windows" list.
WidgetsList::iterator it =
@@ -1115,14 +1110,11 @@ void Manager::pumpQueue()
}
}
-void Manager::invalidateDisplayRegion(const JRegion region)
+void Manager::invalidateDisplayRegion(const gfx::Region& region)
{
- JRegion reg1 = jregion_new(NULL, 0);
- JRegion reg2 = jregion_new(this->rc, 0);
- JRegion reg3;
-
- // TODO intersect with jwidget_get_drawable_region()???
- jregion_intersect(reg1, region, reg2);
+ // TODO intersect with getDrawableRegion()???
+ gfx::Region reg1;
+ reg1.createIntersection(region, gfx::Region(getBounds()));
// Redraw windows from top to background.
bool withDesktop = false;
@@ -1139,19 +1131,15 @@ void Manager::invalidateDisplayRegion(const JRegion region)
}
// Clip this window area for the next window.
- reg3 = jwidget_get_region(window);
- jregion_copy(reg2, reg1);
- jregion_subtract(reg1, reg2, reg3);
- jregion_free(reg3);
+ gfx::Region reg3;
+ window->getRegion(reg3);
+ reg1.createSubtraction(reg1, reg3);
}
// Invalidate areas outside windows (only when there are not a
// desktop window).
if (!withDesktop)
Widget::invalidateRegion(reg1);
-
- jregion_free(reg1);
- jregion_free(reg2);
}
LayoutIO* Manager::getLayoutIO()
View
@@ -64,7 +64,7 @@ namespace ui {
void removeMessageFilter(int message, Widget* widget);
void removeMessageFilterFor(Widget* widget);
- void invalidateDisplayRegion(const JRegion region);
+ void invalidateDisplayRegion(const gfx::Region& region);
LayoutIO* getLayoutIO();
View
@@ -679,11 +679,8 @@ void MenuBox::set_position(JRect rect)
{
jrect_copy(this->rc, rect);
- if (Menu* menu = getMenu()) {
- JRect cpos = jwidget_get_child_rect(this);
- jwidget_set_rect(menu, cpos);
- jrect_free(cpos);
- }
+ if (Menu* menu = getMenu())
+ menu->setBounds(getChildrenBounds());
}
bool MenuItem::onProcessMessage(Message* msg)
Oops, something went wrong.

0 comments on commit eacd0c7

Please sign in to comment.