Skip to content

Commit eacd0c7

Browse files
committed
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.
1 parent 6332b1a commit eacd0c7

32 files changed

+315
-3221
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
* About Signals/Slots: Add some field in slots to avoid disconnecting
5454
them from dead signals.
5555
* Replace JRect & jrect with gfx::Rect.
56-
* Create gfx::Region to replace JRegion & jregion.
5756
* editors_ -> MultiEditors class widget
5857
* convert all widgets to classes:
5958
* match UI library design with Vaca library.

src/commands/filters/filter_manager_impl.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "raster/stock.h"
3333
#include "ui/manager.h"
3434
#include "ui/rect.h"
35-
#include "ui/region.h"
3635
#include "ui/view.h"
3736
#include "ui/widget.h"
3837
#include "undo_transaction.h"
@@ -256,28 +255,21 @@ void FilterManagerImpl::applyToTarget()
256255
void FilterManagerImpl::flush()
257256
{
258257
if (m_row >= 0) {
259-
JRegion reg1, reg2;
260-
struct jrect rect;
261-
Editor* editor = current_editor;
262-
263-
reg1 = jregion_new(NULL, 0);
258+
gfx::Rect rect;
264259

260+
Editor* editor = current_editor;
265261
editor->editorToScreen(m_x+m_offset_x,
266262
m_y+m_offset_y+m_row-1,
267-
&rect.x1, &rect.y1);
268-
rect.x2 = rect.x1 + (m_w << editor->getZoom());
269-
rect.y2 = rect.y1 + (1 << editor->getZoom());
270-
271-
reg2 = jregion_new(&rect, 1);
272-
jregion_union(reg1, reg1, reg2);
273-
jregion_free(reg2);
263+
&rect.x, &rect.y);
264+
rect.w = (m_w << editor->getZoom());
265+
rect.h = (1 << editor->getZoom());
274266

275-
reg2 = jwidget_get_drawable_region(editor, JI_GDR_CUTTOPWINDOWS);
276-
jregion_intersect(reg1, reg1, reg2);
277-
jregion_free(reg2);
267+
gfx::Region reg1(rect);
268+
gfx::Region reg2;
269+
editor->getDrawableRegion(reg2, Widget::kCutTopWindows);
270+
reg1.createIntersection(reg1, reg2);
278271

279272
editor->invalidateRegion(reg1);
280-
jregion_free(reg1);
281273
}
282274
}
283275

src/dialogs/aniedit.cpp

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,10 @@ void AnimationEditor::setScroll(int x, int y, bool use_refresh_region)
13831383
int old_scroll_y = 0;
13841384
int max_scroll_x;
13851385
int max_scroll_y;
1386-
JRegion region = NULL;
1386+
Region region;
13871387

13881388
if (use_refresh_region) {
1389-
region = jwidget_get_drawable_region(this, JI_GDR_CUTTOPWINDOWS);
1389+
getDrawableRegion(region, kCutTopWindows);
13901390
old_scroll_x = m_scroll_x;
13911391
old_scroll_y = m_scroll_y;
13921392
}
@@ -1404,51 +1404,36 @@ void AnimationEditor::setScroll(int x, int y, bool use_refresh_region)
14041404
int new_scroll_y = m_scroll_y;
14051405
int dx = old_scroll_x - new_scroll_x;
14061406
int dy = old_scroll_y - new_scroll_y;
1407-
JRegion reg1 = jregion_new(NULL, 0);
1408-
JRegion reg2 = jregion_new(NULL, 0);
1409-
JRect rect2 = jrect_new(0, 0, 0, 0);
1407+
Rect rect2;
1408+
Region reg1;
14101409

14111410
jmouse_hide();
14121411

14131412
// Scroll layers.
1414-
jrect_replace(rect2,
1415-
this->rc->x1,
1416-
this->rc->y1 + HDRSIZE,
1417-
this->rc->x1 + m_separator_x,
1418-
this->rc->y2);
1419-
jregion_reset(reg2, rect2);
1420-
jregion_copy(reg1, region);
1421-
jregion_intersect(reg1, reg1, reg2);
1422-
this->scrollRegion(reg1, 0, dy);
1413+
rect2 = Rect(this->rc->x1,
1414+
this->rc->y1 + HDRSIZE,
1415+
m_separator_x,
1416+
this->rc->y2 - (this->rc->y1 + HDRSIZE));
1417+
reg1.createIntersection(region, Region(rect2));
1418+
scrollRegion(reg1, 0, dy);
14231419

