Commit 82ec6b1d authored by Mathieu L Bouchard's avatar Mathieu L Bouchard
Browse files

big refactoring #9 : merging of horizontal/vertical classes is completed

parent 18cca2c5
......@@ -14,22 +14,11 @@
#include "m_pd.h"
#include "g_canvas.h"
#include "m_imp.h"
#include "t_tk.h"
#include "g_all_guis.h"
#include <math.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
t_symbol *s_empty;
/*------------------ global varaibles -------------------------*/
int iemgui_color_hex[]=
{
16579836, 10526880, 4210752, 16572640, 16572608,
......@@ -40,9 +29,6 @@ int iemgui_color_hex[]=
7874580, 2641940, 17488, 5256, 5767248
};
/*------------------ global functions -------------------------*/
int iemgui_clip_size(int size)
{
if(size < IEM_GUI_MINSIZE)
......@@ -165,8 +151,7 @@ static void iemgui_init_sym2dollararg(t_iemgui *iemgui, t_symbol **symp,
}
}
/* get the unexpanded versions of the symbols; initialize them if
necessary. */
/* get the unexpanded versions of the symbols; initialize them if necessary. */
void iemgui_all_sym2dollararg(t_iemgui *iemgui, t_symbol **srlsym)
{
iemgui_init_sym2dollararg(iemgui, &iemgui->x_snd_unexpanded,
......@@ -180,51 +165,30 @@ void iemgui_all_sym2dollararg(t_iemgui *iemgui, t_symbol **srlsym)
srlsym[2] = iemgui->x_lab_unexpanded;
}
static int col2save(int col) {
return -1-(((0xfc0000 & col) >> 6)|((0xfc00 & col) >> 4)|((0xfc & col) >> 2));
}
void iemgui_all_col2save(t_iemgui *iemgui, int *bflcol)
{
bflcol[0] = -1 - (((0xfc0000 & iemgui->x_bcol) >> 6)|
((0xfc00 & iemgui->x_bcol) >> 4)|((0xfc & iemgui->x_bcol) >> 2));
bflcol[1] = -1 - (((0xfc0000 & iemgui->x_fcol) >> 6)|
((0xfc00 & iemgui->x_fcol) >> 4)|((0xfc & iemgui->x_fcol) >> 2));
bflcol[2] = -1 - (((0xfc0000 & iemgui->x_lcol) >> 6)|
((0xfc00 & iemgui->x_lcol) >> 4)|((0xfc & iemgui->x_lcol) >> 2));
bflcol[0] = col2save(iemgui->x_bcol);
bflcol[1] = col2save(iemgui->x_fcol);
bflcol[2] = col2save(iemgui->x_lcol);
}
void iemgui_all_colfromload(t_iemgui *iemgui, int *bflcol)
{
if(bflcol[0] < 0)
{
bflcol[0] = -1 - bflcol[0];
iemgui->x_bcol = ((bflcol[0] & 0x3f000) << 6)|((bflcol[0] & 0xfc0) << 4)|
((bflcol[0] & 0x3f) << 2);
}
else
{
bflcol[0] = iemgui_modulo_color(bflcol[0]);
iemgui->x_bcol = iemgui_color_hex[bflcol[0]];
}
if(bflcol[1] < 0)
{
bflcol[1] = -1 - bflcol[1];
iemgui->x_fcol = ((bflcol[1] & 0x3f000) << 6)|((bflcol[1] & 0xfc0) << 4)|
((bflcol[1] & 0x3f) << 2);
}
else
{
bflcol[1] = iemgui_modulo_color(bflcol[1]);
iemgui->x_fcol = iemgui_color_hex[bflcol[1]];
}
if(bflcol[2] < 0)
static int colfromload(int col) {
if(col)
{
bflcol[2] = -1 - bflcol[2];
iemgui->x_lcol = ((bflcol[2] & 0x3f000) << 6)|((bflcol[2] & 0xfc0) << 4)|
((bflcol[2] & 0x3f) << 2);
col = -1-col;
return ((col & 0x3f000) << 6)|((col & 0xfc0) << 4)|((col & 0x3f) << 2);
}
else
{
bflcol[2] = iemgui_modulo_color(bflcol[2]);
iemgui->x_lcol = iemgui_color_hex[bflcol[2]];
}
return iemgui_color_hex[iemgui_modulo_color(col)];
}
void iemgui_all_colfromload(t_iemgui *iemgui, int *bflcol)
{
iemgui->x_bcol = colfromload(bflcol[0]);
iemgui->x_fcol = colfromload(bflcol[1]);
iemgui->x_lcol = colfromload(bflcol[2]);
}
static int iemgui_compatible_col(int i)
......@@ -370,30 +334,15 @@ void iemgui_label_getrect(t_iemgui x_gui, t_glist *x,
if (x->gl_isgraph && !glist_istoplevel(x))
{
//fprintf(stderr,"iemgui_label_getrect\n");
if (x_gui.x_lab!=s_empty)
{
switch(x_gui.x_font_style)
{
case 1:
width_multiplier = 0.83333;
break;
case 2:
width_multiplier = 0.735;
break;
default:
width_multiplier = 1.0;
break;
}
if (x_gui.x_fontsize % 2 == 0)
{
actual_fontsize = x_gui.x_fontsize;
}
else
{
actual_fontsize = x_gui.x_fontsize;
case 1: width_multiplier = 0.83333; break;
case 2: width_multiplier = 0.735; break;
default: width_multiplier = 1.0; break;
}
actual_fontsize = x_gui.x_fontsize;
actual_height = actual_fontsize;
//exceptions
if (x_gui.x_font_style == 0 &&
......@@ -577,7 +526,7 @@ void iemgui_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy)
t_iemgui *x = (t_iemgui *)z;
x->x_obj.te_xpix += dx;
x->x_obj.te_ypix += dy;
//(*x->x_gui.x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_MOVE);
//x->x_gui.x_draw((void *)z, glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(glist), (t_text *)z);
}
......@@ -587,7 +536,7 @@ void iemgui_select(t_gobj *z, t_glist *glist, int selected)
t_iemgui *x = (t_iemgui *)z;
x->x_selected = selected;
(*x->x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_SELECT);
x->x_draw((void *)z, glist, IEM_GUI_DRAW_MODE_SELECT);
}
void iemgui_delete(t_gobj *z, t_glist *glist)
......@@ -602,15 +551,14 @@ void iemgui_vis(t_gobj *z, t_glist *glist, int vis)
{
if (vis)
{
(*x->x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_NEW);
x->x_vis = 1;
x->x_draw((void *)z, glist, IEM_GUI_DRAW_MODE_NEW);
}
else
{
(*x->x_draw)((void *)z, glist, IEM_GUI_DRAW_MODE_ERASE);
x->x_draw((void *)z, glist, IEM_GUI_DRAW_MODE_ERASE);
sys_unqueuegui(z);
x->x_vis = 0;
}
x->x_vis = vis;
}
}
......@@ -771,12 +719,22 @@ void scalehandle_bind(t_scalehandle *h) {
// in 18 cases only, because canvas does not fit the pattern below.
// canvas has no label handle and has a motion handle
// but in the case of canvas, the "iemgui" tag is added (it wasn't the case originally)
void scalehandle_draw_select(t_scalehandle *h, t_glist *canvas, int px, int py,
const char *nlet_tag) {
void scalehandle_draw_select(t_scalehandle *h, t_glist *canvas, int px, int py, const char *nlet_tag) {
char tags[128]; // BNG may need up to 100 chars in 64-bit mode, for example
t_text *x = (t_text *)h->h_master;
t_iemgui *x = (t_iemgui *)h->h_master;
//if (!nlet_tag) nlet_tag = iem_get_tag(canvas, (t_iemgui *)x);
//int px,py;
//t_class *c = pd_class((t_pd *)x);
//if (h->h_scale) {
// int x1,y1,x2,y2;
// c->c_wb->w_getrectfn((t_gobj *)x,canvas,&x1,&y1,&x2,&y2);
// px=x2-x1; py=y2-y1;
//} else if (c==canvas_class) {
//} else {
// px=x->x_ldx; py=x->x_ldy;
//}
const char *cursor = h->h_scale ? "bottom_right_corner" : "crosshair";
int sx = h->h_scale ? SCALEHANDLE_WIDTH : LABELHANDLE_WIDTH;
int sy = h->h_scale ? SCALEHANDLE_HEIGHT : LABELHANDLE_HEIGHT;
......@@ -785,8 +743,8 @@ const char *nlet_tag) {
if (h->h_vis) scalehandle_draw_erase(h,canvas);
// sys_vgui("canvas %s -width %d -height %d -bg $pd_colors(selection) -bd 0 "
sys_vgui("canvas %s -width %d -height %d -bg #0080ff -bd 0 "
sys_vgui("canvas %s -width %d -height %d -bg $pd_colors(selection) -bd 0 "
// sys_vgui("canvas %s -width %d -height %d -bg #0080ff -bd 0 "
"-cursor %s\n", h->h_pathname, sx, sy, cursor);
// there was a %lxBNG tag (or similar) in every scalehandle,
// but it didn't seem to be used —mathieu
......@@ -799,19 +757,20 @@ const char *nlet_tag) {
(long)x,pd_class((t_pd *)x)==canvas_class?"MOVE":"LABELH",nlet_tag);
}
sys_vgui(".x%x.c create window %d %d -anchor nw -width %d -height %d "
"-window %s -tags {%s}\n", canvas, x->te_xpix+px-sx, x->te_ypix+py-sy,
"-window %s -tags {%s}\n", canvas, x->x_obj.te_xpix+px-sx, x->x_obj.te_ypix+py-sy,
sx, sy, h->h_pathname, tags);
scalehandle_bind(h);
h->h_vis = 1;
}
void scalehandle_draw_select2(t_iemgui *x, t_glist *canvas, int sx, int sy) {
void scalehandle_draw_select2(t_iemgui *x, t_glist *canvas) {
char *nlet_tag = iem_get_tag(canvas, (t_iemgui *)x);
scalehandle_draw_select(x->x_handle,canvas,sx,sy,nlet_tag);
t_class *c = pd_class((t_pd *)x);
int x1,y1,x2,y2;
c->c_wb->w_getrectfn((t_gobj *)x,canvas,&x1,&y1,&x2,&y2);
scalehandle_draw_select(x->x_handle,canvas,x2-x1-1,y2-y1-1,nlet_tag);
if (x->x_lab!=s_empty)
{
scalehandle_draw_select(x->x_lhandle,canvas,x->x_ldx,x->x_ldy,nlet_tag);
}
}
void scalehandle_draw_erase(t_scalehandle *h, t_glist *canvas) {
......@@ -1125,6 +1084,8 @@ const char *iemgui_font(t_iemgui *x) {
return "invalid-font";
}
void iemgui_init(t_iemgui *x, t_floatarg f) {x->x_loadinit = f!=0.0;}
void iemgui_class_addmethods(t_class *c) {
class_addmethod(c, (t_method)iemgui_delta,
gensym("delta"), A_GIMME, 0);
......
......@@ -292,7 +292,7 @@ EXTERN void canvas_apply_setundo(t_canvas *x, t_gobj *y);
// scalehandle code, as refactored by Mathieu
EXTERN void scalehandle_bind(t_scalehandle *h);
EXTERN void scalehandle_draw_select(t_scalehandle *h, t_glist *canvas, int px, int py, const char *nlet_tag);
EXTERN void scalehandle_draw_select2(t_iemgui *x, t_glist *canvas, int sx, int sy);
EXTERN void scalehandle_draw_select2(t_iemgui *x, t_glist *canvas);
EXTERN void scalehandle_draw_erase(t_scalehandle *h, t_glist *canvas);
EXTERN void scalehandle_draw_erase2(t_iemgui *x, t_glist *canvas);
EXTERN void scalehandle_draw_new(t_scalehandle *x, t_glist *canvas);
......@@ -334,9 +334,6 @@ static inline int iemgui_has_snd (t_iemgui *x) {return x->x_snd!=s_empty;}
static inline int iemgui_has_rcv (t_iemgui *x) {return x->x_rcv!=s_empty;}
EXTERN const char *iemgui_font(t_iemgui *x);
EXTERN void iemgui_class_addmethods(t_class *c);
EXTERN void scrollbar_update(t_glist *glist);
EXTERN void radio_draw_update(t_gobj *client, t_glist *glist);
EXTERN void iemgui_init(t_iemgui *x, t_floatarg f);
......@@ -8,7 +8,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "m_pd.h"
#include "g_canvas.h"
#include "g_all_guis.h"
......@@ -104,8 +103,7 @@ void bng_draw_select(t_bng* x, t_glist* glist)
{
sys_vgui(".x%lx.c itemconfigure %lxBUT "
"-stroke $pd_colors(selection)\n", canvas, x);
scalehandle_draw_select2(&x->x_gui,glist,
x->x_gui.x_w-1,x->x_gui.x_h-1);
scalehandle_draw_select2(&x->x_gui,glist);
}
}
else
......@@ -223,9 +221,7 @@ void bng_check_minmax(t_bng *x, int ftbreak, int fthold)
{
if(ftbreak > fthold)
{
int h;
h = ftbreak;
int h = ftbreak;
ftbreak = fthold;
fthold = h;
}
......@@ -281,7 +277,6 @@ static void bng_set(t_bng *x)
static void bng_bout1(t_bng *x)/*wird nur mehr gesendet, wenn snd != rcv*/
{
fprintf(stderr,"bng_bout1: snd=%s rcv=%s\n",x->x_gui.x_snd->s_name,x->x_gui.x_rcv->s_name);
if(!x->x_gui.x_put_in2out)
{
x->x_gui.x_locked = 1;
......@@ -366,19 +361,10 @@ static int bng_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix,
return (1);
}
static void bng_float(t_bng *x, t_floatarg f)
{bng_bang2(x);}
static void bng_symbol(t_bng *x, t_symbol *s)
{bng_bang2(x);}
static void bng_pointer(t_bng *x, t_gpointer *gp)
{bng_bang2(x);}
static void bng_list(t_bng *x, t_symbol *s, int ac, t_atom *av)
{
bng_bang2(x);
}
static void bng_float(t_bng *x, t_floatarg f) {bng_bang2(x);}
static void bng_symbol(t_bng *x, t_symbol *s) {bng_bang2(x);}
static void bng_pointer(t_bng *x, t_gpointer *gp) {bng_bang2(x);}
static void bng_list(t_bng *x, t_symbol *s, int ac, t_atom *av){bng_bang2(x);}
static void bng_anything(t_bng *x, t_symbol *s, int argc, t_atom *argv)
{bng_bang2(x);}
......@@ -394,8 +380,7 @@ static void bng_loadbang(t_bng *x)
static void bng_size(t_bng *x, t_symbol *s, int ac, t_atom *av)
{
x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
x->x_gui.x_h = x->x_gui.x_w;
x->x_gui.x_h = x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av));
iemgui_size(&x->x_gui);
}
......@@ -405,11 +390,6 @@ static void bng_flashtime(t_bng *x, t_symbol *s, int ac, t_atom *av)
(int)atom_getintarg(1, ac, av));
}
static void bng_init(t_bng *x, t_floatarg f)
{
x->x_gui.x_loadinit = (f==0.0)?0:1;
}
static void bng_tick_hld(t_bng *x)
{
x->x_flashed = 0;
......@@ -529,7 +509,7 @@ void g_bang_setup(void)
iemgui_class_addmethods(bng_class);
class_addmethod(bng_class, (t_method)bng_flashtime, gensym("flashtime"),
A_GIMME, 0);
class_addmethod(bng_class, (t_method)bng_init, gensym("init"), A_FLOAT, 0);
class_addmethod(bng_class, (t_method)iemgui_init, gensym("init"), A_FLOAT, 0);
scalehandle_class = class_new(gensym("_scalehandle"), 0, 0,
sizeof(t_scalehandle), CLASS_PD, 0);
......
......@@ -1928,8 +1928,6 @@ void canvasgop__clickhook(t_scalehandle *sh, t_floatarg f, t_floatarg xxx, t_flo
/* done dragging */
if(sh->h_scale) //enter if resize_gop hook
{
/* first set up the undo apply */
//canvas_canvas_setundo(x);
canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x));
if (sh->h_dragx || sh->h_dragy)
......
......@@ -89,8 +89,7 @@ void my_canvas_draw_select(t_my_canvas* x, t_glist* glist)
{
sys_vgui(".x%lx.c itemconfigure %lxBASE "
"-stroke $pd_colors(selection)\n", canvas, x);
scalehandle_draw_select2(&x->x_gui,glist,
x->x_vis_w,x->x_vis_h);
scalehandle_draw_select2(&x->x_gui,glist);
}
sys_vgui(".x%lx.c addtag selected withtag %lxOBJ\n", canvas, x);
}
......
......@@ -254,8 +254,7 @@ static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
sys_vgui(".x%lx.c itemconfigure %lxNUMBER -fill %s\n", canvas, x,
issel ? selection_color : fcol);
if(issel)
scalehandle_draw_select2(&x->x_gui,glist,
x->x_numwidth-1,x->x_gui.x_h-1);
scalehandle_draw_select2(&x->x_gui,glist);
else
scalehandle_draw_erase2(&x->x_gui,glist);
iemgui_label_draw_select(&x->x_gui,canvas);
......@@ -704,11 +703,6 @@ static void my_numbox_lin(t_my_numbox *x)
x->x_lin0_log1 = 0;
}
static void my_numbox_init(t_my_numbox *x, t_floatarg f)
{
x->x_gui.x_loadinit = (f==0.0)?0:1;
}
static void my_numbox_loadbang(t_my_numbox *x)
{
if(!sys_noloadbang && x->x_gui.x_loadinit)
......@@ -910,7 +904,7 @@ void g_numbox_setup(void)
gensym("log"), 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_lin,
gensym("lin"), 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_init,
class_addmethod(my_numbox_class, (t_method)iemgui_init,
gensym("init"), A_FLOAT, 0);
class_addmethod(my_numbox_class, (t_method)my_numbox_log_height,
gensym("log_height"), A_FLOAT, 0);
......
This diff is collapsed.
This diff is collapsed.
......@@ -108,15 +108,9 @@ void toggle_draw_select(t_toggle* x, t_glist* glist)
if(x->x_gui.x_selected)
{
if (x->x_gui.x_glist == glist_getcanvas(glist))
{
scalehandle_draw_select2(&x->x_gui,glist,
x->x_gui.x_w-1,x->x_gui.x_h-1);
}
}
else
{
scalehandle_draw_erase2(&x->x_gui,glist);
scalehandle_draw_select2(&x->x_gui,glist);
}
else scalehandle_draw_erase2(&x->x_gui,glist);
iemgui_label_draw_select(&x->x_gui,canvas);
iemgui_tag_selected(&x->x_gui,canvas);
}
......@@ -338,11 +332,6 @@ static void toggle_size(t_toggle *x, t_symbol *s, int ac, t_atom *av)
iemgui_size(&x->x_gui);
}
static void toggle_init(t_toggle *x, t_floatarg f)
{
x->x_gui.x_loadinit = (f==0.0)?0:1;
}
static void toggle_nonzero(t_toggle *x, t_floatarg f)
{
if(f != 0.0)
......@@ -444,7 +433,7 @@ void g_toggle_setup(void)
class_addmethod(toggle_class, (t_method)toggle_size, gensym("size"),
A_GIMME, 0);
iemgui_class_addmethods(toggle_class);
class_addmethod(toggle_class, (t_method)toggle_init, gensym("init"),
class_addmethod(toggle_class, (t_method)iemgui_init, gensym("init"),
A_FLOAT, 0);
class_addmethod(toggle_class, (t_method)toggle_nonzero, gensym("nonzero"),
A_FLOAT, 0);
......
......@@ -270,14 +270,10 @@ static void vu_draw_select(t_vu* x,t_glist* glist)
int issel = x->x_gui.x_selected && x->x_gui.x_glist==canvas;
sys_vgui(".x%lx.c itemconfigure %lxSCALEN "
"-fill %s\n", canvas, x, issel ? selection_color : lcol);
if(issel) {
scalehandle_draw_select2(&x->x_gui,glist,
x->x_gui.x_w+2-1,x->x_gui.x_h+4-1);
}
if(issel)
scalehandle_draw_select2(&x->x_gui,glist);
else
{
scalehandle_draw_erase2(&x->x_gui,glist);
}
iemgui_label_draw_select(&x->x_gui,canvas);
iemgui_tag_selected(&x->x_gui,canvas);
}
......@@ -305,8 +301,7 @@ static void vu__clickhook(t_scalehandle *sh, t_floatarg f, t_floatarg xxx,
scalehandle_unclick_scale(sh);
}
}
else iemgui__clickhook3(sh,newstate);
sh->h_dragon = newstate;
iemgui__clickhook3(sh,newstate);
}
static void vu__motionhook(t_scalehandle *sh, t_floatarg f1, t_floatarg f2)
......
......@@ -13,13 +13,11 @@ void g_guiconnect_setup(void);
/* iemlib */
void g_iemgui_setup(void);
void g_bang_setup(void);
void g_hradio_setup(void);
void g_hslider_setup(void);
void g_radio_setup(void);
void g_slider_setup(void);
void g_mycanvas_setup(void);
void g_numbox_setup(void);
void g_toggle_setup(void);
void g_vradio_setup(void);
void g_vslider_setup(void);
void g_vumeter_setup(void);
/* iemlib */
void g_io_setup(void);
......@@ -64,13 +62,11 @@ void conf_init(void)
/* iemlib */
g_iemgui_setup();
g_bang_setup();
g_hradio_setup();
g_hslider_setup();
g_radio_setup();
g_slider_setup();
g_mycanvas_setup();
g_numbox_setup();
g_toggle_setup();
g_vradio_setup();
g_vslider_setup();
g_vumeter_setup();
/* iemlib */
g_io_setup();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment