Skip to content

Commit

Permalink
for #270 - cleanup - delete unused macros and compatiblity code
Browse files Browse the repository at this point in the history
* working pretty well. More testing is needed.
  • Loading branch information
Cecil committed Mar 31, 2019
1 parent d0b69a1 commit 37adfae
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 227 deletions.
24 changes: 9 additions & 15 deletions shoes/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void shoes_canvas_free(shoes_canvas *canvas) {
RUBY_CRITICAL(free(canvas));
}

TypedData_Type_New(shoes_canvas);
const TypedData_Type_New(shoes_canvas);

VALUE shoes_canvas_alloc(VALUE klass) {
shoes_canvas *canvas = SHOE_ALLOC(shoes_canvas);
Expand Down Expand Up @@ -579,16 +579,13 @@ VALUE shoes_canvas_draw(VALUE self, VALUE c, VALUE actual) {
for (i = 0; i < RARRAY_LEN(self_t->contents); i++) {
shoes_canvas *c1;
VALUE ele = rb_ary_entry(self_t->contents, i);
if (RTYPEDDATA_P(ele)) {
/* This a nasty trick. The original blindly assumes that
* Data_Get_Struct can unwrap anything into a shoes_canvas.
* shoes_element would be a better choice but they both fail
* for TypedData objects
*/
c1 = (shoes_canvas *)RTYPEDDATA_DATA(ele);
} else {
TypedData_Get_Struct(ele, shoes_canvas, &shoes_canvas_type, c1);
}
/* This a nasty trick. The original blindly assumes that
* Data_Get_Struct can unwrap anything into a shoes_canvas.
* shoes_element would be a better choice but they both fail
* for TypedData objects
*/
c1 = (shoes_canvas *)RTYPEDDATA_DATA(ele);

if (shoes_canvas_inherits(ele, self_t)) {
if (!NIL_P(masks) && RTEST(actual)) {
if (rb_obj_class(ele) == cMask)
Expand Down Expand Up @@ -1342,10 +1339,7 @@ shoes_canvas_send_##event_name (VALUE self, VALUE key) \
{ \
long i; \
shoes_canvas *self_t; \
if (RTYPEDDATA_P(self)) \
self_t = (shoes_canvas *)RTYPEDDATA_DATA(self); \
else \
Data_Get_Struct(self, shoes_canvas, self_t); \
TypedData_Get_Struct(self, shoes_canvas, &shoes_canvas_type, self_t); \
if (ATTR(self_t->attr, hidden) != Qtrue) \
{ \
VALUE handler = ATTR(self_t->attr, event_name); \
Expand Down
40 changes: 9 additions & 31 deletions shoes/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "shoes/code.h"
#include <rsvg.h>

#define NEW_MACRO_CANVAS

struct _shoes_app;

typedef unsigned int PIXEL;
Expand Down Expand Up @@ -63,53 +61,34 @@ typedef struct {
unsigned char flags;
} shoes_place;

// TODO Transition to new macros. - clean up after transistion

#define SETUP_BASIC() \
shoes_basic *basic; \
if (RTYPEDDATA_P(self)) { \
basic = (shoes_basic *)RTYPEDDATA_DATA(self); \
} else { \
Data_Get_Struct(self, shoes_basic, basic); \
}
/*
* Note: SETUP_BASIC_T does not typecheck because we downcast all
* drawables (widgets, shapes,.. to shoes_basic struct
*/

#define SETUP_BASIC_T(ele) \
shoes_basic *basic; \
if (RTYPEDDATA_P(ele)) { \
basic = (shoes_basic *)RTYPEDDATA_DATA(ele); \
} else { \
Data_Get_Struct(ele, shoes_basic, basic); \
}
basic = (shoes_basic *)RTYPEDDATA_DATA(ele);

#define SETUP_SHAPE() \
shoes_canvas *canvas = NULL; \
VALUE c = shoes_find_canvas(self); \
if (RTYPEDDATA_P(c)) \
canvas = (shoes_canvas*)RTYPEDDATA_DATA(c); \
else \
canvas = (shoes_canvas*)rb_data_object_get(c); \
Data_Get_Struct(c, shoes_canvas, canvas)


/* TODO: delete after macro transition
#define SETUP_BASIC() \
shoes_basic *basic; \
Data_Get_Struct(self, shoes_basic, basic);
*/
TypedData_Get_Struct(c, shoes_canvas, &shoes_canvas_type, canvas);


#define COPY_PENS(attr1, attr2) \
if (NIL_P(ATTR(attr1, stroke))) ATTRSET(attr1, stroke, ATTR(attr2, stroke)); \
if (NIL_P(ATTR(attr1, fill))) ATTRSET(attr1, fill, ATTR(attr2, fill)); \
if (NIL_P(ATTR(attr1, strokewidth))) ATTRSET(attr1, strokewidth, ATTR(attr2, strokewidth)); \
if (NIL_P(ATTR(attr1, cap))) ATTRSET(attr1, cap, ATTR(attr2, cap));

#define DRAW(c, app, blk) \
{ \
rb_ary_push(app->nesting, c); \
blk; \
rb_ary_pop(app->nesting); \
}


#define ABSX(place) ((place).flags & FLAG_ABSX)
#define ABSY(place) ((place).flags & FLAG_ABSY)
#define POS(place) ((place).flags & FLAG_POSITION)
Expand Down Expand Up @@ -230,9 +209,8 @@ typedef struct {
VALUE layout_mgr; // we have a Layout object
} shoes_canvas;

#ifdef NEW_MACRO_CANVAS

extern const rb_data_type_t shoes_canvas_type;
#endif


VALUE shoes_app_main(int, VALUE *, VALUE);
Expand Down
2 changes: 1 addition & 1 deletion shoes/layout/emeus-constraint-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ emeus_constraint_layout_size_allocate (EmeusConstraintLayout *self,
int x,y,wid,hgt;
shoes_abstract *ab;
VALUE abv = (VALUE)gshoes_ele_get_element(child->widget);
Data_Get_Struct(abv, shoes_abstract, ab);
ab = (shoes_abstract *)RTYPEDDATA_DATA(abv);
//variable_set_value(top, ab->place.y);
//variable_set_value(left, ab->place.x);
//variable_set_value(width, ab->place.w);
Expand Down
57 changes: 12 additions & 45 deletions shoes/layout/shoes-vfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,10 @@ void shoes_vfl_add_ele(shoes_canvas *canvas, VALUE ele) {
Get_TypedStruct2(canvas->layout_mgr, shoes_layout, lay);
#else
shoes_layout *lay;
Data_Get_Struct(canvas->layout_mgr, shoes_layout, lay);
TypedData_Get_Struct(canvas->layout_mgr, shoes_layout, &shoes_layout_type, lay);
#endif
shoes_abstract *widget;
if (RTYPEDDATA_P(ele))
widget = (shoes_abstract*)RTYPEDDATA_DATA(ele);
else
widget = (shoes_abstract*)rb_data_object_get(ele);
// Data_Get_Struct(ele, shoes_abstract, widget); // TODO after macro transition
widget = (shoes_abstract*)RTYPEDDATA_DATA(ele);
VALUE name = ATTR(widget->attr, name);
if (NIL_P(name))
rb_raise(rb_eArgError, "please supply a name: ");
Expand Down Expand Up @@ -212,7 +208,7 @@ void shoes_vfl_add_contraints(shoes_layout *lay, shoes_canvas *canvas, VALUE arg
rb_raise(rb_eArgError, "arg must be a Shoes::Constraint object");
// convert to emeus and add to solver.
shoes_cassowary_constraint *cs;
Data_Get_Struct(arg, shoes_cassowary_constraint, cs);
TypedData_Get_Struct(arg, shoes_cassowary_constraint, &shoes_cassowary_constraint_type, cs);
EmeusConstraintLayout *layout = (EmeusConstraintLayout *)lay->root;
gpointer source, target;
EmeusConstraintAttribute source_attr, target_attr;
Expand Down Expand Up @@ -421,13 +417,9 @@ gboolean shoes_vfl_is_element(GshoesEle *p) {
return false;
shoes_abstract *ab;
gpointer gp = gshoes_ele_get_element(p);
if (RTYPEDDATA_P((VALUE)gp))
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
else
ab = (shoes_abstract*)rb_data_object_get((VALUE)gp);
// Data_Get_Struct((VALUE)gp, shoes_abstract, ab); // TODO after macro transition
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
shoes_canvas *canvas;
Data_Get_Struct(ab->parent, shoes_canvas, canvas);
TypedData_Get_Struct(ab->parent, shoes_canvas, &shoes_canvas_type, canvas);
if (NIL_P(canvas->layout_mgr))
return false;
return true;
Expand Down Expand Up @@ -486,11 +478,7 @@ VALUE shoes_vfl_hash_emeus(EmeusConstraint *c) {
val = Qnil;
else {
gpointer gp = gshoes_ele_get_element(p);
if (RTYPEDDATA_P((VALUE)gp))
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
else
ab = (shoes_abstract*)rb_data_object_get((VALUE)gp);
//Data_Get_Struct((VALUE)gp, shoes_abstract, ab); TODO: macro transition cleanup
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
VALUE obj = ATTR(ab->attr, name);
if (NIL_P(obj))
val = Qnil;
Expand All @@ -517,11 +505,7 @@ VALUE shoes_vfl_hash_emeus(EmeusConstraint *c) {
val = rb_str_new2("parent");
else {
gpointer gp = gshoes_ele_get_element(p);
if (RTYPEDDATA_P((VALUE)gp))
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
else
ab = (shoes_abstract*)rb_data_object_get((VALUE)gp);
// Data_Get_Struct((VALUE)gp, shoes_abstract, ab); //TODO macro transition
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
VALUE obj = ATTR(ab->attr, name);
if (NIL_P(obj))
val = Qnil;
Expand Down Expand Up @@ -565,19 +549,15 @@ VALUE shoes_vfl_wrap_emeus(EmeusConstraint *c) {

VALUE csobj = shoes_cassowary_constraint_alloc(cCassowaryconstraint);
shoes_cassowary_constraint *ct;
Data_Get_Struct(csobj, shoes_cassowary_constraint, ct);
TypedData_Get_Struct(csobj, shoes_cassowary_constraint, &shoes_cassowary_constraint_type, ct);
VALUE val;
gpointer p = emeus_constraint_get_target_object(c);
shoes_abstract *ab;
if (! GSHOES_IS_ELE(p))
val = Qnil;
else {
gpointer gp = gshoes_ele_get_element(p);
if (RTYPEDDATA_P((VALUE)gp))
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
else
ab = (shoes_abstract*)rb_data_object_get((VALUE)gp);
//Data_Get_Struct((VALUE)gp, shoes_abstract, ab);
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
VALUE obj = ATTR(ab->attr, name);
if (NIL_P(obj))
val = Qnil;
Expand All @@ -601,11 +581,7 @@ VALUE shoes_vfl_wrap_emeus(EmeusConstraint *c) {
val = rb_str_new2("parent");
else {
gpointer gp = gshoes_ele_get_element(p);
if (RTYPEDDATA_P((VALUE)gp))
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
else
ab = (shoes_abstract*)rb_data_object_get((VALUE)gp);
//Data_Get_Struct((VALUE)gp, shoes_abstract, ab);
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
VALUE obj = ATTR(ab->attr, name);
if (NIL_P(obj))
val = Qnil;
Expand Down Expand Up @@ -684,11 +660,7 @@ void shoes_vfl_change_pos(GshoesEle *gs, int x, int y, int width, int height)
{
shoes_abstract *ab;
gpointer gp = gshoes_ele_get_element(gs);
if (RTYPEDDATA_P((VALUE)gp))
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
else
ab = (shoes_abstract*)rb_data_object_get((VALUE)gp);
//Data_Get_Struct((VALUE)gp, shoes_abstract, ab); // TODO macro transition cleanup
ab = (shoes_abstract*)RTYPEDDATA_DATA((VALUE)gp);
//if (x != ab->place.x || y != ab->place.y) {
fprintf(stderr, "move from %d,%d to %d,%d\n", ab->place.x, ab->place.y, x, y);
fprintf(stderr, "size from %d, %d to %d %d\n", ab->place.w, ab->place.h, width, height);
Expand All @@ -704,17 +676,12 @@ void shoes_vfl_child_size(EmeusConstraintLayoutChild *self) {
return;
shoes_abstract *ab;
VALUE abv = (VALUE)gshoes_ele_get_element(self->widget);
if (RTYPEDDATA_P(abv))
ab = (shoes_abstract*)RTYPEDDATA_DATA(abv);
else
ab = (shoes_abstract*)rb_data_object_get(abv);
//Data_Get_Struct(abv, shoes_abstract, ab); // TODO: macro transition cleanup
ab = (shoes_abstract*)RTYPEDDATA_DATA(abv);
top = get_child_attribute (self, EMEUS_CONSTRAINT_ATTRIBUTE_TOP);
left = get_child_attribute (self, EMEUS_CONSTRAINT_ATTRIBUTE_LEFT);
width = get_child_attribute (self, EMEUS_CONSTRAINT_ATTRIBUTE_WIDTH);
height = get_child_attribute (self, EMEUS_CONSTRAINT_ATTRIBUTE_HEIGHT);

//Data_Get_Struct(abv, shoes_abstract, ab); // TODO: macro transition cleanup
//variable_set_value(top, ab->place.y);
//variable_set_value(left, ab->place.x);
variable_set_value(width, ab->place.w);
Expand Down
22 changes: 6 additions & 16 deletions shoes/ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,7 @@ void shoes_place_decide(shoes_place *place, VALUE c, VALUE attr, int dw, int dh,
oy = canvas->cy;
if ((REL_COORDS(rel) & REL_STICKY) && shoes_is_element(stuck)) {
shoes_element *element;
//Data_Get_Struct(stuck, shoes_element, element);
/* Temporary while fixing TypedData new API */
if (RTYPEDDATA_P(stuck))
element = (shoes_element*)RTYPEDDATA_DATA(stuck);
else
element = (shoes_element*)rb_data_object_get(stuck);
element = (shoes_element*)RTYPEDDATA_DATA(stuck);
ox = element->place.x;
oy = element->place.y;
}
Expand Down Expand Up @@ -555,14 +550,9 @@ void shoes_place_decide(shoes_place *place, VALUE c, VALUE attr, int dw, int dh,
// shoes_basic routines
//
VALUE shoes_basic_remove(VALUE self) {
//GET_STRUCT(basic, self_t);
/* Temporary while fixing TypedData new API */
shoes_basic* self_t;
if (RTYPEDDATA_P(self))
self_t = (shoes_basic*)RTYPEDDATA_DATA(self);
else
self_t = (shoes_basic*)rb_data_object_get(self);

self_t = (shoes_basic*)RTYPEDDATA_DATA(self);

shoes_canvas_remove_item(self_t->parent, self, 0, 0);
shoes_canvas_repaint_all(self_t->parent);
return self;
Expand All @@ -572,9 +562,9 @@ unsigned char shoes_is_element_p(VALUE ele, unsigned char any) {
void *dmark;
if (TYPE(ele) != T_DATA)
return 0;
dmark = RDATA(ele)->dmark;
//dmark = RDATA(ele)->dmark;
/* Temporary while fixing TypedData new API */
if (RTYPEDDATA_P(ele))
//if (RTYPEDDATA_P(ele))
dmark = RTYPEDDATA_TYPE(ele)->function.dmark;
return (dmark == shoes_canvas_mark || dmark == shoes_shape_mark ||
dmark == shoes_image_mark || dmark == shoes_effect_mark ||
Expand Down Expand Up @@ -728,7 +718,7 @@ VALUE shoes_font(VALUE self, VALUE path) {
//
// See ruby.h for the complete list of App methods which redirect to Canvas.
//
CANVAS_DEFS(FUNC_M);
CANVAS_DEFS(FUNC_T);

#define C(n, s) \
re##n = rb_eval_string(s); \
Expand Down
3 changes: 2 additions & 1 deletion shoes/ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ VALUE call_cfunc(HOOK func, VALUE recv, int len, int argc, VALUE *argv);
//
// Common methods - we need mixed set during transition.
//
#include "shoes/methods_mixed.h"
#include "shoes/methods_new.h"
//#include "shoes/methods_mixed.h"
//#include "shoes/methods_typed.h"
//#include "shoes/methods_old.h"

Expand Down
2 changes: 1 addition & 1 deletion shoes/types/effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ VALUE shoes_effect_new(ID name, VALUE attr, VALUE parent) {
}

VALUE shoes_effect_draw(VALUE self, VALUE c, VALUE actual) {
SETUP_DRAWING(shoes_effect, REL_TILE, canvas->width, canvas->height);
SETUP_DRAWING_T(shoes_effect, REL_TILE, canvas->width, canvas->height);

if (RTEST(actual) && self_t->filter != NULL)
self_t->filter(CCR(canvas), self_t->attr, &self_t->place);
Expand Down
1 change: 1 addition & 0 deletions shoes/types/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ static void shoes_image_draw_surface(cairo_t *cr, shoes_image *self_t, shoes_pla
shoes_undo_transformation(cr, self_t->st, place, 0);
self_t->place = *place;
}

// TODO useless macro - only used once. clean up after transition
#define SHOES_IMAGE_PLACE(type, imw, imh, surf) \
SETUP_DRAWING_T(shoes_##type, (REL_CANVAS | REL_SCALE), imw, imh); \
Expand Down
10 changes: 0 additions & 10 deletions shoes/types/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,4 @@ VALUE shoes_canvas_blur(int, VALUE *, VALUE);
VALUE shoes_canvas_glow(int, VALUE *, VALUE);
VALUE shoes_canvas_shadow(int, VALUE *, VALUE);

// todo: this macro only used in image.c and only once.
/*
#define SHOES_IMAGE_PLACE(type, imw, imh, surf) \
SETUP_DRAWING(shoes_##type, (REL_CANVAS | REL_SCALE), imw, imh); \
VALUE ck = rb_obj_class(c); \
if (RTEST(actual)) \
shoes_image_draw_surface(CCR(canvas), self_t, &place, surf, imw, imh); \
FINISH(); \
return self;
*/
#endif
7 changes: 1 addition & 6 deletions shoes/types/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,7 @@ void shoes_layout_add_ele(shoes_canvas *canvas, VALUE ele) {
if (! NIL_P(lay->delegate)) {
VALUE del = lay->delegate;
shoes_abstract *widget;
// TODO: in Typed world this won't work - fix after macro transition
//Data_Get_Struct(ele, shoes_abstract, widget);
if (RTYPEDDATA_P(ele))
widget = (shoes_abstract*)RTYPEDDATA_DATA(ele);
else
widget = (shoes_abstract*)rb_data_object_get(ele);
widget = (shoes_abstract*)RTYPEDDATA_DATA(ele);
rb_funcall(del, s_addw, 3, lay->canvas, ele, widget->attr);
return;
}
Expand Down
Loading

0 comments on commit 37adfae

Please sign in to comment.