14241420
// Scroll header-frame.
1425-
jrect_replace(rect2,
1426-
this->rc->x1 + m_separator_x + m_separator_w,
1427-
this->rc->y1,
1428-
this->rc->x2,
1429-
this->rc->y1 + HDRSIZE);
1430-
jregion_reset(reg2, rect2);
1431-
jregion_copy(reg1, region);
1432-
jregion_intersect(reg1, reg1, reg2);
1433-
this->scrollRegion(reg1, dx, 0);
1421+
rect2 = Rect(this->rc->x1 + m_separator_x + m_separator_w,
1422+
this->rc->y1,
1423+
this->rc->x2 - (this->rc->x1 + m_separator_x + m_separator_w),
1424+
HDRSIZE);
1425+
reg1.createIntersection(region, Region(rect2));
1426+
scrollRegion(reg1, dx, 0);
14341427

14351428
// Scroll cels.
1436-
jrect_replace(rect2,
1437-
this->rc->x1 + m_separator_x + m_separator_w,
1438-
this->rc->y1 + HDRSIZE,
1439-
this->rc->x2,
1440-
this->rc->y2);
1441-
jregion_reset(reg2, rect2);
1442-
jregion_copy(reg1, region);
1443-
jregion_intersect(reg1, reg1, reg2);
1444-
this->scrollRegion(reg1, dx, dy);
1429+
rect2 = Rect(this->rc->x1 + m_separator_x + m_separator_w,
1430+
this->rc->y1 + HDRSIZE,
1431+
this->rc->x2 - (this->rc->x1 + m_separator_x + m_separator_w),
1432+
this->rc->y2 - (this->rc->y1 + HDRSIZE));
1433+
reg1.createIntersection(region, Region(rect2));
1434+
scrollRegion(reg1, dx, dy);
14451435

14461436
jmouse_show();
1447-
1448-
jregion_free(region);
1449-
jregion_free(reg1);
1450-
jregion_free(reg2);
1451-
jrect_free(rect2);
14521437
}
14531438
}
14541439

src/skin/skin_theme.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ Cursor* SkinTheme::getCursor(CursorType type)
577577
}
578578
}
579579

580-
void SkinTheme::init_widget(Widget* widget)
580+
void SkinTheme::initWidget(Widget* widget)
581581
{
582582
#define BORDER(n) \
583583
widget->border_width.l = (n); \
@@ -781,12 +781,12 @@ void SkinTheme::init_widget(Widget* widget)
781781
}
782782
}
783783

784-
JRegion SkinTheme::get_window_mask(Widget* widget)
784+
void SkinTheme::getWindowMask(Widget* widget, Region& region)
785785
{
786-
return jregion_new(widget->rc, 1);
786+
region = widget->getBounds();
787787
}
788788

789-
void SkinTheme::map_decorative_widget(Widget* widget)
789+
void SkinTheme::mapDecorativeWidget(Widget* widget)
790790
{
791791
if (widget->getId() == kThemeCloseButtonId) {
792792
Widget* window = widget->getParent();

src/skin/skin_theme.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ class SkinTheme : public ui::Theme
119119
void reload_fonts();
120120

121121
ui::Cursor* getCursor(ui::CursorType type);
122-
void init_widget(ui::Widget* widget);
123-
ui::JRegion get_window_mask(ui::Widget* widget);
124-
void map_decorative_widget(ui::Widget* widget);
122+
void initWidget(ui::Widget* widget);
123+
void getWindowMask(ui::Widget* widget, gfx::Region& region);
124+
void mapDecorativeWidget(ui::Widget* widget);
125125

126126
void paintDesktop(ui::PaintEvent& ev);
127127
void paintBox(ui::PaintEvent& ev);

src/ui/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ add_library(ui-lib
3636
preferred_size_event.cpp
3737
property.cpp
3838
rect.cpp
39-
region.cpp
4039
scroll_bar.cpp
4140
separator.cpp
4241
slider.cpp

src/ui/base.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
namespace ui {
3333

3434
struct jrect;
35-
struct jregion;
3635

3736
// Alignment.
3837
#define JI_HORIZONTAL 0x0001
@@ -134,14 +133,9 @@ namespace ui {
134133
JM_REGISTERED_MESSAGES
135134
};
136135

137-
// Flags for jwidget_get_drawable_region.
138-
#define JI_GDR_CUTTOPWINDOWS 1 // Cut areas where are windows on top.
139-
#define JI_GDR_USECHILDAREA 2 // Use areas where are children.
140-
141136
typedef unsigned int JID;
142137

143138
typedef struct jrect* JRect;
144-
typedef struct jregion* JRegion;
145139

146140
class GuiSystem {
147141
public:

src/ui/draw.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "ui/font.h"
1515
#include "ui/intern.h"
1616
#include "ui/rect.h"
17-
#include "ui/region.h"
1817
#include "ui/system.h"
1918
#include "ui/widget.h"
2019

@@ -154,33 +153,33 @@ void jdraw_text(BITMAP* bmp, FONT* font, const char *s, int x, int y,
154153
}
155154
}
156155

157-
void ji_move_region(JRegion region, int dx, int dy)
156+
void ji_move_region(const Region& region, int dx, int dy)
158157
{
159-
int c, nrects = JI_REGION_NUM_RECTS(region);
160-
JRect rc;
158+
size_t nrects = region.size();
161159

162160
// Blit directly screen to screen.
163161
if (is_linear_bitmap(ji_screen) && nrects == 1) {
164-
rc = JI_REGION_RECTS(region);
165-
blit(ji_screen, ji_screen,
166-
rc->x1, rc->y1,
167-
rc->x1+dx, rc->y1+dy, jrect_w(rc), jrect_h(rc));
162+
Rect rc = region[0];
163+
blit(ji_screen, ji_screen, rc.x, rc.y, rc.x+dx, rc.y+dy, rc.w, rc.h);
168164
}
169165
// Blit saving areas and copy them.
170166
else if (nrects > 1) {
171167
std::vector<BITMAP*> images(nrects);
168+
Region::const_iterator it, begin=region.begin(), end=region.end();
172169
BITMAP* bmp;
170+
int c;
173171

174-
for (c=0, rc=JI_REGION_RECTS(region); c<nrects; ++c, ++rc) {
175-
bmp = create_bitmap(jrect_w(rc), jrect_h(rc));
176-
blit(ji_screen, bmp,
177-
rc->x1, rc->y1, 0, 0, bmp->w, bmp->h);
172+
for (c=0, it=begin; it != end; ++it, ++c) {
173+
const Rect& rc = *it;
174+
bmp = create_bitmap(rc.w, rc.h);
175+
blit(ji_screen, bmp, rc.x, rc.y, 0, 0, bmp->w, bmp->h);
178176
images[c] = bmp;
179177
}
180178

181-
for (c=0, rc=JI_REGION_RECTS(region); c<nrects; ++c, ++rc) {
179+
for (c=0, it=begin; it != end; ++it, ++c) {
180+
const Rect& rc = *it;
182181
bmp = images[c];
183-
blit(bmp, ji_screen, 0, 0, rc->x1+dx, rc->y1+dy, bmp->w, bmp->h);
182+
blit(bmp, ji_screen, 0, 0, rc.x+dx, rc.y+dy, bmp->w, bmp->h);
184183
destroy_bitmap(bmp);
185184
}
186185
}

src/ui/draw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define UI_DRAW_H_INCLUDED
99

1010
#include "gfx/rect.h"
11+
#include "gfx/region.h"
1112
#include "ui/base.h"
1213
#include "ui/color.h"
1314

@@ -34,7 +35,7 @@ namespace ui {
3435

3536
void jdraw_inverted_sprite(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y);
3637

37-
void ji_move_region(JRegion region, int dx, int dy);
38+
void ji_move_region(const gfx::Region& region, int dx, int dy);
3839

3940
} // namespace ui
4041

src/ui/gui.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "ui/preferred_size_event.h"
4545
#include "ui/property.h"
4646
#include "ui/rect.h"
47-
#include "ui/region.h"
4847
#include "ui/save_layout_event.h"
4948
#include "ui/scroll_bar.h"
5049
#include "ui/separator.h"

src/ui/manager.cpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -824,15 +824,13 @@ void Manager::_openWindow(Window* window)
824824
void Manager::_closeWindow(Window* window, bool redraw_background)
825825
{
826826
Message* msg;
827-
JRegion reg1;
827+
gfx::Region reg1;
828828

829829
if (!hasChild(window))
830830
return;
831831

832832
if (redraw_background)
833-
reg1 = jwidget_get_region(window);
834-
else
835-
reg1 = NULL;
833+
window->getRegion(reg1);
836834

837835
// Close all windows to this desktop
838836
if (window->is_desktop()) {
@@ -841,9 +839,9 @@ void Manager::_closeWindow(Window* window, bool redraw_background)
841839
if (child == window)
842840
break;
843841
else {
844-
JRegion reg2 = jwidget_get_region(window);
845-
jregion_union(reg1, reg1, reg2);
846-
jregion_free(reg2);
842+
gfx::Region reg2;
843+
window->getRegion(reg2);
844+
reg1.createUnion(reg1, reg2);
847845

848846
_closeWindow(child, false);
849847
}
@@ -872,10 +870,7 @@ void Manager::_closeWindow(Window* window, bool redraw_background)
872870
removeChild(window);
873871

874872
// Redraw background.
875-
if (reg1) {
876-
invalidateRegion(reg1);
877-
jregion_free(reg1);
878-
}
873+
invalidateRegion(reg1);
879874

880875
// Maybe the window is in the "new_windows" list.
881876
WidgetsList::iterator it =
@@ -1115,14 +1110,11 @@ void Manager::pumpQueue()
11151110
}
11161111
}
11171112

1118-
void Manager::invalidateDisplayRegion(const JRegion region)
1113+
void Manager::invalidateDisplayRegion(const gfx::Region& region)
11191114
{
1120-
JRegion reg1 = jregion_new(NULL, 0);
1121-
JRegion reg2 = jregion_new(this->rc, 0);
1122-
JRegion reg3;
1123-
1124-
// TODO intersect with jwidget_get_drawable_region()???
1125-
jregion_intersect(reg1, region, reg2);
1115+
// TODO intersect with getDrawableRegion()???
1116+
gfx::Region reg1;
1117+
reg1.createIntersection(region, gfx::Region(getBounds()));
11261118

11271119
// Redraw windows from top to background.
11281120
bool withDesktop = false;
@@ -1139,19 +1131,15 @@ void Manager::invalidateDisplayRegion(const JRegion region)
11391131
}
11401132

11411133
// Clip this window area for the next window.
1142-
reg3 = jwidget_get_region(window);
1143-
jregion_copy(reg2, reg1);
1144-
jregion_subtract(reg1, reg2, reg3);
1145-
jregion_free(reg3);
1134+
gfx::Region reg3;
1135+
window->getRegion(reg3);
1136+
reg1.createSubtraction(reg1, reg3);
11461137
}
11471138

11481139
// Invalidate areas outside windows (only when there are not a
11491140
// desktop window).
11501141
if (!withDesktop)
11511142
Widget::invalidateRegion(reg1);
1152-
1153-
jregion_free(reg1);
1154-
jregion_free(reg2);
11551143
}
11561144

11571145
LayoutIO* Manager::getLayoutIO()

src/ui/manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace ui {
6464
void removeMessageFilter(int message, Widget* widget);
6565
void removeMessageFilterFor(Widget* widget);
6666

67-
void invalidateDisplayRegion(const JRegion region);
67+
void invalidateDisplayRegion(const gfx::Region& region);
6868

6969
LayoutIO* getLayoutIO();
7070

src/ui/menu.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,8 @@ void MenuBox::set_position(JRect rect)
679679
{
680680
jrect_copy(this->rc, rect);
681681

682-
if (Menu* menu = getMenu()) {
683-
JRect cpos = jwidget_get_child_rect(this);
684-
jwidget_set_rect(menu, cpos);
685-
jrect_free(cpos);
686-
}
682+
if (Menu* menu = getMenu())
683+
menu->setBounds(getChildrenBounds());
687684
}
688685

689686
bool MenuItem::onProcessMessage(Message* msg)

0 commit comments

Comments
 (0)