Update of /cvsroot/pure-data/externals/iem/iemgui/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8512/iem/iemgui/src
Added Files:
cube_sphere.c hfadl_scale.c hfadr_scale.c iem_event.c
iem_image.c iem_vu.c iemgui.c iemgui.dsp iemgui.dsw iemgui.h
iemlib.h makefile makefile_linux makefile_win
numberbox_matrix.c room_sim_2d.c room_sim_3d.c sym_dial.c
vfad_scale.c
Log Message:
initial check in
--- NEW FILE: iem_vu.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
/* ------------------------ setup routine ------------------------- */
t_widgetbehavior iem_vu_widgetbehavior;
static t_class *iem_vu_class;
static int iem_vu_db2i[]=
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
9, 9, 9, 9, 9,10,10,10,10,10,
11,11,11,11,11,12,12,12,12,12,
13,13,13,13,14,14,14,14,15,15,
15,15,16,16,16,16,17,17,17,18,
18,18,19,19,19,20,20,20,21,21,
22,22,23,23,24,24,25,26,27,28,
29,30,31,32,33,33,34,34,35,35,
36,36,37,37,37,38,38,38,39,39,
39,39,39,39,40,40
};
static int iem_vu_col[]=
{
0,17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
15,15,15,15,15,15,15,15,15,15,14,14,13,13,13,13,13,13,13,13,13,13,13,19,19,19
};
typedef struct _iem_vu
{
t_iemgui x_gui;
int x_peak;
int x_rms;
t_float x_fp;
t_float x_fr;
short x_scale;
short x_old_width;
int x_scale_w;
int x_scale_h;
void *x_out_rms;
void *x_out_peak;
char x_scale_gif[750];
char x_bkgd_gif_bord[990];
char x_bkgd_gif_cent[990];
} t_iem_vu;
static int iem_vu_clip_width(int w)
{
if(w < 8)
w = 8;
w &= 0xffffffc;
return(w);
}
static void iem_vu_update_rms(t_iem_vu *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
int ypos1=text_ypix(&x->x_gui.x_obj, glist)-1;
int xpos=text_xpix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c coords %xRCOVER %d %d %d %d\n",
glist_getcanvas(glist), x, xpos, ypos1, xpos+x->x_gui.x_w-1,
ypos1 + 3*(IEM_VU_STEPS-x->x_rms));
}
}
static void iem_vu_update_peak(t_iem_vu *x, t_glist *glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(glist_isvisible(glist))
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
if(x->x_peak)
{
int i=iem_vu_col[x->x_peak];
int j=ypos + 3*(IEM_VU_STEPS+1-x->x_peak) - 1;
sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n", canvas, x,
xpos, j, xpos+x->x_gui.x_w, j);
sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n", canvas, x, my_iemgui_color_hex[i]);
}
else
{
int mid=xpos+x->x_gui.x_w/2;
sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n",
canvas, x, mid, ypos+20, mid, ypos+20);
}
}
}
static void iem_vu_cpy(char *src, char *dst, int n)
{
while(n--)
*dst++ = *src++;
}
static void iem_vu_change_bkgd_col(t_iem_vu *x)
{
int i, j;
char pix_bkgd_col[10];
char pix_led_col[10];
char *cvec;
sprintf(pix_bkgd_col, "#%6.6x ", x->x_gui.x_bcol);
cvec = x->x_bkgd_gif_bord;
for(i=0; i<122; i++)
{
iem_vu_cpy(pix_bkgd_col, cvec, 8);
cvec += 8;
}
iem_vu_cpy(pix_bkgd_col, cvec, 8);
cvec[7] = 0;
cvec = x->x_bkgd_gif_cent;
iem_vu_cpy(pix_bkgd_col, cvec, 8);
cvec += 8;
iem_vu_cpy(pix_bkgd_col, cvec, 8);
cvec += 8;
for(i=IEM_VU_STEPS; i>=1; i--)
{
j = iem_vu_col[i];
sprintf(pix_led_col, "#%6.6x ", my_iemgui_color_hex[j]);
iem_vu_cpy(pix_led_col, cvec, 8);
cvec += 8;
iem_vu_cpy(pix_led_col, cvec, 8);
cvec += 8;
iem_vu_cpy(pix_bkgd_col, cvec, 8);
cvec += 8;
}
iem_vu_cpy(pix_bkgd_col, cvec, 8);
cvec[7] = 0;
sys_vgui("%xBKGDIMAGE_PROTO put {%s} -to 0 0\n", x, x->x_bkgd_gif_bord);
sys_vgui("%xBKGDIMAGE_PROTO put {%s} -to 1 0\n", x, x->x_bkgd_gif_cent);
sys_vgui("%xBKGDIMAGE_PROTO put {%s} -to 2 0\n", x, x->x_bkgd_gif_cent);
sys_vgui("%xBKGDIMAGE_PROTO put {%s} -to 3 0\n", x, x->x_bkgd_gif_bord);
}
static void iem_vu_draw_new(t_iem_vu *x, t_glist *glist)
{
t_canvas *canvas=glist_getcanvas(glist);
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int mid=xpos+x->x_gui.x_w/2;
int zoom=x->x_gui.x_w/4;
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xBASE\n",
canvas, xpos-1, ypos-2, xpos+x->x_gui.x_w, ypos+x->x_gui.x_h+2, x);
sys_vgui("image create photo %xBKGDIMAGE_PROTO -format gif -width %d -height %d\n",
x, 5, 123);
sys_vgui("%xBKGDIMAGE_PROTO blank\n", x);
iem_vu_change_bkgd_col(x);
sys_vgui("image create photo %xBKGDIMAGE -format gif -width %d -height %d\n",
x, x->x_gui.x_w, x->x_gui.x_h+3);
sys_vgui("%xBKGDIMAGE blank\n", x);
sys_vgui("%xBKGDIMAGE copy %xBKGDIMAGE_PROTO -zoom %d 1\n", x, x, zoom);
sys_vgui(".x%x.c create image %d %d -image %xBKGDIMAGE -tags %xBKGDPHOTO\n",
canvas, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2, x, x);
sys_vgui("image create photo %xSCALEIMAGE -format gif -width %d -height %d\n",
x, x->x_scale_w, x->x_scale_h);
sys_vgui("%xSCALEIMAGE blank\n", x);
if(x->x_scale)
{
sys_vgui(".x%x.c create image %d %d -image %xSCALEIMAGE -tags %xSCALEPHOTO\n",
canvas, xpos+x->x_gui.x_w+x->x_scale_w/2+2, ypos+x->x_gui.x_h/2+2, x, x);
my_iemgui_change_scale_col(x->x_scale_gif, x->x_gui.x_lcol);
sys_vgui("%xSCALEIMAGE configure -data {%s}\n", x, x->x_scale_gif);
}
sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xRCOVER\n",
canvas, xpos, ypos-1, xpos+x->x_gui.x_w-1,
ypos-1 + 3*IEM_VU_STEPS, x->x_gui.x_bcol, x->x_gui.x_bcol, x);
sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xPLED\n",
canvas, mid, ypos+10, mid, ypos+10, 2, x->x_gui.x_bcol, x);
sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
-font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
canvas, xpos-1, ypos + x->x_gui.x_h+1,
xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2, x, 0);
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
canvas, xpos+x->x_gui.x_w-IOWIDTH, ypos + x->x_gui.x_h+1,
xpos+x->x_gui.x_w, ypos + x->x_gui.x_h+2, x, 1);
}
if(!x->x_gui.x_fsf.x_rcv_able)
{
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
canvas, xpos-1, ypos-2, xpos + IOWIDTH-1, ypos-1, x, 0);
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
canvas, xpos+x->x_gui.x_w-IOWIDTH, ypos-2,
xpos+x->x_gui.x_w, ypos-1, x, 1);
}
}
static void iem_vu_draw_move(t_iem_vu *x, t_glist *glist)
{
t_canvas *canvas=glist_getcanvas(glist);
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos-1, ypos-2, xpos+x->x_gui.x_w,ypos+x->x_gui.x_h+2);
sys_vgui(".x%x.c coords %xBKGDPHOTO %d %d\n",
canvas, x, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2);
if(x->x_scale)
{
sys_vgui(".x%x.c coords %xSCALEPHOTO %d %d\n",
canvas, x, xpos+x->x_gui.x_w+x->x_scale_w/2+2, ypos+x->x_gui.x_h/2+2);
}
iem_vu_update_peak(x, glist);
iem_vu_update_rms(x, glist);
sys_vgui(".x%x.c coords %xLABEL %d %d\n",
canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
if(!x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
canvas, x, 0, xpos-1, ypos + x->x_gui.x_h+1,
xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2);
sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
canvas, x, 1,xpos+x->x_gui.x_w-IOWIDTH, ypos + x->x_gui.x_h+1,
xpos+x->x_gui.x_w, ypos + x->x_gui.x_h+2);
}
if(!x->x_gui.x_fsf.x_rcv_able)
{
sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
canvas, x, 0, xpos-1, ypos-2,
xpos + IOWIDTH-1, ypos-1);
sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
canvas, x, 1, xpos+x->x_gui.x_w-IOWIDTH, ypos-2,
xpos+x->x_gui.x_w, ypos-1);
}
}
static void iem_vu_draw_erase(t_iem_vu* x,t_glist* glist)
{
int i;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
sys_vgui(".x%x.c delete %xBKGDPHOTO\n", canvas, x);
sys_vgui("image delete %xBKGDIMAGE\n", x);
sys_vgui("image delete %xBKGDIMAGE_PROTO\n", x);
if(x->x_scale)
sys_vgui(".x%x.c delete %xSCALEPHOTO\n", canvas, x);
sys_vgui("image delete %xSCALEIMAGE\n", x);
sys_vgui(".x%x.c delete %xPLED\n", canvas, x);
sys_vgui(".x%x.c delete %xRCOVER\n", canvas, x);
sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
}
if(!x->x_gui.x_fsf.x_rcv_able)
{
sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1);
}
}
static void iem_vu_draw_config(t_iem_vu* x, t_glist* glist)
{
int i, zoom = x->x_gui.x_w / 4;
t_canvas *canvas=glist_getcanvas(glist);
iem_vu_change_bkgd_col(x);
if(x->x_gui.x_w != x->x_old_width)
{
x->x_old_width = x->x_gui.x_w;
sys_vgui("%xBKGDIMAGE blank\n", x);
sys_vgui("%xBKGDIMAGE configure -width %d -height %d\n",
x, x->x_gui.x_w, x->x_gui.x_h+3);
}
sys_vgui("%xBKGDIMAGE copy %xBKGDIMAGE_PROTO -zoom %d 1\n", x, x, zoom);
my_iemgui_change_scale_col(x->x_scale_gif, x->x_gui.x_lcol);
sys_vgui("%xSCALEIMAGE configure -data {%s}\n", x, x->x_scale_gif);
sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
sys_vgui(".x%x.c itemconfigure %xRCOVER -fill #%6.6x -outline #%6.6x\n",
canvas, x, x->x_gui.x_bcol, x->x_gui.x_bcol);
sys_vgui(".x%x.c itemconfigure %xPLED -width %d\n", canvas, x, 2);
}
static void iem_vu_draw_io(t_iem_vu* x, t_glist* glist, int old_snd_rcv_flags)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
{
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
canvas, xpos-1, ypos-2, xpos + IOWIDTH-1, ypos-1, x, 0);
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
canvas, xpos+x->x_gui.x_w-IOWIDTH, ypos-2,
xpos+x->x_gui.x_w, ypos-1, x, 1);
}
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
{
sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1);
}
}
static void iem_vu_draw_select(t_iem_vu* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
if(x->x_scale)
{
my_iemgui_change_scale_col(x->x_scale_gif, IEM_GUI_COLOR_SELECTED);
sys_vgui("%xSCALEIMAGE configure -data {%s}\n", x, x->x_scale_gif);
}
sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
if(x->x_scale)
{
my_iemgui_change_scale_col(x->x_scale_gif, x->x_gui.x_lcol);
sys_vgui("%xSCALEIMAGE configure -data {%s}\n", x, x->x_scale_gif);
}
sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
}
}
void iem_vu_draw(t_iem_vu *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
iem_vu_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
iem_vu_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
iem_vu_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
iem_vu_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
iem_vu_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
iem_vu_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ vu widgetbehaviour----------------------------- */
static void iem_vu_getrect(t_gobj *z, t_glist *glist,
int *xp1, int *yp1, int *xp2, int *yp2)
{
t_iem_vu* x = (t_iem_vu*)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist) - 1;
*yp1 = text_ypix(&x->x_gui.x_obj, glist) - 2;
*xp2 = *xp1 + x->x_gui.x_w + 2;
*yp2 = *yp1 + x->x_gui.x_h + 4;
}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void iem_vu_save(t_gobj *z, t_binbuf *b)
{
t_iem_vu *x = (t_iem_vu *)z;
int bflcol[3];
t_symbol *srl[3];
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiissiiiiiiii", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("iem_vu"), /*x->x_gui.x_w+1*/ x->x_gui.x_w, 120,
srl[1], srl[2],
x->x_gui.x_ldx, x->x_gui.x_ldy,
iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
bflcol[0], bflcol[2], x->x_scale, iem_symargstoint(&x->x_gui.x_isa));
binbuf_addv(b, ";");
}
#else
static void iem_vu_save(t_gobj *z, t_binbuf *b)
{
t_iem_vu *x = (t_iem_vu *)z;
int bflcol[3], *ip1, *ip2;
t_symbol *srl[3];
iemgui_save(&x->x_gui, srl, bflcol);
ip1 = (int *)(&x->x_gui.x_isa);
ip2 = (int *)(&x->x_gui.x_fsf);
binbuf_addv(b, "ssiisiissiiiiiiii", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("iem_vu"), /*x->x_gui.x_w+1*/ x->x_gui.x_w, 120,
srl[1], srl[2],
x->x_gui.x_ldx, x->x_gui.x_ldy,
(*ip2)&IEM_FSTYLE_FLAGS_ALL, x->x_gui.x_fontsize,
bflcol[0], bflcol[2], x->x_scale, (*ip1)&IEM_INIT_ARGS_ALL);
binbuf_addv(b, ";");
}
#endif
static void iem_vu_scale(t_iem_vu *x, t_floatarg fscale)
{
int i, scale = (int)fscale;
if(scale != 0)
scale = 1;
if(x->x_scale && !scale)
{
x->x_scale = scale;
if(glist_isvisible(x->x_gui.x_glist))
{
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
sys_vgui(".x%x.c delete %xSCALEPHOTO\n", canvas, x);
}
}
if(!x->x_scale && scale)
{
x->x_scale = scale;
if(glist_isvisible(x->x_gui.x_glist))
{
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
sys_vgui(".x%x.c create image %d %d -image %xSCALEIMAGE -tags %xSCALEPHOTO\n",
canvas, xpos+x->x_gui.x_w+x->x_scale_w/2+3, ypos+x->x_gui.x_h/2+2, x, x);
my_iemgui_change_scale_col(x->x_scale_gif, x->x_gui.x_lcol);
sys_vgui("%xSCALEIMAGE configure -data {%s}\n", x, x->x_scale_gif);
}
}
}
static void iem_vu_properties(t_gobj *z, t_glist *owner)
{
t_iem_vu *x = (t_iem_vu *)z;
char buf[800];
t_symbol *srl[3];
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s IEM_VU-METER \
--------dimensions(pix)(pix):-------- %d %d width: %d %d height: \
empty 0.0 empty 0.0 empty %d \
%d no_scale scale %d %d empty %d \
%s %s \
%s %d %d \
%d %d \
%d %d %d\n",
x->x_gui.x_w, IEM_GUI_MINSIZE, 120, 80,
0,/*no_schedule*/
x->x_scale, -1, -1, -1,/*no linlog, no init, no multi*/
"nosndno", srl[1]->s_name,/*no send*/
srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
0xffffff & x->x_gui.x_bcol, -1/*no front-color*/, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
void iem_vu_dialog(t_iem_vu *x, t_symbol *s, int argc, t_atom *argv)
{
t_symbol *srl[3];
int w = (int)atom_getintarg(0, argc, argv);
int scale = (int)atom_getintarg(4, argc, argv);
int sr_flags;
srl[0] = gensym("empty");
sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
// post("srl-flag = %x", sr_flags);
x->x_gui.x_fsf.x_snd_able = 0;
x->x_gui.x_isa.x_loadinit = 0;
x->x_gui.x_w = iem_vu_clip_width(w+1);
x->x_gui.x_h = 120;
if(scale != 0)
scale = 1;
iem_vu_scale(x, (t_float)scale);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void iem_vu_size(t_iem_vu *x, t_symbol *s, int ac, t_atom *av)
{
x->x_gui.x_w = iem_vu_clip_width((int)atom_getintarg(0, ac, av)+1);
x->x_gui.x_h = 120;
if(glist_isvisible(x->x_gui.x_glist))
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}
static void iem_vu_delta(t_iem_vu *x, t_symbol *s, int ac, t_atom *av)
{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
static void iem_vu_pos(t_iem_vu *x, t_symbol *s, int ac, t_atom *av)
{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
static void iem_vu_color(t_iem_vu *x, t_symbol *s, int ac, t_atom *av)
{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
static void iem_vu_receive(t_iem_vu *x, t_symbol *s)
{iemgui_receive(x, &x->x_gui, s);}
static void iem_vu_label(t_iem_vu *x, t_symbol *s)
{iemgui_label((void *)x, &x->x_gui, s);}
static void iem_vu_label_pos(t_iem_vu *x, t_symbol *s, int ac, t_atom *av)
{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
static void iem_vu_label_font(t_iem_vu *x, t_symbol *s, int ac, t_atom *av)
{iemgui_label_font((void *)x, &x->x_gui, s, ac, av);}
static void iem_vu_float(t_iem_vu *x, t_floatarg rms)
{
int i;
if(rms <= IEM_VU_MINDB)
x->x_rms = 0;
else if(rms >= IEM_VU_MAXDB)
x->x_rms = IEM_VU_STEPS;
else
{
int i = (int)(2.0*(rms + IEM_VU_OFFSET));
x->x_rms = iem_vu_db2i[i];
}
i = (int)(100.0*rms + 10000.5);
rms = 0.01*(t_float)(i - 10000);
x->x_fr = rms;
outlet_float(x->x_out_rms, rms);
iem_vu_update_rms(x, x->x_gui.x_glist);
}
static void iem_vu_ft1(t_iem_vu *x, t_floatarg peak)
{
int i;
if(peak <= IEM_VU_MINDB)
x->x_peak = 0;
else if(peak >= IEM_VU_MAXDB)
x->x_peak = IEM_VU_STEPS;
else
{
int i = (int)(2.0*(peak + IEM_VU_OFFSET));
x->x_peak = iem_vu_db2i[i];
}
i = (int)(100.0*peak + 10000.5);
peak = 0.01*(t_float)(i - 10000);
x->x_fp = peak;
outlet_float(x->x_out_peak, peak);
iem_vu_update_peak(x, x->x_gui.x_glist);
}
static void iem_vu_bang(t_iem_vu *x)
{
outlet_float(x->x_out_peak, x->x_fp);
outlet_float(x->x_out_rms, x->x_fr);
iem_vu_update_rms(x, x->x_gui.x_glist);
iem_vu_update_peak(x, x->x_gui.x_glist);
}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void *iem_vu_new(t_symbol *s, int argc, t_atom *argv)
{
t_iem_vu *x = (t_iem_vu *)pd_new(iem_vu_class);
int bflcol[]={-66577, -1, -1};
int w=IEM_GUI_DEFAULTSIZE;
int ldx=-1, ldy=-8, f=0, fs=8, scale=1;
int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
char str[144];
iem_inttosymargs(&x->x_gui.x_isa, 0);
iem_inttofstyle(&x->x_gui.x_fsf, 0);
if((argc >= 11)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
&&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2))
&&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))
&&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
&&IS_A_FLOAT(argv,6)&&IS_A_FLOAT(argv,7)
&&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10))
{
w = (int)atom_getintarg(0, argc, argv);
iemgui_new_getnames(&x->x_gui, 1, argv);
ldx = (int)atom_getintarg(4, argc, argv);
ldy = (int)atom_getintarg(5, argc, argv);
iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(6, argc, argv));
fs = (int)atom_getintarg(7, argc, argv);
bflcol[0] = (int)atom_getintarg(8, argc, argv);
bflcol[2] = (int)atom_getintarg(9, argc, argv);
scale = (int)atom_getintarg(10, argc, argv);
}
else iemgui_new_getnames(&x->x_gui, 1, 0);
if((argc == 12)&&IS_A_FLOAT(argv,11))
iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(11, argc, argv));
x->x_gui.x_draw = (t_iemfunptr)iem_vu_draw;
x->x_gui.x_fsf.x_snd_able = 0;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
x->x_gui.x_fsf.x_rcv_able = 0;
if (x->x_gui.x_fsf.x_font_style == 1)
strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2)
strcpy(x->x_gui.x_font, "times");
else { x->x_gui.x_fsf.x_font_style = 0;
strcpy(x->x_gui.x_font, "courier"); }
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
fs = 4;
x->x_gui.x_fontsize = fs;
// x->x_gui.x_w = iem_vu_clip_width(w)-1;
x->x_gui.x_w = iem_vu_clip_width(w+1);
x->x_old_width = x->x_gui.x_w;
x->x_gui.x_h = 120;
iemgui_all_colfromload(&x->x_gui, bflcol);
if(scale != 0)
scale = 1;
x->x_scale = scale;
x->x_peak = 0;
x->x_rms = 0;
x->x_fp = -101.0;
x->x_fr = -101.0;
iemgui_verify_snd_ne_rcv(&x->x_gui);
inlet_new(&x->x_gui.x_obj, &x->x_gui.x_obj.ob_pd, &s_float, gensym("ft1"));
x->x_out_rms = outlet_new(&x->x_gui.x_obj, &s_float);
x->x_out_peak = outlet_new(&x->x_gui.x_obj, &s_float);
x->x_scale_w = 14;
x->x_scale_h = 129;
strcpy(x->x_scale_gif, my_iemgui_black_vscale_gif);
x->x_gui.x_fsf.x_selected = 0;
return (x);
}
#else
static void *iem_vu_new(t_symbol *s, int argc, t_atom *argv)
{
t_iem_vu *x = (t_iem_vu *)pd_new(iem_vu_class);
int bflcol[]={-66577, -1, -1};
t_symbol *srl[3];
int w=IEM_GUI_DEFAULTSIZE;
int ldx=-1, ldy=-8, f=0, fs=8, scale=1;
int iinit=0, ifstyle=0;
int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME;
t_iem_init_symargs *init=(t_iem_init_symargs *)(&iinit);
t_iem_fstyle_flags *fstyle=(t_iem_fstyle_flags *)(&ifstyle);
char str[144];
srl[0] = gensym("empty");
srl[1] = gensym("empty");
srl[2] = gensym("empty");
if((argc >= 11)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
&&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2))
&&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3))
&&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
&&IS_A_FLOAT(argv,6)&&IS_A_FLOAT(argv,7)
&&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10))
{
w = (int)atom_getintarg(0, argc, argv);
if(IS_A_SYMBOL(argv,2))
srl[1] = atom_getsymbolarg(2, argc, argv);
else if(IS_A_FLOAT(argv,2))
{
sprintf(str, "%d", (int)atom_getintarg(2, argc, argv));
srl[1] = gensym(str);
}
if(IS_A_SYMBOL(argv,3))
srl[2] = atom_getsymbolarg(3, argc, argv);
else if(IS_A_FLOAT(argv,3))
{
sprintf(str, "%d", (int)atom_getintarg(3, argc, argv));
srl[2] = gensym(str);
}
ldx = (int)atom_getintarg(4, argc, argv);
ldy = (int)atom_getintarg(5, argc, argv);
ifstyle = (int)atom_getintarg(6, argc, argv);
fs = (int)atom_getintarg(7, argc, argv);
bflcol[0] = (int)atom_getintarg(8, argc, argv);
bflcol[2] = (int)atom_getintarg(9, argc, argv);
scale = (int)atom_getintarg(10, argc, argv);
}
if((argc == 12)&&IS_A_FLOAT(argv,11))
iinit = (int)atom_getintarg(11, argc, argv);
x->x_gui.x_draw = (t_iemfunptr)iem_vu_draw;
iinit &= IEM_INIT_ARGS_ALL;
ifstyle &= IEM_FSTYLE_FLAGS_ALL;
fstyle->x_snd_able = 0;
fstyle->x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_gui.x_isa = *init;
if(!strcmp(srl[1]->s_name, "empty")) fstyle->x_rcv_able = 0;
x->x_gui.x_unique_num = 0;
if(fstyle->x_font_style == 1)
strcpy(x->x_gui.x_font, "helvetica");
else if(fstyle->x_font_style == 2)
strcpy(x->x_gui.x_font, "times");
else
{
fstyle->x_font_style = 0;
strcpy(x->x_gui.x_font, "courier");
}
x->x_gui.x_fsf = *fstyle;
iemgui_first_dollararg2sym(&x->x_gui, srl);
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, srl[1]);
x->x_gui.x_snd = srl[0];
x->x_gui.x_rcv = srl[1];
x->x_gui.x_lab = srl[2];
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
fs = 4;
x->x_gui.x_fontsize = fs;
// x->x_gui.x_w = iem_vu_clip_width(w)-1;
x->x_gui.x_w = iem_vu_clip_width(w+1);
x->x_old_width = x->x_gui.x_w;
x->x_gui.x_h = 120;
iemgui_all_colfromload(&x->x_gui, bflcol);
if(scale != 0)
scale = 1;
x->x_scale = scale;
x->x_peak = 0;
x->x_rms = 0;
x->x_fp = -101.0;
x->x_fr = -101.0;
iemgui_verify_snd_ne_rcv(&x->x_gui);
inlet_new(&x->x_gui.x_obj, &x->x_gui.x_obj.ob_pd, &s_float, gensym("ft1"));
x->x_out_rms = outlet_new(&x->x_gui.x_obj, &s_float);
x->x_out_peak = outlet_new(&x->x_gui.x_obj, &s_float);
x->x_scale_w = 14;
x->x_scale_h = 129;
strcpy(x->x_scale_gif, my_iemgui_black_vscale_gif);
x->x_gui.x_fsf.x_selected = 0;
return (x);
}
#endif
static void iem_vu_free(t_iem_vu *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void iem_vu_setup(void)
{
iem_vu_class = class_new(gensym("iem_vu"), (t_newmethod)iem_vu_new, (t_method)iem_vu_free,
sizeof(t_iem_vu), 0, A_GIMME, 0);
class_addbang(iem_vu_class, iem_vu_bang);
class_addfloat(iem_vu_class, iem_vu_float);
class_addmethod(iem_vu_class, (t_method)iem_vu_ft1, gensym("ft1"), A_FLOAT, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_dialog, gensym("dialog"),
A_GIMME, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_size, gensym("size"), A_GIMME, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_scale, gensym("scale"), A_DEFFLOAT, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_delta, gensym("delta"), A_GIMME, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_pos, gensym("pos"), A_GIMME, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_color, gensym("color"), A_GIMME, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_receive, gensym("receive"), A_DEFSYM, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_label, gensym("label"), A_DEFSYM, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_label_pos, gensym("label_pos"), A_GIMME, 0);
class_addmethod(iem_vu_class, (t_method)iem_vu_label_font, gensym("label_font"), A_GIMME, 0);
iem_vu_widgetbehavior.w_getrectfn = iem_vu_getrect;
iem_vu_widgetbehavior.w_displacefn = iemgui_displace;
iem_vu_widgetbehavior.w_selectfn = iemgui_select;
iem_vu_widgetbehavior.w_activatefn = NULL;
iem_vu_widgetbehavior.w_deletefn = iemgui_delete;
iem_vu_widgetbehavior.w_visfn = iemgui_vis;
iem_vu_widgetbehavior.w_clickfn = NULL;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(iem_vu_class, iem_vu_save);
class_setpropertiesfn(iem_vu_class, iem_vu_properties);
#else
iem_vu_widgetbehavior.w_propertiesfn = iem_vu_properties;
iem_vu_widgetbehavior.w_savefn = iem_vu_save;
#endif
class_setwidget(iem_vu_class, &iem_vu_widgetbehavior);
class_sethelpsymbol(iem_vu_class, gensym("iemhelp2/help-iem_vu"));
}
--- NEW FILE: iemgui.dsp ---
# Microsoft Developer Studio Project File - Name="iemgui" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** NICHT BEARBEITEN **
# TARGTYPE "Win32 (x86) External Target" 0x0106
CFG=iemgui - Win32 Debug
!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
!MESSAGE
!MESSAGE NMAKE /f "iemgui.mak".
!MESSAGE
!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
!MESSAGE
!MESSAGE NMAKE /f "iemgui.mak" CFG="iemgui - Win32 Debug"
!MESSAGE
!MESSAGE Für die Konfiguration stehen zur Auswahl:
!MESSAGE
!MESSAGE "iemgui - Win32 Release" (basierend auf "Win32 (x86) External Target")
!MESSAGE "iemgui - Win32 Debug" (basierend auf "Win32 (x86) External Target")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
!IF "$(CFG)" == "iemgui - Win32 Release"
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Cmd_Line "NMAKE /f makefile_win"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "makefile_win.exe"
# PROP BASE Bsc_Name "makefile_win.bsc"
# PROP BASE Target_Dir ""
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Cmd_Line "NMAKE /f makefile_win"
# PROP Rebuild_Opt "/a"
# PROP Target_File "iemgui.exe"
# PROP Bsc_Name "iemgui.bsc"
# PROP Target_Dir ""
!ELSEIF "$(CFG)" == "iemgui - Win32 Debug"
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Cmd_Line "NMAKE /f makefile_win"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "makefile_win.exe"
# PROP BASE Bsc_Name "makefile_win.bsc"
# PROP BASE Target_Dir ""
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Cmd_Line "NMAKE /f makefile_win"
# PROP Rebuild_Opt "/a"
# PROP Target_File "iemgui.exe"
# PROP Bsc_Name "iemgui.bsc"
# PROP Target_Dir ""
!ENDIF
# Begin Target
# Name "iemgui - Win32 Release"
# Name "iemgui - Win32 Debug"
!IF "$(CFG)" == "iemgui - Win32 Release"
!ELSEIF "$(CFG)" == "iemgui - Win32 Debug"
!ENDIF
# Begin Source File
SOURCE=.\makefile_win
# End Source File
# End Target
# End Project
--- NEW FILE: room_sim_2d.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include "t_tk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
#define IEM_GUI_ROOMSIM_2D_MAX_NR_SRC 30
/* ---------- room_sim_2d my gui-canvas for a window ---------------- */
t_widgetbehavior room_sim_2d_widgetbehavior;
static t_class *room_sim_2d_class;
typedef struct _room_sim_2d
{
t_iemgui x_gui;
t_float x_rho_head;
int x_fontsize;
int x_nr_src;
int x_pix_src_x[IEM_GUI_ROOMSIM_2D_MAX_NR_SRC + 1];
int x_pix_src_y[IEM_GUI_ROOMSIM_2D_MAX_NR_SRC + 1];
int x_col_src[IEM_GUI_ROOMSIM_2D_MAX_NR_SRC + 1];
int x_pos_x;
int x_pos_y;
int x_sel_index;
int x_pix_rad;
t_float x_cnvrt_roomlx2pixh;
t_float x_r_ambi;
t_float x_room_x;
t_float x_room_y;
t_symbol *x_s_head_xy;
t_symbol *x_s_src_xy;
void *x_out_para;
void *x_out_rho;
t_atom x_at[6];
} t_room_sim_2d;
static void room_sim_2d_out_rho(t_room_sim_2d *x)
{
outlet_float(x->x_out_rho, x->x_rho_head);
}
static void room_sim_2d_out_para(t_room_sim_2d *x)
{
int i, n = x->x_nr_src;
int w2=x->x_gui.x_w/2, h2=x->x_gui.x_h/2;
SETFLOAT(x->x_at, 0.0f);
SETSYMBOL(x->x_at+1, x->x_s_head_xy);
SETFLOAT(x->x_at+2, (t_float)(h2 - x->x_pix_src_y[0])/x->x_cnvrt_roomlx2pixh);
SETFLOAT(x->x_at+3, (t_float)(w2 - x->x_pix_src_x[0])/x->x_cnvrt_roomlx2pixh);
outlet_list(x->x_out_para, &s_list, 4, x->x_at);
for(i=1; i<=n; i++)
{
SETFLOAT(x->x_at, (t_float)i);
SETSYMBOL(x->x_at+1, x->x_s_src_xy);
SETFLOAT(x->x_at+2, (t_float)(h2 - x->x_pix_src_y[i])/x->x_cnvrt_roomlx2pixh);
SETFLOAT(x->x_at+3, (t_float)(w2 - x->x_pix_src_x[i])/x->x_cnvrt_roomlx2pixh);
outlet_list(x->x_out_para, &s_list, 4, x->x_at);
}
}
static void room_sim_2d_draw_update(t_room_sim_2d *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int dx, dy;
t_canvas *canvas=glist_getcanvas(glist);
dx = -(int)((t_float)x->x_pix_rad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
dy = -(int)((t_float)x->x_pix_rad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+dx, ypos+x->x_pix_src_y[0]+dy);
}
}
void room_sim_2d_draw_new(t_room_sim_2d *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int dx, dy;
int i, n=x->x_nr_src;
int fs=x->x_fontsize;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
x->x_gui.x_bcol, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:IEM_GUI_COLOR_NORMAL, x);
for(i=1; i<=n; i++)
{
sys_vgui(".x%x.c create text %d %d -text {%d} -anchor c \
-font {times %d bold} -fill #%6.6x -tags %xSRC%d\n",
canvas, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i], i, fs,
x->x_col_src[i], x, i);
}
sys_vgui(".x%x.c create oval %d %d %d %d -outline #%6.6x -tags %xHEAD\n",
canvas, xpos+x->x_pix_src_x[0]-x->x_pix_rad, ypos+x->x_pix_src_y[0]-x->x_pix_rad,
xpos+x->x_pix_src_x[0]+x->x_pix_rad-1, ypos+x->x_pix_src_y[0]+x->x_pix_rad-1,
x->x_gui.x_fcol, x);
dx = -(int)((t_float)x->x_pix_rad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
dy = -(int)((t_float)x->x_pix_rad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %xNOSE\n",
canvas, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+dx, ypos+x->x_pix_src_y[0]+dy,
x->x_gui.x_fcol, x);
}
void room_sim_2d_draw_move(t_room_sim_2d *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int dx, dy;
int i, n;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
n = x->x_nr_src;
for(i=1; i<=n; i++)
{
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, i, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i]);
}
sys_vgui(".x%x.c coords %xHEAD %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-x->x_pix_rad, ypos+x->x_pix_src_y[0]-x->x_pix_rad,
xpos+x->x_pix_src_x[0]+x->x_pix_rad-1, ypos+x->x_pix_src_y[0]+x->x_pix_rad-1);
dx = -(int)((t_float)x->x_pix_rad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
dy = -(int)((t_float)x->x_pix_rad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+dx, ypos+x->x_pix_src_y[0]+dy);
}
void room_sim_2d_draw_erase(t_room_sim_2d* x, t_glist* glist)
{
int i, n;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
n = x->x_nr_src;
for(i=1; i<=n; i++)
{
sys_vgui(".x%x.c delete %xSRC%d\n", canvas, x, i);
}
sys_vgui(".x%x.c delete %xHEAD\n", canvas, x);
sys_vgui(".x%x.c delete %xNOSE\n", canvas, x);
}
void room_sim_2d_draw_select(t_room_sim_2d* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
}
}
void room_sim_2d_draw(t_room_sim_2d *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
room_sim_2d_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
room_sim_2d_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
room_sim_2d_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
room_sim_2d_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
room_sim_2d_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void room_sim_2d_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_room_sim_2d *x = (t_room_sim_2d *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h;
}
static void room_sim_2d_save(t_gobj *z, t_binbuf *b)
{
t_room_sim_2d *x = (t_room_sim_2d *)z;
int i, j, c, n=x->x_nr_src;
binbuf_addv(b, "ssiis", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, gensym("room_sim_2d"));
binbuf_addv(b, "ifffi", x->x_nr_src, x->x_cnvrt_roomlx2pixh, x->x_rho_head, x->x_r_ambi, x->x_fontsize);
c = x->x_gui.x_bcol;
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "iff", j, x->x_room_x, x->x_room_y);
c = x->x_gui.x_fcol;
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "iii", j, x->x_pix_src_x[0], x->x_pix_src_y[0]);
for(i=1; i<=n; i++)
{
c = x->x_col_src[i];
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "iii", j, x->x_pix_src_x[i], x->x_pix_src_y[i]);
}
binbuf_addv(b, ";");
}
static void room_sim_2d_motion(t_room_sim_2d *x, t_floatarg dx, t_floatarg dy)
{
int sel=x->x_sel_index;
int pixrad=x->x_pix_rad;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ddx, ddy;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(x->x_gui.x_fsf.x_finemoved && (sel == 0))
{
x->x_rho_head -= dy;
if(x->x_rho_head <= -180.0f)
x->x_rho_head += 360.0f;
if(x->x_rho_head > 180.0f)
x->x_rho_head -= 360.0f;
room_sim_2d_out_rho(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
else if(sel == 0)
{
x->x_pos_x += (int)dx;
x->x_pos_y += (int)dy;
x->x_pix_src_x[0] = x->x_pos_x;
x->x_pix_src_y[0] = x->x_pos_y;
if(x->x_pix_src_x[0] < 0)
x->x_pix_src_x[0] = 0;
if(x->x_pix_src_x[0] > x->x_gui.x_w)
x->x_pix_src_x[0] = x->x_gui.x_w;
if(x->x_pix_src_y[0] < 0)
x->x_pix_src_y[0] = 0;
if(x->x_pix_src_y[0] > x->x_gui.x_h)
x->x_pix_src_y[0] = x->x_gui.x_h;
room_sim_2d_out_para(x);
sys_vgui(".x%x.c coords %xHEAD %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-pixrad, ypos+x->x_pix_src_y[0]-pixrad,
xpos+x->x_pix_src_x[0]+pixrad-1, ypos+x->x_pix_src_y[0]+pixrad-1);
ddx = -(int)((t_float)pixrad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
ddy = -(int)((t_float)pixrad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+ddx, ypos+x->x_pix_src_y[0]+ddy);
}
else
{
x->x_pos_x += (int)dx;
x->x_pos_y += (int)dy;
x->x_pix_src_x[sel] = x->x_pos_x;
x->x_pix_src_y[sel] = x->x_pos_y;
if(x->x_pix_src_x[sel] < 0)
x->x_pix_src_x[sel] = 0;
if(x->x_pix_src_x[sel] > x->x_gui.x_w)
x->x_pix_src_x[sel] = x->x_gui.x_w;
if(x->x_pix_src_y[sel] < 0)
x->x_pix_src_y[sel] = 0;
if(x->x_pix_src_y[sel] > x->x_gui.x_h)
x->x_pix_src_y[sel] = x->x_gui.x_h;
room_sim_2d_out_para(x);
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, sel, xpos+x->x_pix_src_x[sel], ypos+x->x_pix_src_y[sel]);
}
}
static void room_sim_2d_click(t_room_sim_2d *x, t_floatarg xpos, t_floatarg ypos,
t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
int w = (int)xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int h = (int)ypos - text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int i, n=x->x_nr_src;
int pixrad=x->x_pix_rad;
int fsi=x->x_fontsize;
int diff, maxdiff=10000, sel=-1;
i = 0;/* head */
if((w >= (x->x_pix_src_x[i]-pixrad)) && (w <= (x->x_pix_src_x[i]+pixrad)) && (h >= (x->x_pix_src_y[i]-pixrad)) && (h <= (x->x_pix_src_y[i]+pixrad)))
{
diff = w - x->x_pix_src_x[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
diff = h - x->x_pix_src_y[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
}
fsi *= 2;
fsi /= 3;
for(i=1; i<=n; i++)
{
if((w >= (x->x_pix_src_x[i]-fsi)) && (w <= (x->x_pix_src_x[i]+fsi)) &&
(h >= (x->x_pix_src_y[i]-fsi)) && (h <= (x->x_pix_src_y[i]+fsi)))
{
diff = w - x->x_pix_src_x[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
diff = h - x->x_pix_src_y[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
}
}
if(sel >= 0)
{
x->x_sel_index = sel;
x->x_pos_x = x->x_pix_src_x[sel];
x->x_pos_y = x->x_pix_src_y[sel];
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, (t_glistmotionfn)room_sim_2d_motion, 0, xpos, ypos);
}
}
static int room_sim_2d_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_room_sim_2d* x = (t_room_sim_2d *)z;
if(doit)
{
room_sim_2d_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
if(shift)
{
x->x_gui.x_fsf.x_finemoved = 1;
room_sim_2d_out_rho(x);
}
else
{
x->x_gui.x_fsf.x_finemoved = 0;
room_sim_2d_out_para(x);
}
}
return (1);
}
static void room_sim_2d_bang(t_room_sim_2d *x)
{
room_sim_2d_out_para(x);
room_sim_2d_out_rho(x);
}
static void room_sim_2d_src_font(t_room_sim_2d *x, t_floatarg ff)
{
int fs=(int)(ff + 0.49999f);
int i, n=x->x_nr_src;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(fs < 8)
fs = 8;
if(fs > 250)
fs = 250;
x->x_fontsize = fs;
for(i=1; i<=n; i++)
{
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, i, fs);
}
}
static void room_sim_2d_set_rho(t_room_sim_2d *x, t_floatarg rho)
{
while(rho <= -180.0f)
rho += 360.0f;
while(rho > 180.0f)
rho -= 360.0f;
x->x_rho_head = rho;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
static void room_sim_2d_rho(t_room_sim_2d *x, t_floatarg rho)
{
room_sim_2d_set_rho(x, rho);
room_sim_2d_out_rho(x);
}
static void room_sim_2d_set_src_xy(t_room_sim_2d *x, t_symbol *s, int argc, t_atom *argv)
{
t_float xsrc, ysrc;
t_float roomx2=0.5f*x->x_room_x, roomy2=0.5f*x->x_room_y;
int i, n=x->x_nr_src;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int w2=x->x_gui.x_w/2, h2=x->x_gui.x_h/2;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(argc < 3)
{
post("room_sim_2d ERROR: src_xy-input needs 1 index + 2 float-dimensions: src_index, x [m], y [m]");
return;
}
i = (int)atom_getint(argv++);
if((i > 0)&&(i <= n))
{
ysrc = atom_getfloat(argv++);
xsrc = atom_getfloat(argv);
if(xsrc < -roomy2)
xsrc = -roomy2;
if(xsrc > roomy2)
xsrc = roomy2;
if(ysrc < -roomx2)
ysrc = -roomx2;
if(ysrc > roomx2)
ysrc = roomx2;
x->x_pix_src_x[i] = w2 - (int)(x->x_cnvrt_roomlx2pixh * xsrc + 0.49999f);
x->x_pix_src_y[i] = h2 - (int)(x->x_cnvrt_roomlx2pixh * ysrc + 0.49999f);
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, i, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i]);
}
}
static void room_sim_2d_src_xy(t_room_sim_2d *x, t_symbol *s, int argc, t_atom *argv)
{
room_sim_2d_set_src_xy(x, s, argc, argv);
room_sim_2d_out_para(x);
}
static void room_sim_2d_set_head_xy(t_room_sim_2d *x, t_symbol *s, int argc, t_atom *argv)
{
int pixrad=x->x_pix_rad;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int w2=x->x_gui.x_w/2, h2=x->x_gui.x_h/2;
int ddx, ddy;
t_float xh, yh;
t_float roomx2=0.5f*x->x_room_x, roomy2=0.5f*x->x_room_y;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(argc < 2)
{
post("room_sim_2d ERROR: head_xy-input needs 2 float-dimensions: x [m], y [m]");
return;
}
yh = atom_getfloat(argv++);
xh = atom_getfloat(argv);
if(xh < -roomy2)
xh = -roomy2;
if(xh > roomy2)
xh = roomy2;
if(yh < -roomx2)
yh = -roomx2;
if(yh > roomx2)
yh = roomx2;
x->x_pix_src_x[0] = w2 - (int)(x->x_cnvrt_roomlx2pixh * xh + 0.49999f);
x->x_pix_src_y[0] = h2 - (int)(x->x_cnvrt_roomlx2pixh * yh + 0.49999f);
sys_vgui(".x%x.c coords %xHEAD %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-pixrad, ypos+x->x_pix_src_y[0]-pixrad,
xpos+x->x_pix_src_x[0]+pixrad-1, ypos+x->x_pix_src_y[0]+pixrad-1);
ddx = -(int)((t_float)pixrad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
ddy = -(int)((t_float)pixrad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+ddx, ypos+x->x_pix_src_y[0]+ddy);
}
static void room_sim_2d_head_xy(t_room_sim_2d *x, t_symbol *s, int argc, t_atom *argv)
{
room_sim_2d_set_head_xy(x, s, argc, argv);
room_sim_2d_out_para(x);
}
static void room_sim_2d_room_dim(t_room_sim_2d *x, t_symbol *s, int argc, t_atom *argv)
{
int i, n=x->x_nr_src;
if(argc < 2)
{
post("room_sim_2d ERROR: room_dim-input needs 2 float-dimensions: x-Length [m], y-Width [m]");
return;
}
x->x_room_x = atom_getfloat(argv++);
x->x_room_y = atom_getfloat(argv);
if(x->x_room_x < 1.0f)
x->x_room_x = 1.0f;
if(x->x_room_y < 1.0f)
x->x_room_y = 1.0f;
x->x_gui.x_h = (int)(x->x_cnvrt_roomlx2pixh * (t_float)x->x_room_x + 0.49999f);
x->x_gui.x_w = (int)(x->x_cnvrt_roomlx2pixh * (t_float)x->x_room_y + 0.49999f);
for(i=1; i<=n; i++)
{
if(x->x_pix_src_x[i] > x->x_gui.x_w)
x->x_pix_src_x[i] = x->x_gui.x_w;
if(x->x_pix_src_y[i] > x->x_gui.x_h)
x->x_pix_src_y[i] = x->x_gui.x_h;
}
room_sim_2d_out_para(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
/*static void room_sim_2d_n_src(t_room_sim_2d *x, t_floatarg fnsrc)
{
int n_src=(int)fnsrc;
if(n_src < 1)
n_src = 1;
if(n_src > 30)
n_src = 30;
if(n_src != x->x_nr_src)
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
x->x_nr_src = n_src;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
*/
static void room_sim_2d_room_col(t_room_sim_2d *x, t_floatarg fcol)
{
int col=(int)fcol;
int i;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(col < 0)
{
i = -1 - col;
x->x_gui.x_bcol = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_gui.x_bcol = my_iemgui_color_hex[col];
}
sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
}
static void room_sim_2d_head_col(t_room_sim_2d *x, t_floatarg fcol)
{
int col=(int)fcol;
int i;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(col < 0)
{
i = -1 - col;
x->x_gui.x_fcol = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_gui.x_fcol = my_iemgui_color_hex[col];
}
sys_vgui(".x%x.c itemconfigure %xHEAD -outline #%6.6x\n", canvas, x, x->x_gui.x_fcol);
sys_vgui(".x%x.c itemconfigure %xNOSE -fill #%6.6x\n", canvas, x, x->x_gui.x_fcol);
}
static void room_sim_2d_src_col(t_room_sim_2d *x, t_symbol *s, int argc, t_atom *argv)
{
int col;
int i, j, n=x->x_nr_src;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if((argc >= 2)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1))
{
j = (int)atom_getintarg(0, argc, argv);
if((j > 0)&&(j <= n))
{
col = (int)atom_getintarg(1, argc, argv);
if(col < 0)
{
i = -1 - col;
x->x_col_src[j] = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_col_src[j] = my_iemgui_color_hex[col];
}
sys_vgui(".x%x.c itemconfigure %xSRC%d -fill #%6.6x\n", canvas, x, j, x->x_col_src[j]);
}
}
}
static void room_sim_2d_pix_per_m_ratio(t_room_sim_2d *x, t_floatarg ratio)
{
t_float rr;
int i, n=x->x_nr_src;
if(ratio < 1.0f)
ratio = 1.0f;
if(ratio > 200.0f)
ratio = 200.0f;
rr = ratio / x->x_cnvrt_roomlx2pixh;
x->x_cnvrt_roomlx2pixh = ratio;
x->x_gui.x_w = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_y + 0.49999f);
x->x_gui.x_h = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_x + 0.49999f);
x->x_pix_rad = (int)(x->x_cnvrt_roomlx2pixh * x->x_r_ambi + 0.49999f);
for(i=0; i<=n; i++)
{
x->x_pix_src_x[i] = (int)((t_float)x->x_pix_src_x[i]*rr + 0.49999f);
x->x_pix_src_y[i] = (int)((t_float)x->x_pix_src_y[i]*rr + 0.49999f);
}
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void room_sim_2d_r_ambi(t_room_sim_2d *x, t_floatarg r_ambi)
{
if(r_ambi < 0.1f)
r_ambi = 0.1f;
x->x_r_ambi = r_ambi;
x->x_pix_rad = (int)(x->x_cnvrt_roomlx2pixh*r_ambi + 0.49999f);
room_sim_2d_out_para(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
}
static void room_sim_2d_nr_src(t_room_sim_2d *x, t_floatarg fnr_src)
{
int nr_src = (int)fnr_src;
int old_nr_src, i, j;
if(nr_src < 1)
nr_src = 1;
else if(nr_src > IEM_GUI_ROOMSIM_2D_MAX_NR_SRC)
nr_src = IEM_GUI_ROOMSIM_2D_MAX_NR_SRC;
if(nr_src != x->x_nr_src)
{
if(glist_isvisible(x->x_gui.x_glist))
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
old_nr_src = x->x_nr_src;
x->x_nr_src = nr_src;
j = (old_nr_src + 1) % 7;
for(i=old_nr_src+1; i<=nr_src; i++)
{
x->x_col_src[i] = simularca_color_hex[j];
if(i & 1)
x->x_pix_src_x[i] = 125 + (IEM_GUI_ROOMSIM_2D_MAX_NR_SRC - i)*4;
else
x->x_pix_src_x[i] = 125 - (IEM_GUI_ROOMSIM_2D_MAX_NR_SRC - i)*4;
x->x_pix_src_y[i] = 100;
j++;
j %= 7;
}
if(glist_isvisible(x->x_gui.x_glist))
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
static void *room_sim_2d_new(t_symbol *s, int argc, t_atom *argv)
{
t_room_sim_2d *x = (t_room_sim_2d *)pd_new(room_sim_2d_class);
int i, j, n=1, c;
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
n = (int)atom_getintarg(0, argc, argv);
if(n < 1)
n = 1;
if(n > IEM_GUI_ROOMSIM_2D_MAX_NR_SRC)
n = IEM_GUI_ROOMSIM_2D_MAX_NR_SRC;
x->x_nr_src = n;
}
if(argc == (3*n + 11))
{
x->x_cnvrt_roomlx2pixh = atom_getfloatarg(1, argc, argv);
x->x_rho_head = atom_getfloatarg(2, argc, argv);
x->x_r_ambi = atom_getfloatarg(3, argc, argv);
x->x_fontsize = (int)atom_getintarg(4, argc, argv);
c = (int)atom_getintarg(5, argc, argv);
x->x_gui.x_bcol = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_room_x = atom_getfloatarg(6, argc, argv);
x->x_room_y = atom_getfloatarg(7, argc, argv);
c = (int)atom_getintarg(8, argc, argv);
x->x_gui.x_fcol = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_pix_src_x[0] = (int)atom_getintarg(9, argc, argv);
x->x_pix_src_y[0] = (int)atom_getintarg(10, argc, argv);
for(i=1; i<=n; i++)
{
c = (int)atom_getintarg(8+3*i, argc, argv);
x->x_col_src[i] = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_pix_src_x[i] = (int)atom_getintarg(9+3*i, argc, argv);
x->x_pix_src_y[i] = (int)atom_getintarg(10+3*i, argc, argv);
}
}
else
{
x->x_cnvrt_roomlx2pixh = 25.0f;
x->x_rho_head = 0.0f;
x->x_r_ambi = 1.4f;
x->x_fontsize = 12;
x->x_gui.x_bcol = my_iemgui_color_hex[IEM_GUI_COLNR_GREEN];
x->x_room_x = 12.0f;
x->x_room_y = 10.0f;
x->x_gui.x_fcol = my_iemgui_color_hex[IEM_GUI_COLNR_D_ORANGE];
x->x_pix_src_x[0] = 125;
x->x_pix_src_y[0] = 200;
j = 0;
for(i=1; i<=n; i++)
{
x->x_col_src[i] = simularca_color_hex[j];
if(i & 1)
x->x_pix_src_x[i] = 125 + (IEM_GUI_ROOMSIM_2D_MAX_NR_SRC - i)*4;
else
x->x_pix_src_x[i] = 125 - (IEM_GUI_ROOMSIM_2D_MAX_NR_SRC - i)*4;
x->x_pix_src_y[i] = 100;
j++;
j %= 7;
}
}
x->x_gui.x_w = (int)(x->x_room_y*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_gui.x_h = (int)(x->x_room_x*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_pix_rad = (int)(x->x_r_ambi*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_gui.x_draw = (t_iemfunptr)room_sim_2d_draw;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_out_para = outlet_new(&x->x_gui.x_obj, &s_list);
x->x_out_rho = outlet_new(&x->x_gui.x_obj, &s_float);
x->x_s_head_xy = gensym("head_xy");
x->x_s_src_xy = gensym("src_xy");
return (x);
}
static void room_sim_2d_ff(t_room_sim_2d *x)
{
gfxstub_deleteforkey(x);
}
void room_sim_2d_setup(void)
{
room_sim_2d_class = class_new(gensym("room_sim_2d"), (t_newmethod)room_sim_2d_new,
(t_method)room_sim_2d_ff, sizeof(t_room_sim_2d), 0, A_GIMME, 0);
class_addcreator((t_newmethod)room_sim_2d_new, gensym("room_sim_2d"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_click, gensym("click"),
A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_motion, gensym("motion"),
A_FLOAT, A_FLOAT, 0);
class_addbang(room_sim_2d_class, (t_method)room_sim_2d_bang);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_room_dim, gensym("room_dim"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_r_ambi, gensym("r_ambi"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_room_col, gensym("room_col"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_head_col, gensym("head_col"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_src_col, gensym("src_col"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_rho, gensym("rho"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_src_xy, gensym("src_xy"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_head_xy, gensym("head_xy"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_set_rho, gensym("set_rho"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_set_src_xy, gensym("set_src_xy"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_set_head_xy, gensym("set_head_xy"), A_GIMME, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_pix_per_m_ratio, gensym("pix_per_m_ratio"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_src_font, gensym("src_font"), A_DEFFLOAT, 0);
class_addmethod(room_sim_2d_class, (t_method)room_sim_2d_nr_src, gensym("nr_src"), A_DEFFLOAT, 0);
room_sim_2d_widgetbehavior.w_getrectfn = room_sim_2d_getrect;
room_sim_2d_widgetbehavior.w_displacefn = iemgui_displace;
room_sim_2d_widgetbehavior.w_selectfn = iemgui_select;
room_sim_2d_widgetbehavior.w_activatefn = NULL;
room_sim_2d_widgetbehavior.w_deletefn = iemgui_delete;
room_sim_2d_widgetbehavior.w_visfn = iemgui_vis;
room_sim_2d_widgetbehavior.w_clickfn = room_sim_2d_newclick;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(room_sim_2d_class, room_sim_2d_save);
#else
room_sim_2d_widgetbehavior.w_propertiesfn = NULL;
room_sim_2d_widgetbehavior.w_savefn = room_sim_2d_save;
#endif
class_setwidget(room_sim_2d_class, &room_sim_2d_widgetbehavior);
class_sethelpsymbol(room_sim_2d_class, gensym("iemhelp2/help-room_sim_2d"));
}
--- NEW FILE: makefile_linux ---
current: all
.SUFFIXES: .pd_linux
INCLUDE = -I. -I/usr/local/src/pd/src
LDFLAGS = -export-dynamic -shared
LIB = -ldl -lm -lpthread
#select either the DBG and OPT compiler flags below:
CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \
-Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing \
-DDL_OPEN
SYSTEM = $(shell uname -m)
# the sources
SRC = room_sim_2d.c \
room_sim_3d.c \
cube_sphere.c \
sym_dial.c \
iem_image.c \
iem_vu.c \
hfadl_scale.c \
hfadr_scale.c \
vfad_scale.c \
numberbox_matrix.c \
iem_event.c \
iemgui.c
TARGET = iemgui.pd_linux
OBJ = $(SRC:.c=.o)
#
# ------------------ targets ------------------------------------
#
clean:
rm ..\$(TARGET)
rm *.o
all: $(OBJ)
@echo :: $(OBJ)
$(LD) $(LDFLAGS) -o $(TARGET) *.o $(LIB)
strip --strip-unneeded $(TARGET)
mv $(TARGET) ..
$(OBJ) : %.o : %.c
$(CC) $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
--- NEW FILE: iemgui.dsw ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: iemgui.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
char my_iemgui_black_vscale_gif[]="R0lGODlhDgCCAJEAANnZ2QAAAP///////yH5BAEAAAAALAAAAAAOAIIAAAL/hI+pa0EBICIIdkRYBCEBgIigEHbEBQSFsCPOIghGxF0EwQkzg6AAEQTfIoxiE3xMvQgK4WMERBDsuIg7owAQEQEEgGKDgRHsuAgICmHHRUBQCB8jguBj6nL7AxITPkZABMGOu4gzCuFHHMUGACP4cRBxByQARBB8NIpN8DF1uf1JTPgYAREE/yIgguBfBEQQjIiwCEJC8C8CIgj+RUAEwceIIPiYutz+gMSEjxEQQfDRIjKNEgCABRCACIKPEJEJlBA+GsUm+Ji63P4kJnyMgAiCfxGISHEIdkRYBCEh+BcBEQT/IiCC4GNEEHxMXW5fkgDAgmBHhEUQEgCICAph5UdcQFAIO+IsgmBE3EUQnDAzCAoQQfAtwig2wcfU5fYkMQAsAAhIQAQEBQmCHwERQAnhR0AEUELYERYBlAAADICQQAQAUAIAMDCCGRvgCD6mLrcriQFgAUBAAiIgKEgQ/AiIAEoIO8IigBLCj4AIoITwIyACKAGAgQElMAAAC4ITQfAxdbldSRyAI9gRFwGUAMAAgJBABABQHAADAwICEAFBQYLgR0AEUAIAAwNKYAAAFgQnguBj6nL7OxIHLgCAkABEBBASAIgAQhIAEUBAAiAiCEgYRBjFAAMAoDhwQfAxdbkdSQEAOw==";
char my_iemgui_black_hlscale_gif[]="R0lGODlhgwAaAJEAANnZ2QAAAP///////yH5BAEAAAAALAAAAACDABoAAAL/hI+py+0Po5y02ouz3rz7D4biKBIJ4WPqcvsDkhD+RQQiUEz4FxGBiAgZEhM+pi63P4kJ3yIgguBDBEQQfItARMRD4hB8CMQLgo8QmZmZDolD8BEiMikhfIhAREREggTBh0C8IPgIkZmZ6ZAgQfARIhIpIXyLiEBEhBBJCJtiE3yg2AQfKDbBt4hABIoJHyMQjRLCR4hIowARBB8iAhGBJIQPgXhB8BEiMzNTIgnhXwQiUkL4GIGIiIckhA+BeEHwESIzM1MiCeFbBKJRAiP4EAERBB9TLYLgY+py+wOSEL5RbIJvEYEIFBM+pi63P4xy0gpITPgRcXcUE/5FBCJQ/0z4FxGIQDHhX0QgAsWEfxGBiIgMSWAAAEZICD5EQATBhwiIIPgQAREEHyIgguBDBEQQfIiACIIPERBB8CECIgh2RAQEJSH4GIERBB8vIo0SGMHHCLygED5eRBolMIIPERBB8CECIghGhEUEAQkzM6AEAGBG8BEi0iiBEXyMwAtKQvARItIogRF8iIAIgg8REEEwIiwiCEiYmQWFsCMg4u5IQvgWAREE/yIQg4IEwb8IxKAgQfAhAiIIPkRABMGIsIggIGFmEBTCj4CIOyMJ4V8ERBB8i0AESmAE3yIQgRIYwYcIiCD4EAERBCPCIoKAhJlFEHyIgAiCDxGIRgmM4FVDBKJRAiP4EIFolMAIPkRABMGHCIgg2BEREJSE4APFJtgRcWcUm+BbRCBSbIJvEYFIsQm+RQQiUEz4FxEEH1OX2x9GOWm1F2e9efcfDMWRLM0TfYgCADs=";
char my_iemgui_black_hrscale_gif[]="R0lGODlhhgAbAJEAANnZ2QAAAP///////yH5BAEAAAAALAAAAACGABsAAAL/hI+py+0Po5y02ouz3rz7D4biSG5EHIJvEYEIFBM+RhB8TF1uf0ASwsfUjCD4FwERBB8iIILgW0QQfExdbn8SEz6mYgTBx4vIpITwISICERFCCBkSwkeITKAQfkQEwcdUjKCE8DEC8SghfAiIQESEEEKGhPARIhMohB8QcXd3SEz4EBaBaCQh/ItANEoI/yICESgmfKPYBB8oNsEHik3wIwg+pm4EwccIxKAQPkJEZmZKiITwESITKIRvEYiIiABJYAQfIiCC4EMEIlJC+Ji6GgQfITKBQvgWgYiIyJCY8C8iECk2wb8Igo+py+0PSEL4mLrc/jDKSesiMeFfRCAC/8WEfxGBCBQT/kUEIlBM+BcRiEAx4UfE3R3FgQsAICQQQfAhAiIIPkRABMGHCIgg+BABEQQfIiCC4EMERBB8iIAIgg8REEEwIiDi7gBJABYARnACIswMSAIj+BABEQQfI/CCQvh4EWmUwAg+RuAFhfAxAtEoAVgAGMEJiDAzIAmM4EMERBB8jMALSkLwESLSKIERfIzAC0pC8C0C0SgBWAAYwQmIMDMgCYzgQwREEPyLQAwKEgT/IhCDggTBvwjEoCBB8CPuzigBWAAYwQmIMDMgCYzgQwREEHyLQARKYATfIhCBEhjBtwhEoARGsCPu7oDiwAUAEBKIIPgQAREEH1YiIILgQwSiUQIj+BCBaJTACD5EIBolMAAAI/iYuhEUwr+IQASKCd8oNsG3iECk2ATfIgKRYhN8iwgEik3wMXW5/WGUk1Z7cdabd//BUBzJ0jzRVF1NogA7";
char my_iemgui_base64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int my_iemgui_color_hex[]=
{
16579836, 10526880, 4210752, 16572640, 16572608,
16579784, 14220504, 14220540, 14476540, 16308476,
14737632, 8158332, 2105376, 16525352, 16559172,
15263784, 1370132, 2684148, 3952892, 16003312,
12369084, 6316128, 0, 9177096, 5779456,
7874580, 2641940, 17488, 5256, 5767248
};
int simularca_color_hex[]=
{
16003312, 3952892, 2684148, 15263784, 16559172, 16525352, 8158332
};
void my_iemgui_change_scale_col(char *gif, int color)
{
int i;
unsigned int red = (color & 0xff0000) >> 16;
unsigned int green = (color & 0xff00) >> 8;
unsigned int blue = color & 0xff;
t_my_iemgui_3u4 hexbyte;
hexbyte.b3.dummy = 0;
hexbyte.b3.byte1 = 0xD6;
hexbyte.b3.byte2 = red;
hexbyte.b3.byte3 = green;
i = hexbyte.h4.hex1;
gif[20] = my_iemgui_base64[i];
i = hexbyte.h4.hex2;
gif[21] = my_iemgui_base64[i];
i = hexbyte.h4.hex3;
gif[22] = my_iemgui_base64[i];
i = hexbyte.h4.hex4;
gif[23] = my_iemgui_base64[i];
hexbyte.b3.byte1 = blue;
hexbyte.b3.byte2 = 0xFF;
hexbyte.b3.byte3 = 0xFF;
i = hexbyte.h4.hex1;
gif[24] = my_iemgui_base64[i];
i = hexbyte.h4.hex2;
gif[25] = my_iemgui_base64[i];
i = hexbyte.h4.hex3;
gif[26] = my_iemgui_base64[i];
i = hexbyte.h4.hex4;
gif[27] = my_iemgui_base64[i];
}
static t_class *iemgui_class;
static void *iemgui_new(void)
{
t_object *x = (t_object *)pd_new(iemgui_class);
return (x);
}
//void simularca_2d_setup(void);
//void simularca_3d_setup(void);
void room_sim_2d_setup(void);
void room_sim_3d_setup(void);
//void simularca_3d_no_z_clip_setup(void);
void cube_sphere_setup(void);
void sym_dial_setup(void);
void iem_image_setup(void);
void iem_vu_setup(void);
void hfadl_scale_setup(void);
void hfadr_scale_setup(void);
void vfad_scale_setup(void);
void numberbox_matrix_setup(void);
void iem_event_setup(void);
//void toggle_matrix_setup(void);
/* ------------------------ setup routine ------------------------- */
void iemgui_setup(void)
{
// simularca_2d_setup();
// simularca_3d_setup();
room_sim_2d_setup();
room_sim_3d_setup();
// simularca_3d_no_z_clip_setup();
cube_sphere_setup();
sym_dial_setup();
iem_image_setup();
iem_vu_setup();
hfadl_scale_setup();
hfadr_scale_setup();
vfad_scale_setup();
numberbox_matrix_setup();
iem_event_setup();
// toggle_matrix_setup();
post("iemgui (R-1.16) library loaded! (c) Thomas Musil 05.2005");
post(" musil%ciem.at iem KUG Graz Austria", '@');
}
--- NEW FILE: hfadl_scale.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include <string.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
/* ------------------------ setup routine ------------------------- */
t_widgetbehavior hfadl_scale_widgetbehavior;
static t_class *hfadl_scale_class;
typedef struct _hfadl_scale
{
t_iemgui x_gui;
char x_gif[870];
} t_hfadl_scale;
static void hfadl_scale_draw_new(t_hfadl_scale *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui("image create photo %xPHOTOIMAGE -format gif -data {%s} -width %d -height %d\n",
x, x->x_gif, x->x_gui.x_w, x->x_gui.x_h);
sys_vgui(".x%x.c create image %d %d -image %xPHOTOIMAGE -tags %xPHOTO\n",
canvas, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2-1, x, x);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos+1,
xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
IEM_GUI_COLOR_SELECTED, x);
}
static void hfadl_scale_draw_move(t_hfadl_scale *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xPHOTO %d %d\n",
canvas, x, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2-1);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos+1,
xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void hfadl_scale_draw_erase(t_hfadl_scale* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
sys_vgui("image delete %xPHOTOIMAGE\n", x);
sys_vgui(".x%x.c delete %xPHOTO\n", canvas, x);
}
static void hfadl_scale_draw_select(t_hfadl_scale* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos+1, xpos + x->x_gui.x_w,
ypos + x->x_gui.x_h, IEM_GUI_COLOR_SELECTED, x);
}
else
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
}
static void hfadl_scale_draw(t_hfadl_scale *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
hfadl_scale_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
hfadl_scale_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
hfadl_scale_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
hfadl_scale_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void hfadl_scale_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_hfadl_scale *x = (t_hfadl_scale *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist)+1;
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h-1;
}
static void hfadl_scale_color(t_hfadl_scale *x, t_symbol *s, int argc, t_atom *argv)
{
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
int j, i = (int)atom_getintarg(0, argc, argv);
if(i >= 0)
{
j = iemgui_modulo_color(i);
x->x_gui.x_lcol = my_iemgui_color_hex[j];
}
else
x->x_gui.x_lcol = (-1 - i) & 0xffffff;
my_iemgui_change_scale_col(x->x_gif, x->x_gui.x_lcol);
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui("%xPHOTOIMAGE configure -data {%s}\n", x, x->x_gif);
}
}
static void hfadl_scale_save(t_gobj *z, t_binbuf *b)
{
t_hfadl_scale *x = (t_hfadl_scale *)z;
binbuf_addv(b, "ssiisi", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("hfadl_scale"), -1 - (((0xfc0000 & x->x_gui.x_lcol) >> 6)|
((0xfc00 & x->x_gui.x_lcol) >> 4)|((0xfc & x->x_gui.x_lcol) >> 2)));
binbuf_addv(b, ";");
}
static void *hfadl_scale_new(t_symbol *s, int argc, t_atom *argv)
{
t_hfadl_scale *x = (t_hfadl_scale *)pd_new(hfadl_scale_class);
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
int j, i = (int)atom_getintarg(0, argc, argv);
if(i >= 0)
{
j = iemgui_modulo_color(i);
x->x_gui.x_lcol = my_iemgui_color_hex[j];
}
else
{
j = -1 - i;
x->x_gui.x_lcol = ((j & 0x3f000) << 6)|((j & 0xfc0) << 4)|((j & 0x3f) << 2);
}
}
else
x->x_gui.x_lcol = 0;
x->x_gui.x_draw = (t_iemfunptr)hfadl_scale_draw;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_gui.x_w = 126;
x->x_gui.x_h = 21;
strcpy(x->x_gif, my_iemgui_black_hlscale_gif);
my_iemgui_change_scale_col(x->x_gif, x->x_gui.x_lcol);
x->x_gui.x_fsf.x_selected = 0;
return(x);
}
static void hfadl_scale_ff(t_hfadl_scale *x)
{
gfxstub_deleteforkey(x);
}
void hfadl_scale_setup(void)
{
hfadl_scale_class = class_new(gensym("hfadl_scale"), (t_newmethod)hfadl_scale_new,
(t_method)hfadl_scale_ff, sizeof(t_hfadl_scale), 0, A_GIMME, 0);
class_addmethod(hfadl_scale_class, (t_method)hfadl_scale_color, gensym("color"), A_GIMME, 0);
hfadl_scale_widgetbehavior.w_getrectfn = hfadl_scale_getrect;
hfadl_scale_widgetbehavior.w_displacefn = iemgui_displace;
hfadl_scale_widgetbehavior.w_selectfn = iemgui_select;
hfadl_scale_widgetbehavior.w_activatefn = NULL;
hfadl_scale_widgetbehavior.w_deletefn = iemgui_delete;
hfadl_scale_widgetbehavior.w_visfn = iemgui_vis;
hfadl_scale_widgetbehavior.w_clickfn = NULL;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(hfadl_scale_class, hfadl_scale_save);
#else
hfadl_scale_widgetbehavior.w_propertiesfn = NULL;
hfadl_scale_widgetbehavior.w_savefn = hfadl_scale_save;
#endif
class_setwidget(hfadl_scale_class, &hfadl_scale_widgetbehavior);
class_sethelpsymbol(hfadl_scale_class, gensym("iemhelp2/help-hfadl_scale"));
}
--- NEW FILE: makefile_win ---
all: ..\iemgui.dll
VIS_CPP_PATH = "C:\Programme\Microsoft Visual Studio\Vc98"
PD_INST_PATH = "C:\Programme\pd-0.39-2"
PD_WIN_INCLUDE_PATH = /I. /I$(PD_INST_PATH)\src /I$(VIS_CPP_PATH)\include
PD_WIN_C_FLAGS = /nologo /W3 /WX /DMSW /DNT /DPD /DWIN32 /DWINDOWS /Ox -DPA_LITTLE_ENDIAN
PD_WIN_L_FLAGS = /nologo
PD_WIN_LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel /NODEFAULTLIB:uuid \
$(VIS_CPP_PATH)\lib\libc.lib \
$(VIS_CPP_PATH)\lib\oldnames.lib \
$(VIS_CPP_PATH)\lib\kernel32.lib \
$(VIS_CPP_PATH)\lib\wsock32.lib \
$(VIS_CPP_PATH)\lib\winmm.lib \
$(PD_INST_PATH)\bin\pthreadVC.lib \
$(PD_INST_PATH)\bin\pd.lib
SRC = room_sim_2d.c \
room_sim_3d.c \
cube_sphere.c \
sym_dial.c \
iem_image.c \
iem_vu.c \
hfadl_scale.c \
hfadr_scale.c \
vfad_scale.c \
numberbox_matrix.c \
iem_event.c \
iemgui.c
OBJ = $(SRC:.c=.obj)
.c.obj:
cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c
..\iemgui.dll: $(OBJ)
link $(PD_WIN_L_FLAGS) /dll /export:iemgui_setup \
/out:..\iemgui.dll $(OBJ) $(PD_WIN_LIB)
clean:
del *.obj
--- NEW FILE: makefile ---
current: all
.SUFFIXES: .pd_linux
INCLUDE = -I. -I/usr/local/src/pd/src
LDFLAGS = -export-dynamic -shared
LIB = -ldl -lm -lpthread
#select either the DBG and OPT compiler flags below:
CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \
-Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer -fno-strict-aliasing \
-DDL_OPEN
SYSTEM = $(shell uname -m)
# the sources
SRC = room_sim_2d.c \
room_sim_3d.c \
cube_sphere.c \
sym_dial.c \
iem_image.c \
iem_vu.c \
hfadl_scale.c \
hfadr_scale.c \
vfad_scale.c \
numberbox_matrix.c \
iem_event.c \
iemgui.c
TARGET = iemgui.pd_linux
OBJ = $(SRC:.c=.o)
#
# ------------------ targets ------------------------------------
#
clean:
rm ..\$(TARGET)
rm *.o
all: $(OBJ)
@echo :: $(OBJ)
$(LD) $(LDFLAGS) -o $(TARGET) *.o $(LIB)
strip --strip-unneeded $(TARGET)
mv $(TARGET) ..
$(OBJ) : %.o : %.c
$(CC) $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
--- NEW FILE: cube_sphere.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include "t_tk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
#define IEMGUI_CUBE_SPHERE_MAX 200
/* ---------- cube_sphere my gui-canvas for a window ---------------- */
t_widgetbehavior cube_sphere_widgetbehavior;
static t_class *cube_sphere_class;
typedef struct _cube_sphere
{
t_iemgui x_gui;
int x_fontsize;
int x_n_src;
int x_null;
int x_pix_src_x[IEMGUI_CUBE_SPHERE_MAX];
int x_pix_src_y[IEMGUI_CUBE_SPHERE_MAX];
int x_col_src[IEMGUI_CUBE_SPHERE_MAX];
int x_vis_src[IEMGUI_CUBE_SPHERE_MAX];
int x_pos_x;
int x_pos_y;
t_float x_pos_dx;
t_float x_pos_dy;
t_float x_pos_dr;
int x_sel_index;
int x_radius;
t_float x_90overradius;
void *x_out_para;
t_atom x_at[3];
} t_cube_sphere;
static void cube_sphere_out_all(t_cube_sphere *x)
{
t_float delta, phi, diffr, diffx, diffy, fff=180.0f/3.14159265f;
int i, n = x->x_n_src;
int rad=x->x_radius;
for(i=0; i<n; i++)
{
SETFLOAT(x->x_at, (t_float)(i+1));
diffx = (t_float)(x->x_pix_src_x[i] - rad);
diffy = (t_float)(x->x_pix_src_y[i] - rad);
diffr = sqrt(diffx * diffx + diffy * diffy);
delta = 90.0f - x->x_90overradius*diffr*1.01f;
if(delta < 0.0f)
delta = 0.0f;
if(delta > 90.0f)
delta = 90.0f;
if(diffx == 0.0f)
{
if(diffy > 0.0f)
phi = -180.0f;
else
phi = 0.0f;
}
else if(diffx > 0.0f)
{
if(diffy >= 0.0f)
phi = fff*atan(diffx/diffy) - 180.0f;
else
phi = fff*atan(diffx/diffy);
}
else /* diffx < 0 */
{
if(diffy >= 0.0f)
phi = fff*atan(diffx/diffy) + 180.0f;
else
phi = fff*atan(diffx/diffy);
}
SETFLOAT(x->x_at+1, delta);
SETFLOAT(x->x_at+2, phi);
outlet_list(x->x_out_para, &s_list, 3, x->x_at);
}
}
static void cube_sphere_out_sel(t_cube_sphere *x)
{
t_float delta, phi, fff=180.0f/3.14159265f;
t_float diffr=x->x_pos_dr;
t_float diffx=x->x_pos_dx;
t_float diffy=x->x_pos_dy;
int sel=x->x_sel_index;
int n = x->x_n_src;
int rad=x->x_radius;
SETFLOAT(x->x_at, (t_float)(sel+1));
delta = 90.0f - x->x_90overradius*diffr*1.01f;
if(delta < 0.0f)
delta = 0.0f;
if(delta > 90.0f)
delta = 90.0f;
if(diffx == 0.0f)
{
if(diffy > 0.0f)
phi = -180.0f;
else
phi = 0.0f;
}
else if(diffx > 0.0f)
{
if(diffy >= 0.0f)
phi = fff*atan(diffx/diffy) - 180.0f;
else
phi = fff*atan(diffx/diffy);
}
else /* diffx < 0 */
{
if(diffy >= 0.0f)
phi = fff*atan(diffx/diffy) + 180.0f;
else
phi = fff*atan(diffx/diffy);
}
SETFLOAT(x->x_at+1, delta);
SETFLOAT(x->x_at+2, phi);
outlet_list(x->x_out_para, &s_list, 3, x->x_at);
}
void cube_sphere_draw_new(t_cube_sphere *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int x2=xpos+x->x_gui.x_w/2;
int y2=ypos+x->x_gui.x_h/2;
int r3=x->x_radius/3;
int i, n=x->x_n_src;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol, x);
sys_vgui(".x%x.c create oval %d %d %d %d -fill #%6.6x -tags %xCIRC_AQ\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h, x->x_gui.x_bcol, x);
sys_vgui(".x%x.c create oval %d %d %d %d -tags %xCIRC_WK\n",
canvas, x2-2*r3, y2-2*r3, x2+2*r3, y2+2*r3, x);
sys_vgui(".x%x.c create oval %d %d %d %d -tags %xCIRC_PK\n",
canvas, x2-r3, y2-r3, x2+r3, y2+r3, x);
sys_vgui(".x%x.c create oval %d %d %d %d -tags %xCIRC_NP\n",
canvas, x2-2, y2-2, x2+2, y2+2, x);
if(x->x_null)
{
sys_vgui(".x%x.c create text %d %d -text {+} -anchor c \
-font {times %d bold} -fill #%6.6x -tags %xSRC0\n",
canvas, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0], x->x_fontsize,
x->x_col_src[0], x);
}
else
{
for(i=0; i<n; i++)
{
if(x->x_vis_src[i])
sys_vgui(".x%x.c create text %d %d -text {%d} -anchor c \
-font {times %d bold} -fill #%6.6x -tags %xSRC%d\n",
canvas, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i], i+1, x->x_fontsize,
x->x_col_src[i], x, i);
}
}
}
void cube_sphere_draw_move(t_cube_sphere *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int x2=xpos+x->x_gui.x_w/2;
int y2=ypos+x->x_gui.x_h/2;
int r3=x->x_radius/3;
int i, n=x->x_n_src;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
sys_vgui(".x%x.c coords %xCIRC_AQ %d %d %d %d\n",
canvas, x, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
sys_vgui(".x%x.c coords %xCIRC_WK %d %d %d %d\n",
canvas, x, x2-2*r3, y2-2*r3, x2+2*r3, y2+2*r3);
sys_vgui(".x%x.c coords %xCIRC_PK %d %d %d %d\n",
canvas, x, x2-r3, y2-r3, x2+r3, y2+r3);
sys_vgui(".x%x.c coords %xCIRC_NP %d %d %d %d\n",
canvas, x, x2-2, y2-2, x2+2, y2+2);
for(i=0; i<n; i++)
{
if(x->x_vis_src[i])
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, i, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i]);
}
}
void cube_sphere_draw_erase(t_cube_sphere* x, t_glist* glist)
{
int i, n;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
sys_vgui(".x%x.c delete %xCIRC_AQ\n", canvas, x);
sys_vgui(".x%x.c delete %xCIRC_WK\n", canvas, x);
sys_vgui(".x%x.c delete %xCIRC_PK\n", canvas, x);
sys_vgui(".x%x.c delete %xCIRC_NP\n", canvas, x);
n = x->x_n_src;
for(i=0; i<n; i++)
{
if(x->x_vis_src[i])
sys_vgui(".x%x.c delete %xSRC%d\n", canvas, x, i);
}
}
void cube_sphere_draw_select(t_cube_sphere* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n",
canvas, x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
}
void cube_sphere_draw(t_cube_sphere *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
cube_sphere_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
cube_sphere_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
cube_sphere_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
cube_sphere_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void cube_sphere_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_cube_sphere *x = (t_cube_sphere *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h;
}
static void cube_sphere_save(t_gobj *z, t_binbuf *b)
{
t_cube_sphere *x = (t_cube_sphere *)z;
int i, j, c, n=x->x_n_src;
binbuf_addv(b, "ssiis", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, gensym("cube_sphere"));
if(x->x_null)
binbuf_addv(b, "iii", 0, x->x_radius, x->x_fontsize);
else
binbuf_addv(b, "iii", x->x_n_src, x->x_radius, x->x_fontsize);
c = x->x_gui.x_bcol;
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "i", j);
c = x->x_gui.x_fcol;
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "i", j);
for(i=0; i<n; i++)
{
c = x->x_col_src[i];
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "iii", j, x->x_pix_src_x[i], x->x_pix_src_y[i]);
}
binbuf_addv(b, ";");
}
static void cube_sphere_motion(t_cube_sphere *x, t_floatarg dx, t_floatarg dy)
{
int sel=x->x_sel_index;
if(x->x_vis_src[sel])
{
int i, diffx, diffy, diffr, xx, yy;
int rad = x->x_radius;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
x->x_pos_x += (int)dx;
x->x_pos_y += (int)dy;
x->x_pix_src_x[sel] = x->x_pos_x;
x->x_pix_src_y[sel] = x->x_pos_y;
diffx = x->x_pix_src_x[sel] - rad;
diffy = x->x_pix_src_y[sel] - rad;
x->x_pos_dx=(t_float)diffx;
x->x_pos_dy=(t_float)diffy;
x->x_pos_dr = sqrt(diffx * diffx + diffy * diffy);
diffr = (int)(x->x_pos_dr+0.49999f);
if(diffr > rad)
{
xx = rad * diffx;
xx /= diffr;
yy = rad * diffy;
yy /= diffr;
x->x_pix_src_y[sel] = rad + yy;
x->x_pix_src_x[sel] = rad + xx;
}
cube_sphere_out_sel(x);
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, sel, xpos+x->x_pix_src_x[sel], ypos+x->x_pix_src_y[sel]);
}
}
static void cube_sphere_click(t_cube_sphere *x, t_floatarg xpos, t_floatarg ypos,
t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
int xpix=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypix=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int cxpos=xpix+x->x_radius;
int cypos=ypix+x->x_radius;
int w = (int)xpos - xpix;
int h = (int)ypos - ypix;
int i, n=x->x_n_src;
int diff, maxdiff=10000, sel=-1, diffx, diffy, diffr;
int fs=x->x_fontsize/2+2;
diffx = xpos - cxpos;
diffy = ypos - cypos;
diffr = (int)(sqrt(diffx * diffx + diffy * diffy)+0.49999f);
if(diffr <= x->x_radius)
{
for(i=0; i<n; i++)
{
if((w >= (x->x_pix_src_x[i]-fs)) && (w <= (x->x_pix_src_x[i]+fs)) && (h >= (x->x_pix_src_y[i]-fs)) && (h <= (x->x_pix_src_y[i]+fs)))
{
diff = w - x->x_pix_src_x[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
diff = h - x->x_pix_src_y[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
}
}
if(sel >= 0)
{
if(x->x_vis_src[sel])
{
x->x_sel_index = sel;
x->x_pos_x = x->x_pix_src_x[sel];
x->x_pos_y = x->x_pix_src_y[sel];
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, (t_glistmotionfn)cube_sphere_motion, 0, xpos, ypos);
}
}
}
}
static int cube_sphere_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_cube_sphere* x = (t_cube_sphere *)z;
if(doit)
{
cube_sphere_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
}
return (1);
}
static void cube_sphere_bang(t_cube_sphere *x)
{
cube_sphere_out_all(x);
}
static void cube_sphere_src_font(t_cube_sphere *x, t_floatarg ff)
{
int fs=(int)(ff + 0.49999f);
int i, n=x->x_n_src;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(fs < 5)
fs = 5;
if(fs > 150)
fs = 150;
x->x_fontsize = fs;
if(glist_isvisible(x->x_gui.x_glist))
{
for(i=0; i<n; i++)
{
if(x->x_vis_src[i])
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, i, fs);
}
}
}
static void cube_sphere_src_dp(t_cube_sphere *x, t_symbol *s, int argc, t_atom *argv)
{
t_float delta, phi;
int i, n=x->x_n_src;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(argc < 3)
{
post("cube_sphere ERROR: src_dp-input needs 1 index + 2 float-angles: src_index, delta [degree], phi [degree]");
return;
}
i = (int)atom_getint(argv++)-1;
if((i >= 0)&&(i < n))
{
delta = 90.0f - atom_getfloat(argv++);
phi = atom_getfloat(argv);
phi /= 180.0f;
phi *= 3.14159265f;
delta /= x->x_90overradius*0.99;
if(delta < 0.0f)
delta = 0.0f;
if(delta > (t_float)x->x_radius)
delta = (t_float)x->x_radius;
x->x_pix_src_x[i] = x->x_radius - (int)(delta*sin(phi) + 0.49999f);
x->x_pix_src_y[i] = x->x_radius - (int)(delta*cos(phi) + 0.49999f);
if(glist_isvisible(x->x_gui.x_glist) && x->x_vis_src[i])
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, i, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i]);
}
}
static void cube_sphere_size(t_cube_sphere *x, t_floatarg size)
{
t_float ratio, xx, yy;
// t_float ratio, rr;
int i, newrad, n=x->x_n_src;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
size /= 6.0f;
newrad = (int)(size + 0.4999f);
newrad *= 3;
if(newrad < 9)
newrad = 9;
if(newrad > 1800)
newrad = 1800;
ratio = (t_float)newrad / (t_float)x->x_radius;
for(i=0; i<n; i++)
{
xx = (t_float)x->x_pix_src_x[i] * ratio;
x->x_pix_src_x[i] = (t_int)(xx + 0.4999f);
yy = (t_float)x->x_pix_src_y[i] * ratio;
x->x_pix_src_y[i] = (t_int)(yy + 0.4999f);
/*xx -= (t_float)newrad;
yy -= (t_float)newrad;
rr = sqrt(xx*xx + yy*yy);
if(rr > (t_float)newrad)
{
}*/
}
x->x_90overradius = 90.0f / (t_float)newrad;
x->x_radius = newrad;
x->x_gui.x_h = 2*newrad;
x->x_gui.x_w = 2*newrad;
cube_sphere_out_all(x);
if(glist_isvisible(x->x_gui.x_glist))
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}
static void cube_sphere_vis(t_cube_sphere *x, t_symbol *s, int argc, t_atom *argv)
{
int index, n=x->x_n_src;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int newstate, oldstate;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(argc < 2)
{
post("cube_sphere ERROR: vis-input needs 1 index + 1 visual state");
return;
}
index = (int)atom_getint(argv++) - 1;
if((index >= 0) && (index < n))
{
newstate = ((int)atom_getint(argv) ? 1 : 0);
oldstate = x->x_vis_src[index];
if(newstate && !oldstate)
{
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c create text %d %d -text {%d} -anchor c \
-font {times %d bold} -fill #%6.6x -tags %xSRC%d\n",
canvas, xpos+x->x_pix_src_x[index], ypos+x->x_pix_src_y[index], index+1, x->x_fontsize,
x->x_col_src[index], x, index);
}
else if(!newstate && oldstate)
{
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c delete %xSRC%d\n", canvas, x, index);
}
x->x_vis_src[index] = newstate;
}
else if(index < 0)
{// if index is -1 : all
newstate = ((int)atom_getint(argv) ? 1 : 0);
for(index=0; index<n; index++)
{
oldstate = x->x_vis_src[index];
if(newstate && !oldstate)
{
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c create text %d %d -text {%d} -anchor c \
-font {times %d bold} -fill #%6.6x -tags %xSRC%d\n",
canvas, xpos+x->x_pix_src_x[index], ypos+x->x_pix_src_y[index], index+1, x->x_fontsize,
x->x_col_src[index], x, index);
}
else if(!newstate && oldstate)
{
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c delete %xSRC%d\n", canvas, x, index);
}
x->x_vis_src[index] = newstate;
}
}
}
static void cube_sphere_sphere_col(t_cube_sphere *x, t_floatarg fcol)
{
int col=(int)fcol;
int i;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(col < 0)
{
i = -1 - col;
x->x_gui.x_bcol = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_gui.x_bcol = my_iemgui_color_hex[col];
}
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c itemconfigure %xCIRC_AQ -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
}
static void cube_sphere_frame_col(t_cube_sphere *x, t_floatarg fcol)
{
int col=(int)fcol;
int i;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(col < 0)
{
i = -1 - col;
x->x_gui.x_fcol = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_gui.x_fcol = my_iemgui_color_hex[col];
}
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n",
canvas, x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
}
static void cube_sphere_src_col(t_cube_sphere *x, t_symbol *s, int argc, t_atom *argv)
{
int col;
int help_col, src_index, n=x->x_n_src;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if((argc >= 2)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1))
{
src_index = (int)atom_getintarg(0, argc, argv) - 1;
if((src_index >= 0) && (src_index < n))
{
col = (int)atom_getintarg(1, argc, argv);
if(col < 0)
{
help_col = -1 - col;
x->x_col_src[src_index] = ((help_col & 0x3f000) << 6)|((help_col & 0xfc0) << 4)|((help_col & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_col_src[src_index] = my_iemgui_color_hex[col];
}
if((x->x_vis_src[src_index]) && glist_isvisible(x->x_gui.x_glist))
sys_vgui(".x%x.c itemconfigure %xSRC%d -fill #%6.6x\n", canvas, x, src_index, x->x_col_src[src_index]);
}
}
}
static void cube_sphere_nr_src(t_cube_sphere *x, t_floatarg fnr_src)
{
int n=(int)fnr_src;
int old_nr_src, i, j, old_null;
old_null = x->x_null;
if(n <= 0)
x->x_null = 1;
else
x->x_null = 0;
if(n < 1)
n = 1;
if(n > IEMGUI_CUBE_SPHERE_MAX)
n = IEMGUI_CUBE_SPHERE_MAX;
if((n != x->x_n_src) || (old_null != x->x_null))
{
if(glist_isvisible(x->x_gui.x_glist))
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
old_nr_src = x->x_n_src;
j = old_nr_src % 7;
x->x_n_src = n;
for(i=old_nr_src; i<n; i++)
{
x->x_col_src[i] = simularca_color_hex[j];
x->x_vis_src[i] = 1;
x->x_pix_src_x[i] = x->x_radius;
x->x_pix_src_y[i] = x->x_radius;
j++;
j %= 7;
}
if(glist_isvisible(x->x_gui.x_glist))
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
static void *cube_sphere_new(t_symbol *s, int argc, t_atom *argv)
{
t_cube_sphere *x = (t_cube_sphere *)pd_new(cube_sphere_class);
int i, j, n=1, c;
t_float xx;
x->x_null = 1;
x->x_radius = 180;
if(argc <= 0)
{
n = 1;
x->x_null = 1;
x->x_n_src = n;
}
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
n = (int)atom_getintarg(0, argc, argv);
if(n <= 0)
x->x_null = 1;
else
x->x_null = 0;
if(n < 1)
n = 1;
if(n > IEMGUI_CUBE_SPHERE_MAX)
n = IEMGUI_CUBE_SPHERE_MAX;
x->x_n_src = n;
}
if((argc >= 2)&&IS_A_FLOAT(argv,1))
{
x->x_radius = atom_getintarg(1, argc, argv);
xx = x->x_radius / 6.0f;
x->x_radius = (int)(xx + 0.4999f);
x->x_radius *= 3;
if(x->x_radius < 9)
x->x_radius = 9;
if(x->x_radius > 1800)
x->x_radius = 1800;
}
if(argc == (3*n + 5))
{
x->x_radius = atom_getintarg(1, argc, argv);
x->x_fontsize = (int)atom_getintarg(2, argc, argv);
c = (int)atom_getintarg(3, argc, argv);
x->x_gui.x_bcol = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
c = (int)atom_getintarg(4, argc, argv);
x->x_gui.x_fcol = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
for(i=0; i<n; i++)
{
c = (int)atom_getintarg(5+3*i, argc, argv);
x->x_col_src[i] = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_pix_src_x[i] = (int)atom_getintarg(6+3*i, argc, argv);
x->x_pix_src_y[i] = (int)atom_getintarg(7+3*i, argc, argv);
}
}
else
{
x->x_fontsize = 12;
x->x_gui.x_bcol = my_iemgui_color_hex[IEM_GUI_COLNR_GREEN];
x->x_gui.x_fcol = my_iemgui_color_hex[IEM_GUI_COLNR_L_GREY];
j = 0;
for(i=0; i<n; i++)
{
x->x_col_src[i] = simularca_color_hex[j];
x->x_pix_src_x[i] = x->x_radius;
x->x_pix_src_y[i] = x->x_radius;
j++;
j %= 7;
}
}
x->x_n_src = n;
for(i=0; i<n; i++)
x->x_vis_src[i] = 1;
x->x_90overradius = 90.0f / (t_float)x->x_radius;
x->x_gui.x_w = 2*x->x_radius;
x->x_gui.x_h = 2*x->x_radius;
x->x_gui.x_draw = (t_iemfunptr)cube_sphere_draw;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_out_para = outlet_new(&x->x_gui.x_obj, &s_list);
return (x);
}
static void cube_sphere_ff(t_cube_sphere *x)
{
gfxstub_deleteforkey(x);
}
void cube_sphere_setup(void)
{
cube_sphere_class = class_new(gensym("cube_sphere"), (t_newmethod)cube_sphere_new,
(t_method)cube_sphere_ff, sizeof(t_cube_sphere), 0, A_GIMME, 0);
class_addcreator((t_newmethod)cube_sphere_new, gensym("cube_sphere"), A_GIMME, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_click, gensym("click"),
A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_motion, gensym("motion"),
A_FLOAT, A_FLOAT, 0);
class_addbang(cube_sphere_class, (t_method)cube_sphere_bang);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_sphere_col, gensym("sphere_col"), A_DEFFLOAT, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_frame_col, gensym("frame_col"), A_DEFFLOAT, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_src_col, gensym("src_col"), A_GIMME, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_src_dp, gensym("src_dp"), A_GIMME, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_size, gensym("size"), A_DEFFLOAT, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_vis, gensym("vis"), A_GIMME, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_src_font, gensym("src_font"), A_DEFFLOAT, 0);
class_addmethod(cube_sphere_class, (t_method)cube_sphere_nr_src, gensym("nr_src"), A_DEFFLOAT, 0);
/* if(!iemgui_key_sym2)
iemgui_key_sym2 = gensym("#keyname");*/
cube_sphere_widgetbehavior.w_getrectfn = cube_sphere_getrect;
cube_sphere_widgetbehavior.w_displacefn = iemgui_displace;
cube_sphere_widgetbehavior.w_selectfn = iemgui_select;
cube_sphere_widgetbehavior.w_activatefn = NULL;
cube_sphere_widgetbehavior.w_deletefn = iemgui_delete;
cube_sphere_widgetbehavior.w_visfn = iemgui_vis;
cube_sphere_widgetbehavior.w_clickfn = cube_sphere_newclick;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(cube_sphere_class, cube_sphere_save);
#else
cube_sphere_widgetbehavior.w_propertiesfn = NULL;
cube_sphere_widgetbehavior.w_savefn = cube_sphere_save;
#endif
class_setwidget(cube_sphere_class, &cube_sphere_widgetbehavior);
class_sethelpsymbol(cube_sphere_class, gensym("iemhelp2/help-cube_sphere"));
}
--- NEW FILE: room_sim_3d.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include "t_tk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
#define IEM_GUI_ROOMSIM_3D_MAX_NR_SRC 30
/* ---------- room_sim_3d my gui-canvas for a window ---------------- */
t_widgetbehavior room_sim_3d_widgetbehavior;
static t_class *room_sim_3d_class;
typedef struct _room_sim_3d
{
t_iemgui x_gui;
t_float x_rho_head;
int x_fontsize;
int x_nr_src;
int x_pix_src_x[IEM_GUI_ROOMSIM_3D_MAX_NR_SRC+1];
int x_pix_src_y[IEM_GUI_ROOMSIM_3D_MAX_NR_SRC+1];
int x_pix_src_z[IEM_GUI_ROOMSIM_3D_MAX_NR_SRC+1];
int x_col_src[IEM_GUI_ROOMSIM_3D_MAX_NR_SRC+1];
int x_pos_x;
int x_pos_y;
int x_pos_z;
int x_height_z;
int x_sel_index;
int x_pix_rad;
t_float x_cnvrt_roomlx2pixh;
t_float x_r_ambi;
t_float x_room_x;
t_float x_room_y;
t_float x_room_z;
void *x_out_para;
void *x_out_rho;
t_symbol *x_s_head_xyz;
t_symbol *x_s_src_xyz;
t_atom x_at[6];
} t_room_sim_3d;
static void room_sim_3d_out_rho(t_room_sim_3d *x)
{
outlet_float(x->x_out_rho, x->x_rho_head);
}
static void room_sim_3d_out_para(t_room_sim_3d *x)
{
int i, n = x->x_nr_src;
int w2=x->x_gui.x_w/2, h2=x->x_gui.x_h/2;
SETFLOAT(x->x_at, 0.0f);
SETSYMBOL(x->x_at+1, x->x_s_head_xyz);
SETFLOAT(x->x_at+2, (t_float)(h2 - x->x_pix_src_y[0])/x->x_cnvrt_roomlx2pixh);
SETFLOAT(x->x_at+3, (t_float)(w2 - x->x_pix_src_x[0])/x->x_cnvrt_roomlx2pixh);
SETFLOAT(x->x_at+4, (t_float)(x->x_pix_src_z[0])/x->x_cnvrt_roomlx2pixh);
outlet_list(x->x_out_para, &s_list, 5, x->x_at);
for(i=1; i<=n; i++)
{
SETFLOAT(x->x_at, (t_float)i);
SETSYMBOL(x->x_at+1, x->x_s_src_xyz);
SETFLOAT(x->x_at+2, (t_float)(h2 - x->x_pix_src_y[i])/x->x_cnvrt_roomlx2pixh);
SETFLOAT(x->x_at+3, (t_float)(w2 - x->x_pix_src_x[i])/x->x_cnvrt_roomlx2pixh);
SETFLOAT(x->x_at+4, (t_float)(x->x_pix_src_z[i])/x->x_cnvrt_roomlx2pixh);
outlet_list(x->x_out_para, &s_list, 5, x->x_at);
}
}
static void room_sim_3d_draw_update(t_room_sim_3d *x, t_glist *glist)
{
if(glist_isvisible(glist))
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int dx, dy;
t_canvas *canvas=glist_getcanvas(glist);
dx = -(int)((t_float)x->x_pix_rad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
dy = -(int)((t_float)x->x_pix_rad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+dx, ypos+x->x_pix_src_y[0]+dy);
}
}
void room_sim_3d_draw_new(t_room_sim_3d *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int dx, dy;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
int rad2;
int i, n=x->x_nr_src;
int fsi, fs=x->x_fontsize;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
x->x_gui.x_bcol, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:IEM_GUI_COLOR_NORMAL, x);
for(i=1; i<=n; i++)
{
fsi = H2 + (H + 2 * x->x_pix_src_z[i]) * x->x_pix_src_z[i];
fsi *= fs;
fsi /= 2*H2;
sys_vgui(".x%x.c create text %d %d -text {%d} -anchor c \
-font {times %d bold} -fill #%6.6x -tags %xSRC%d\n",
canvas, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i], i, fsi,
x->x_col_src[i], x, i);
}
sys_vgui(".x%x.c create oval %d %d %d %d -outline #%6.6x -tags %xHEAD\n",
canvas, xpos+x->x_pix_src_x[0]-x->x_pix_rad, ypos+x->x_pix_src_y[0]-x->x_pix_rad,
xpos+x->x_pix_src_x[0]+x->x_pix_rad-1, ypos+x->x_pix_src_y[0]+x->x_pix_rad-1,
x->x_gui.x_fcol, x);
rad2 = H2 + (H + 2 * x->x_pix_src_z[0]) * x->x_pix_src_z[0];
rad2 *= x->x_pix_rad;
rad2 /= 8*H2;
sys_vgui(".x%x.c create oval %d %d %d %d -outline #%6.6x -tags %xHEAD2\n",
canvas, xpos+x->x_pix_src_x[0]-rad2, ypos+x->x_pix_src_y[0]-rad2,
xpos+x->x_pix_src_x[0]+rad2-1, ypos+x->x_pix_src_y[0]+rad2-1,
x->x_gui.x_fcol, x);
dx = -(int)((t_float)x->x_pix_rad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
dy = -(int)((t_float)x->x_pix_rad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c create line %d %d %d %d -width 3 -fill #%6.6x -tags %xNOSE\n",
canvas, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+dx, ypos+x->x_pix_src_y[0]+dy,
x->x_gui.x_fcol, x);
}
void room_sim_3d_draw_move(t_room_sim_3d *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
int dx, dy;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
int rad2;
int i, n=x->x_nr_src;
int fsi, fs=x->x_fontsize;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
n = x->x_nr_src;
for(i=1; i<=n; i++)
{
fsi = H2 + (H + 2 * x->x_pix_src_z[i]) * x->x_pix_src_z[i];
fsi *= fs;
fsi /= 2*H2;
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, i, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i]);
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, i, fsi);
}
sys_vgui(".x%x.c coords %xHEAD %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-x->x_pix_rad, ypos+x->x_pix_src_y[0]-x->x_pix_rad,
xpos+x->x_pix_src_x[0]+x->x_pix_rad-1, ypos+x->x_pix_src_y[0]+x->x_pix_rad-1);
rad2 = H2 + (H + 2 * x->x_pix_src_z[0]) * x->x_pix_src_z[0];
rad2 *= x->x_pix_rad;
rad2 /= 8*H2;
sys_vgui(".x%x.c coords %xHEAD2 %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-rad2, ypos+x->x_pix_src_y[0]-rad2,
xpos+x->x_pix_src_x[0]+rad2-1, ypos+x->x_pix_src_y[0]+rad2-1);
dx = -(int)((t_float)x->x_pix_rad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
dy = -(int)((t_float)x->x_pix_rad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+dx, ypos+x->x_pix_src_y[0]+dy);
}
void room_sim_3d_draw_erase(t_room_sim_3d* x, t_glist* glist)
{
int i, n;
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
n = x->x_nr_src;
for(i=1; i<=n; i++)
{
sys_vgui(".x%x.c delete %xSRC%d\n", canvas, x, i);
}
sys_vgui(".x%x.c delete %xHEAD\n", canvas, x);
sys_vgui(".x%x.c delete %xHEAD2\n", canvas, x);
sys_vgui(".x%x.c delete %xNOSE\n", canvas, x);
}
void room_sim_3d_draw_select(t_room_sim_3d* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
}
}
void room_sim_3d_draw(t_room_sim_3d *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
room_sim_3d_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
room_sim_3d_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
room_sim_3d_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
room_sim_3d_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
room_sim_3d_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void room_sim_3d_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_room_sim_3d *x = (t_room_sim_3d *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h;
}
static void room_sim_3d_save(t_gobj *z, t_binbuf *b)
{
t_room_sim_3d *x = (t_room_sim_3d *)z;
int i, j, c, n=x->x_nr_src;
binbuf_addv(b, "ssiis", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, gensym("room_sim_3d"));
binbuf_addv(b, "ifffi", x->x_nr_src, x->x_cnvrt_roomlx2pixh, x->x_rho_head, x->x_r_ambi, x->x_fontsize);
c = x->x_gui.x_bcol;
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "ifff", j, x->x_room_x, x->x_room_y, x->x_room_z);
c = x->x_gui.x_fcol;
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "iiii", j, x->x_pix_src_x[0], x->x_pix_src_y[0], x->x_pix_src_z[0]);
for(i=1; i<=n; i++)
{
c = x->x_col_src[i];
j = (((0xfc0000 & c) >> 6)|((0xfc00 & c) >> 4)|((0xfc & c) >> 2));
binbuf_addv(b, "iiii", j, x->x_pix_src_x[i], x->x_pix_src_y[i], x->x_pix_src_z[i]);
}
binbuf_addv(b, ";");
}
static void room_sim_3d_motion(t_room_sim_3d *x, t_floatarg dx, t_floatarg dy)
{
int i, n=x->x_nr_src;
int pixrad=x->x_pix_rad;
int sel=x->x_sel_index;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ddx, ddy;
int fs=x->x_fontsize, fsi;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
int rad2;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(x->x_gui.x_fsf.x_finemoved && (sel == 0))
{
if(x->x_gui.x_fsf.x_steady)/*alt-key, rhoy, rhox*/
{
}
else
{
x->x_rho_head -= dy;
if(x->x_rho_head <= -180.0f)
x->x_rho_head += 360.0f;
if(x->x_rho_head > 180.0f)
x->x_rho_head -= 360.0f;
room_sim_3d_out_rho(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
}
else if(sel == 0)
{
if(x->x_gui.x_fsf.x_steady)/*alt-key, move head in z*/
{
x->x_pix_src_x[0] = x->x_pos_x;
x->x_pix_src_y[0] = x->x_pos_y;
x->x_pix_src_z[0] -= (int)dy;
if(x->x_pix_src_z[0] < 0)
x->x_pix_src_z[0] = 0;
if(x->x_pix_src_z[0] > x->x_height_z)
x->x_pix_src_z[0] = x->x_height_z;
}
else
{
x->x_pix_src_z[0] = x->x_pos_z;
x->x_pos_x += (int)dx;
x->x_pos_y += (int)dy;
x->x_pix_src_x[0] = x->x_pos_x;
x->x_pix_src_y[0] = x->x_pos_y;
if(x->x_pix_src_x[0] < 0)
x->x_pix_src_x[0] = 0;
if(x->x_pix_src_x[0] > x->x_gui.x_w)
x->x_pix_src_x[0] = x->x_gui.x_w;
if(x->x_pix_src_y[0] < 0)
x->x_pix_src_y[0] = 0;
if(x->x_pix_src_y[0] > x->x_gui.x_h)
x->x_pix_src_y[0] = x->x_gui.x_h;
}
room_sim_3d_out_para(x);
sys_vgui(".x%x.c coords %xHEAD %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-pixrad, ypos+x->x_pix_src_y[0]-pixrad,
xpos+x->x_pix_src_x[0]+pixrad-1, ypos+x->x_pix_src_y[0]+pixrad-1);
rad2 = H2 + (H + 2 * x->x_pix_src_z[0]) * x->x_pix_src_z[0];
rad2 *= x->x_pix_rad;
rad2 /= 8*H2;
sys_vgui(".x%x.c coords %xHEAD2 %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-rad2, ypos+x->x_pix_src_y[0]-rad2,
xpos+x->x_pix_src_x[0]+rad2-1, ypos+x->x_pix_src_y[0]+rad2-1);
ddx = -(int)((t_float)pixrad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
ddy = -(int)((t_float)pixrad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+ddx, ypos+x->x_pix_src_y[0]+ddy);
}
else
{
if(x->x_gui.x_fsf.x_steady)/*alt-key, move src in z*/
{
x->x_pix_src_z[sel] -= (int)dy;
if(x->x_pix_src_z[sel] < 0)
x->x_pix_src_z[sel] = 0;
if(x->x_pix_src_z[sel] > x->x_height_z)
x->x_pix_src_z[sel] = x->x_height_z;
room_sim_3d_out_para(x);
fsi = H2 + (H + 2 * x->x_pix_src_z[sel]) * x->x_pix_src_z[sel];
fsi *= fs;
fsi /= 2*H2;
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, sel, fsi);
}
else
{
x->x_pos_x += (int)dx;
x->x_pos_y += (int)dy;
x->x_pix_src_x[sel] = x->x_pos_x;
x->x_pix_src_y[sel] = x->x_pos_y;
x->x_pix_src_z[sel] = x->x_pos_z;
if(x->x_pix_src_x[sel] < 0)
x->x_pix_src_x[sel] = 0;
if(x->x_pix_src_x[sel] > x->x_gui.x_w)
x->x_pix_src_x[sel] = x->x_gui.x_w;
if(x->x_pix_src_y[sel] < 0)
x->x_pix_src_y[sel] = 0;
if(x->x_pix_src_y[sel] > x->x_gui.x_h)
x->x_pix_src_y[sel] = x->x_gui.x_h;
room_sim_3d_out_para(x);
fsi = H2 + (H + 2 * x->x_pix_src_z[sel]) * x->x_pix_src_z[sel];
fsi *= fs;
fsi /= 2*H2;
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, sel, xpos+x->x_pix_src_x[sel], ypos+x->x_pix_src_y[sel]);
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, sel, fsi);
}
}
}
static void room_sim_3d_click(t_room_sim_3d *x, t_floatarg xpos, t_floatarg ypos,
t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
int w = (int)xpos - text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int h = (int)ypos - text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int i, n=x->x_nr_src;
int pixrad=x->x_pix_rad;
int fs=x->x_fontsize, fsi;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
int diff, maxdiff=10000, sel=-1;
i = 0;/* head */
if((w >= (x->x_pix_src_x[i]-pixrad)) && (w <= (x->x_pix_src_x[i]+pixrad)) && (h >= (x->x_pix_src_y[i]-pixrad)) && (h <= (x->x_pix_src_y[i]+pixrad)))
{
diff = w - x->x_pix_src_x[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
diff = h - x->x_pix_src_y[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
}
for(i=1; i<=n; i++)
{
fsi = H2 + (H + 2 * x->x_pix_src_z[i]) * x->x_pix_src_z[i];
fsi *= fs;
fsi /= 2*H2;
if(fsi < fs)
fsi = fs;
fsi *= 2;
fsi /= 3;
if((w >= (x->x_pix_src_x[i]-fsi)) && (w <= (x->x_pix_src_x[i]+fsi)) &&
(h >= (x->x_pix_src_y[i]-fsi)) && (h <= (x->x_pix_src_y[i]+fsi)))
{
diff = w - x->x_pix_src_x[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
diff = h - x->x_pix_src_y[i];
if(diff < 0)
diff *= -1;
if(diff < maxdiff)
{
maxdiff = diff;
sel = i;
}
}
}
if(sel >= 0)
{
x->x_sel_index = sel;
x->x_pos_x = x->x_pix_src_x[sel];
x->x_pos_y = x->x_pix_src_y[sel];
x->x_pos_z = x->x_pix_src_z[sel];
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g, (t_glistmotionfn)room_sim_3d_motion, 0, xpos, ypos);
}
}
static int room_sim_3d_newclick(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_room_sim_3d* x = (t_room_sim_3d *)z;
if(doit)
{
room_sim_3d_click( x, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
if(alt)
x->x_gui.x_fsf.x_steady = 1;
else
x->x_gui.x_fsf.x_steady = 0;
if(shift)
{
x->x_gui.x_fsf.x_finemoved = 1;
room_sim_3d_out_rho(x);
}
else
{
x->x_gui.x_fsf.x_finemoved = 0;
room_sim_3d_out_para(x);
}
}
return (1);
}
static void room_sim_3d_bang(t_room_sim_3d *x)
{
room_sim_3d_out_para(x);
room_sim_3d_out_rho(x);
}
static void room_sim_3d_src_font(t_room_sim_3d *x, t_floatarg ff)
{
int fs=(int)(ff + 0.49999f), fsi;
int i, n=x->x_nr_src;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(fs < 8)
fs = 8;
if(fs > 250)
fs = 250;
x->x_fontsize = fs;
for(i=1; i<=n; i++)
{
fsi = H2 + (H + 2 * x->x_pix_src_z[i]) * x->x_pix_src_z[i];
fsi *= fs;
fsi /= 2*H2;
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, i, fsi);
}
}
static void room_sim_3d_set_rho(t_room_sim_3d *x, t_floatarg rhoz)
{
while(rhoz <= -180.0f)
rhoz += 360.0f;
while(rhoz > 180.0f)
rhoz -= 360.0f;
x->x_rho_head = rhoz;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
static void room_sim_3d_rho(t_room_sim_3d *x, t_floatarg rhoz)
{
room_sim_3d_set_rho(x, rhoz);
room_sim_3d_out_rho(x);
}
static void room_sim_3d_set_src_xyz(t_room_sim_3d *x, t_symbol *s, int argc, t_atom *argv)
{
t_float xsrc, ysrc, zsrc;
t_float roomx2=0.5f*x->x_room_x, roomy2=0.5f*x->x_room_y, roomz=x->x_room_z;
int i, n=x->x_nr_src;
int pixrad=x->x_pix_rad;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int w2=x->x_gui.x_w/2, h2=x->x_gui.x_h/2;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
int fsi, fs=x->x_fontsize;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(argc < 4)
{
post("room_sim_3d ERROR: src_xyz-input needs 1 index + 3 float-dimensions: src_index, x [m], y [m], z [m]");
return;
}
i = (int)atom_getint(argv++);
if((i > 0)&&(i <= n))
{
ysrc = atom_getfloat(argv++);
xsrc = atom_getfloat(argv++);
zsrc = atom_getfloat(argv);
if(xsrc < -roomy2)
xsrc = -roomy2;
if(xsrc > roomy2)
xsrc = roomy2;
if(ysrc < -roomx2)
ysrc = -roomx2;
if(ysrc > roomx2)
ysrc = roomx2;
if(zsrc < 0.0f)
zsrc = 0.0f;
if(zsrc > roomz)
zsrc = roomz;
x->x_pix_src_x[i] = w2 - (int)(x->x_cnvrt_roomlx2pixh * xsrc + 0.49999f);
x->x_pix_src_y[i] = h2 - (int)(x->x_cnvrt_roomlx2pixh * ysrc + 0.49999f);
x->x_pix_src_z[i] = (int)(x->x_cnvrt_roomlx2pixh * zsrc + 0.49999f);
fsi = H2 + (H + 2 * x->x_pix_src_z[i]) * x->x_pix_src_z[i];
fsi *= fs;
fsi /= 2*H2;
sys_vgui(".x%x.c coords %xSRC%d %d %d\n",
canvas, x, i, xpos+x->x_pix_src_x[i], ypos+x->x_pix_src_y[i]);
sys_vgui(".x%x.c itemconfigure %xSRC%d -font {times %d bold}\n", canvas, x, i, fsi);
}
}
static void room_sim_3d_src_xyz(t_room_sim_3d *x, t_symbol *s, int argc, t_atom *argv)
{
room_sim_3d_set_src_xyz(x, s, argc, argv);
room_sim_3d_out_para(x);
}
static void room_sim_3d_set_head_xyz(t_room_sim_3d *x, t_symbol *s, int argc, t_atom *argv)
{
t_float roomx2=0.5f*x->x_room_x, roomy2=0.5f*x->x_room_y, roomz=x->x_room_z;
int pixrad=x->x_pix_rad;
int xpos=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ypos=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
int ddx, ddy;
int H=(int)(0.5f * x->x_room_z * x->x_cnvrt_roomlx2pixh + 0.49999f);
int H2=H*H;
int rad2;
t_float xh, yh, zh;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(argc < 3)
{
post("room_sim_3d ERROR: head_xyz-input needs 3 float-dimensions: x [m], y [m], z [m]");
return;
}
yh = atom_getfloat(argv++);
xh = atom_getfloat(argv++);
zh = atom_getfloat(argv);
if(xh < -roomy2)
xh = -roomy2;
if(xh > roomy2)
xh = roomy2;
if(yh < -roomx2)
yh = -roomx2;
if(yh > roomx2)
yh = roomx2;
if(zh < 0.0f)
zh = 0.0f;
if(zh > roomz)
zh = roomz;
x->x_pix_src_x[0] = x->x_gui.x_w/2 - (int)(x->x_cnvrt_roomlx2pixh * xh + 0.49999f);
x->x_pix_src_y[0] = x->x_gui.x_h/2 - (int)(x->x_cnvrt_roomlx2pixh * yh + 0.49999f);
x->x_pix_src_z[0] = (int)(x->x_cnvrt_roomlx2pixh * zh + 0.49999f);
sys_vgui(".x%x.c coords %xHEAD %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-pixrad, ypos+x->x_pix_src_y[0]-pixrad,
xpos+x->x_pix_src_x[0]+pixrad-1, ypos+x->x_pix_src_y[0]+pixrad-1);
rad2 = H2 + (H + 2 * x->x_pix_src_z[0]) * x->x_pix_src_z[0];
rad2 *= pixrad;
rad2 /= 8*H2;
sys_vgui(".x%x.c coords %xHEAD2 %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0]-rad2, ypos+x->x_pix_src_y[0]-rad2,
xpos+x->x_pix_src_x[0]+rad2-1, ypos+x->x_pix_src_y[0]+rad2-1);
ddx = -(int)((t_float)pixrad*(t_float)sin(x->x_rho_head*0.0174533f) + 0.49999f);
ddy = -(int)((t_float)pixrad*(t_float)cos(x->x_rho_head*0.0174533f) + 0.49999f);
sys_vgui(".x%x.c coords %xNOSE %d %d %d %d\n",
canvas, x, xpos+x->x_pix_src_x[0], ypos+x->x_pix_src_y[0],
xpos+x->x_pix_src_x[0]+ddx, ypos+x->x_pix_src_y[0]+ddy);
}
static void room_sim_3d_head_xyz(t_room_sim_3d *x, t_symbol *s, int argc, t_atom *argv)
{
room_sim_3d_set_head_xyz(x, s, argc, argv);
room_sim_3d_out_para(x);
}
static void room_sim_3d_room_dim(t_room_sim_3d *x, t_symbol *s, int argc, t_atom *argv)
{
int i, n=x->x_nr_src;
if(argc < 3)
{
post("room_sim_3d ERROR: room_dim-input needs 3 float-dimensions: x-Length [m], y-Width [m], z-Height [m]");
return;
}
x->x_room_x = atom_getfloat(argv++);
x->x_room_y = atom_getfloat(argv++);
x->x_room_z = atom_getfloat(argv);
if(x->x_room_x < 1.0f)
x->x_room_x = 1.0f;
if(x->x_room_y < 1.0f)
x->x_room_y = 1.0f;
if(x->x_room_z < 1.0f)
x->x_room_z = 1.0f;
x->x_gui.x_h = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_x + 0.49999f);
x->x_gui.x_w = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_y + 0.49999f);
x->x_height_z = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_z + 0.49999f);
x->x_pix_rad = (int)(x->x_cnvrt_roomlx2pixh * x->x_r_ambi + 0.49999f);
for(i=0; i<=n; i++)
{
if(x->x_pix_src_x[i] > x->x_gui.x_w)
x->x_pix_src_x[i] = x->x_gui.x_w;
if(x->x_pix_src_y[i] > x->x_gui.x_h)
x->x_pix_src_y[i] = x->x_gui.x_h;
if(x->x_pix_src_z[i] > x->x_height_z)
x->x_pix_src_z[i] = x->x_height_z;
}
room_sim_3d_out_para(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void room_sim_3d_room_col(t_room_sim_3d *x, t_floatarg fcol)
{
int col=(int)fcol;
int i;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(col < 0)
{
i = -1 - col;
x->x_gui.x_bcol = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_gui.x_bcol = my_iemgui_color_hex[col];
}
sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol);
}
static void room_sim_3d_head_col(t_room_sim_3d *x, t_floatarg fcol)
{
int col=(int)fcol;
int i;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if(col < 0)
{
i = -1 - col;
x->x_gui.x_fcol = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_gui.x_fcol = my_iemgui_color_hex[col];
}
sys_vgui(".x%x.c itemconfigure %xHEAD -outline #%6.6x\n", canvas, x, x->x_gui.x_fcol);
sys_vgui(".x%x.c itemconfigure %xHEAD2 -outline #%6.6x\n", canvas, x, x->x_gui.x_fcol);
sys_vgui(".x%x.c itemconfigure %xNOSE -fill #%6.6x\n", canvas, x, x->x_gui.x_fcol);
}
static void room_sim_3d_src_col(t_room_sim_3d *x, t_symbol *s, int argc, t_atom *argv)
{
int col;
int i, j, n=x->x_nr_src;
t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist);
if((argc >= 2)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1))
{
j = (int)atom_getintarg(0, argc, argv);
if((j > 0)&&(j <= n))
{
col = (int)atom_getintarg(1, argc, argv);
if(col < 0)
{
i = -1 - col;
x->x_col_src[j] = ((i & 0x3f000) << 6)|((i & 0xfc0) << 4)|((i & 0x3f) << 2);
}
else
{
if(col > 29)
col = 29;
x->x_col_src[j] = my_iemgui_color_hex[col];
}
sys_vgui(".x%x.c itemconfigure %xSRC%d -fill #%6.6x\n", canvas, x, j, x->x_col_src[j]);
}
}
}
static void room_sim_3d_pix_per_m_ratio(t_room_sim_3d *x, t_floatarg ratio)
{
t_float rr;
int i, n=x->x_nr_src;
if(ratio < 1.0f)
ratio = 1.0f;
if(ratio > 200.0f)
ratio = 200.0f;
rr = ratio / x->x_cnvrt_roomlx2pixh;
x->x_cnvrt_roomlx2pixh = ratio;
x->x_gui.x_w = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_y + 0.49999f);
x->x_gui.x_h = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_x + 0.49999f);
x->x_height_z = (int)(x->x_cnvrt_roomlx2pixh * x->x_room_z + 0.49999f);
x->x_pix_rad = (int)(x->x_cnvrt_roomlx2pixh * x->x_r_ambi + 0.49999f);
for(i=0; i<=n; i++)
{
x->x_pix_src_x[i] = (int)((t_float)x->x_pix_src_x[i]*rr + 0.49999f);
x->x_pix_src_y[i] = (int)((t_float)x->x_pix_src_y[i]*rr + 0.49999f);
x->x_pix_src_z[i] = (int)((t_float)x->x_pix_src_z[i]*rr + 0.49999f);
}
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void room_sim_3d_r_ambi(t_room_sim_3d *x, t_floatarg r_ambi)
{
if(r_ambi < 0.1f)
r_ambi = 0.1f;
x->x_r_ambi = r_ambi;
x->x_pix_rad = (int)(x->x_cnvrt_roomlx2pixh*r_ambi + 0.49999f);
room_sim_3d_out_para(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
}
static void room_sim_3d_nr_src(t_room_sim_3d *x, t_floatarg fnr_src)
{
int nr_src = (int)fnr_src;
int old_nr_src, i, j;
if(nr_src < 1)
nr_src = 1;
else if(nr_src > IEM_GUI_ROOMSIM_3D_MAX_NR_SRC)
nr_src = IEM_GUI_ROOMSIM_3D_MAX_NR_SRC;
if(nr_src != x->x_nr_src)
{
if(glist_isvisible(x->x_gui.x_glist))
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
old_nr_src = x->x_nr_src;
x->x_nr_src = nr_src;
j = (old_nr_src + 1) % 7;
for(i=old_nr_src+1; i<=nr_src; i++)
{
x->x_col_src[i] = simularca_color_hex[j];
if(i & 1)
x->x_pix_src_x[i] = 125 + (IEM_GUI_ROOMSIM_3D_MAX_NR_SRC - i)*4;
else
x->x_pix_src_x[i] = 125 - (IEM_GUI_ROOMSIM_3D_MAX_NR_SRC - i)*4;
x->x_pix_src_y[i] = 100;
x->x_pix_src_z[i] = 42;
j++;
j %= 7;
}
if(glist_isvisible(x->x_gui.x_glist))
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
static void *room_sim_3d_new(t_symbol *s, int argc, t_atom *argv)
{
t_room_sim_3d *x = (t_room_sim_3d *)pd_new(room_sim_3d_class);
int i, j, n=1, c;
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
n = (int)atom_getintarg(0, argc, argv);
if(n < 1)
n = 1;
if(n > IEM_GUI_ROOMSIM_3D_MAX_NR_SRC)
n = IEM_GUI_ROOMSIM_3D_MAX_NR_SRC;
x->x_nr_src = n;
}
if(argc == (4*n + 13))
{
x->x_cnvrt_roomlx2pixh = atom_getfloatarg(1, argc, argv);
x->x_rho_head = atom_getfloatarg(2, argc, argv);
x->x_r_ambi = atom_getfloatarg(3, argc, argv);
x->x_fontsize = (int)atom_getintarg(4, argc, argv);
c = (int)atom_getintarg(5, argc, argv);
x->x_gui.x_bcol = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_room_x = atom_getfloatarg(6, argc, argv);
x->x_room_y = atom_getfloatarg(7, argc, argv);
x->x_room_z = atom_getfloatarg(8, argc, argv);
c = (int)atom_getintarg(9, argc, argv);
x->x_gui.x_fcol = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_pix_src_x[0] = (int)atom_getintarg(10, argc, argv);
x->x_pix_src_y[0] = (int)atom_getintarg(11, argc, argv);
x->x_pix_src_z[0] = (int)atom_getintarg(12, argc, argv);
j = 13;
for(i=1; i<=n; i++)
{
c = (int)atom_getintarg(j, argc, argv);
j++;
x->x_col_src[i] = ((c & 0x3f000) << 6)|((c & 0xfc0) << 4)|((c & 0x3f) << 2);
x->x_pix_src_x[i] = (int)atom_getintarg(j, argc, argv);
j++;
x->x_pix_src_y[i] = (int)atom_getintarg(j, argc, argv);
j++;
x->x_pix_src_z[i] = (int)atom_getintarg(j, argc, argv);
j++;
}
}
else
{
x->x_cnvrt_roomlx2pixh = 25.0f;
x->x_rho_head = 0.0f;
x->x_r_ambi = 1.4f;
x->x_fontsize = 12;
x->x_gui.x_bcol = my_iemgui_color_hex[IEM_GUI_COLNR_GREEN];
x->x_room_x = 12.0f;
x->x_room_y = 10.0f;
x->x_room_z = 5.0f;
x->x_gui.x_fcol = my_iemgui_color_hex[IEM_GUI_COLNR_D_ORANGE];
x->x_pix_src_x[0] = 125;
x->x_pix_src_y[0] = 200;
x->x_pix_src_z[0] = 42;
j = 0;
for(i=1; i<=n; i++)
{
x->x_col_src[i] = simularca_color_hex[j];
if(i & 1)
x->x_pix_src_x[i] = 125 + (IEM_GUI_ROOMSIM_3D_MAX_NR_SRC - i)*4;
else
x->x_pix_src_x[i] = 125 - (IEM_GUI_ROOMSIM_3D_MAX_NR_SRC - i)*4;
x->x_pix_src_y[i] = 100;
x->x_pix_src_z[i] = 42;
j++;
j %= 7;
}
}
x->x_gui.x_w = (int)(x->x_room_y*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_gui.x_h = (int)(x->x_room_x*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_height_z = (int)(x->x_room_z*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_pix_rad = (int)(x->x_r_ambi*x->x_cnvrt_roomlx2pixh + 0.49999f);
x->x_gui.x_draw = (t_iemfunptr)room_sim_3d_draw;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_out_para = outlet_new(&x->x_gui.x_obj, &s_list);
x->x_out_rho = outlet_new(&x->x_gui.x_obj, &s_float);
x->x_s_head_xyz = gensym("head_xyz");
x->x_s_src_xyz = gensym("src_xyz");
return (x);
}
static void room_sim_3d_ff(t_room_sim_3d *x)
{
gfxstub_deleteforkey(x);
}
void room_sim_3d_setup(void)
{
room_sim_3d_class = class_new(gensym("room_sim_3d"), (t_newmethod)room_sim_3d_new,
(t_method)room_sim_3d_ff, sizeof(t_room_sim_3d), 0, A_GIMME, 0);
class_addcreator((t_newmethod)room_sim_3d_new, gensym("room_sim_3d"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_click, gensym("click"),
A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_motion, gensym("motion"),
A_FLOAT, A_FLOAT, 0);
class_addbang(room_sim_3d_class, (t_method)room_sim_3d_bang);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_room_dim, gensym("room_dim"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_r_ambi, gensym("r_ambi"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_room_col, gensym("room_col"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_head_col, gensym("head_col"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_src_col, gensym("src_col"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_rho, gensym("rho"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_src_xyz, gensym("src_xyz"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_head_xyz, gensym("head_xyz"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_set_rho, gensym("set_rho"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_set_src_xyz, gensym("set_src_xyz"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_set_head_xyz, gensym("set_head_xyz"), A_GIMME, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_pix_per_m_ratio, gensym("pix_per_m_ratio"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_src_font, gensym("src_font"), A_DEFFLOAT, 0);
class_addmethod(room_sim_3d_class, (t_method)room_sim_3d_nr_src, gensym("nr_src"), A_DEFFLOAT, 0);
room_sim_3d_widgetbehavior.w_getrectfn = room_sim_3d_getrect;
room_sim_3d_widgetbehavior.w_displacefn = iemgui_displace;
room_sim_3d_widgetbehavior.w_selectfn = iemgui_select;
room_sim_3d_widgetbehavior.w_activatefn = NULL;
room_sim_3d_widgetbehavior.w_deletefn = iemgui_delete;
room_sim_3d_widgetbehavior.w_visfn = iemgui_vis;
room_sim_3d_widgetbehavior.w_clickfn = room_sim_3d_newclick;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(room_sim_3d_class, room_sim_3d_save);
#else
room_sim_3d_widgetbehavior.w_propertiesfn = NULL;
room_sim_3d_widgetbehavior.w_savefn = room_sim_3d_save;
#endif
class_setwidget(room_sim_3d_class, &room_sim_3d_widgetbehavior);
class_sethelpsymbol(room_sim_3d_class, gensym("iemhelp2/help-room_sim_3d"));
}
--- NEW FILE: hfadr_scale.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include <string.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
/* ------------------------ setup routine ------------------------- */
t_widgetbehavior hfadr_scale_widgetbehavior;
static t_class *hfadr_scale_class;
typedef struct _hfadr_scale
{
t_iemgui x_gui;
char x_gif[870];
} t_hfadr_scale;
static void hfadr_scale_draw_new(t_hfadr_scale *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui("image create photo %xPHOTOIMAGE -format gif -data {%s} -width %d -height %d\n",
x, x->x_gif, x->x_gui.x_w, x->x_gui.x_h);
sys_vgui(".x%x.c create image %d %d -image %xPHOTOIMAGE -tags %xPHOTO\n",
canvas, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2-1, x, x);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos-1, ypos+1,
xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h,
IEM_GUI_COLOR_SELECTED, x);
}
static void hfadr_scale_draw_move(t_hfadr_scale *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xPHOTO %d %d\n",
canvas, x, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2-1);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos-1, ypos+1,
xpos + x->x_gui.x_w-1, ypos + x->x_gui.x_h);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void hfadr_scale_draw_erase(t_hfadr_scale* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
sys_vgui("image delete %xPHOTOIMAGE\n", x);
sys_vgui(".x%x.c delete %xPHOTO\n", canvas, x);
}
static void hfadr_scale_draw_select(t_hfadr_scale* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos-1, ypos+1, xpos + x->x_gui.x_w-1,
ypos + x->x_gui.x_h, IEM_GUI_COLOR_SELECTED, x);
}
else
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
}
static void hfadr_scale_draw(t_hfadr_scale *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
hfadr_scale_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
hfadr_scale_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
hfadr_scale_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
hfadr_scale_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void hfadr_scale_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_hfadr_scale *x = (t_hfadr_scale *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist)-1;
*yp1 = text_ypix(&x->x_gui.x_obj, glist)+1;
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h-1;
}
static void hfadr_scale_color(t_hfadr_scale *x, t_symbol *s, int argc, t_atom *argv)
{
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
int j, i = (int)atom_getintarg(0, argc, argv);
if(i >= 0)
{
j = iemgui_modulo_color(i);
x->x_gui.x_lcol = my_iemgui_color_hex[j];
}
else
x->x_gui.x_lcol = (-1 - i) & 0xffffff;
my_iemgui_change_scale_col(x->x_gif, x->x_gui.x_lcol);
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui("%xPHOTOIMAGE configure -data {%s}\n", x, x->x_gif);
}
}
static void hfadr_scale_save(t_gobj *z, t_binbuf *b)
{
t_hfadr_scale *x = (t_hfadr_scale *)z;
binbuf_addv(b, "ssiisi", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("hfadr_scale"), -1 - (((0xfc0000 & x->x_gui.x_lcol) >> 6)|
((0xfc00 & x->x_gui.x_lcol) >> 4)|((0xfc & x->x_gui.x_lcol) >> 2)));
binbuf_addv(b, ";");
}
static void *hfadr_scale_new(t_symbol *s, int argc, t_atom *argv)
{
t_hfadr_scale *x = (t_hfadr_scale *)pd_new(hfadr_scale_class);
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
int j, i = (int)atom_getintarg(0, argc, argv);
if(i >= 0)
{
j = iemgui_modulo_color(i);
x->x_gui.x_lcol = my_iemgui_color_hex[j];
}
else
{
j = -1 - i;
x->x_gui.x_lcol = ((j & 0x3f000) << 6)|((j & 0xfc0) << 4)|((j & 0x3f) << 2);
}
}
else
x->x_gui.x_lcol = 0;
x->x_gui.x_draw = (t_iemfunptr)hfadr_scale_draw;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_gui.x_w = 126;
x->x_gui.x_h = 21;
strcpy(x->x_gif, my_iemgui_black_hrscale_gif);
my_iemgui_change_scale_col(x->x_gif, x->x_gui.x_lcol);
x->x_gui.x_fsf.x_selected = 0;
return(x);
}
static void hfadr_scale_ff(t_hfadr_scale *x)
{
gfxstub_deleteforkey(x);
}
void hfadr_scale_setup(void)
{
hfadr_scale_class = class_new(gensym("hfadr_scale"), (t_newmethod)hfadr_scale_new,
(t_method)hfadr_scale_ff, sizeof(t_hfadr_scale), 0, A_GIMME, 0);
class_addmethod(hfadr_scale_class, (t_method)hfadr_scale_color, gensym("color"), A_GIMME, 0);
hfadr_scale_widgetbehavior.w_getrectfn = hfadr_scale_getrect;
hfadr_scale_widgetbehavior.w_displacefn = iemgui_displace;
hfadr_scale_widgetbehavior.w_selectfn = iemgui_select;
hfadr_scale_widgetbehavior.w_activatefn = NULL;
hfadr_scale_widgetbehavior.w_deletefn = iemgui_delete;
hfadr_scale_widgetbehavior.w_visfn = iemgui_vis;
hfadr_scale_widgetbehavior.w_clickfn = NULL;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(hfadr_scale_class, hfadr_scale_save);
#else
hfadr_scale_widgetbehavior.w_propertiesfn = NULL;
hfadr_scale_widgetbehavior.w_savefn = hfadr_scale_save;
#endif
class_setwidget(hfadr_scale_class, &hfadr_scale_widgetbehavior);
class_sethelpsymbol(hfadr_scale_class, gensym("iemhelp2/help-hfadr_scale"));
}
--- NEW FILE: iem_event.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include "t_tk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
#define IEM_GUI_IVNT_COLOR_SELECTED "#0000FF"
#define IEM_GUI_IVNT_COLOR_NORMAL "#000000"
/* ---------- iem_event ---------------- */
t_widgetbehavior iem_event_widgetbehavior;
static t_class *iem_event_class;
typedef struct _iem_event
{
t_iemgui x_gui;
t_int x_x;
t_int x_y;
t_int x_doit;
t_symbol *x_mouse_shft_alt;
t_symbol *x_dragg_x_y;
t_symbol *x_key;
t_symbol *x_move_x_y;
t_atom x_at_out[3];
} t_iem_event;
static void iem_event_key(void *z, t_floatarg fkey);
t_widgetbehavior iem_event_widgetbehavior;
static t_class *iem_event_class;
static void iem_event_draw_new(t_iem_event *x, t_glist *glist)
{
t_int xpos=text_xpix(&x->x_gui.x_obj, glist);
t_int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline %s -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h, IEM_GUI_IVNT_COLOR_SELECTED, x);
}
static void iem_event_draw_move(t_iem_event *x, t_glist *glist)
{
t_int xpos=text_xpix(&x->x_gui.x_obj, glist);
t_int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
}
static void iem_event_draw_erase(t_iem_event* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
}
static void iem_event_draw_select(t_iem_event *x, t_glist *glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
t_int xpos=text_xpix(&x->x_gui.x_obj, glist);
t_int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline %s -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h, IEM_GUI_IVNT_COLOR_SELECTED, x);
}
else
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
}
void iem_event_draw(t_iem_event *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
iem_event_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
iem_event_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
iem_event_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
iem_event_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void iem_event_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_iem_event *x = (t_iem_event *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h;
}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void iem_event_save(t_gobj *z, t_binbuf *b)
{
t_iem_event *x = (t_iem_event *)z;
t_symbol *srl[3];
srl[0] = x->x_gui.x_snd;
srl[1] = x->x_gui.x_rcv;
srl[2] = gensym("empty");
iemgui_all_sym2dollararg(&x->x_gui, srl);
binbuf_addv(b, "ssiisiiiiss", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("ivnt"), x->x_gui.x_w, x->x_gui.x_h,
iem_symargstoint(&x->x_gui.x_isa), iem_fstyletoint(&x->x_gui.x_fsf),
srl[0], srl[1]);
binbuf_addv(b, ";");
}
#else
static void iem_event_save(t_gobj *z, t_binbuf *b)
{
t_iem_event *x = (t_iem_event *)z;
int *ip1, *ip2;
t_symbol *srl[3];
srl[0] = x->x_gui.x_snd;
srl[1] = x->x_gui.x_rcv;
srl[2] = gensym("empty");
iemgui_all_unique2dollarzero(&x->x_gui, srl);
iemgui_all_sym2dollararg(&x->x_gui, srl);
ip1 = (int *)(&x->x_gui.x_isa);
ip2 = (int *)(&x->x_gui.x_fsf);
binbuf_addv(b, "ssiisiiiiss", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("ivnt"), x->x_gui.x_w, x->x_gui.x_h,
(*ip1)&IEM_INIT_ARGS_ALL, (*ip2)&IEM_FSTYLE_FLAGS_ALL,
srl[0], srl[1]);
binbuf_addv(b, ";");
}
#endif
static void iem_event_motion(t_iem_event *x, t_floatarg dx, t_floatarg dy)
{
x->x_x += (t_int)dx;
x->x_y -= (t_int)dy;
SETFLOAT(x->x_at_out, (t_float)x->x_x);
SETFLOAT(x->x_at_out+1, (t_float)x->x_y);
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_dragg_x_y, 2, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_dragg_x_y, 2, x->x_at_out);
}
static void iem_event_key(void *z, t_floatarg fkey)
{
t_iem_event *x = z;
char c = (char)fkey;
if(x->x_gui.x_fsf.x_change)
{
if((c==0))
{
x->x_gui.x_fsf.x_change = 0;
}
else if((c=='\n')||(c==13))
{
x->x_gui.x_fsf.x_change = 0;
SETFLOAT(x->x_at_out, 0.0f);
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_key, 1, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_key, 1, x->x_at_out);
}
else if((c=='\b')||(c==127))
{
SETFLOAT(x->x_at_out, 127.0f);
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_key, 1, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_key, 1, x->x_at_out);
}
else
{
SETFLOAT(x->x_at_out, fkey);
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_key, 1, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_key, 1, x->x_at_out);
}
}
}
static int iem_event_click(t_gobj *z, struct _glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
t_iem_event* x = (t_iem_event *)z;
t_int xpos=text_xpix(&x->x_gui.x_obj, glist);
t_int ypos=text_ypix(&x->x_gui.x_obj, glist);
if(doit != x->x_doit)
{
SETFLOAT(x->x_at_out, (t_float)doit);
SETFLOAT(x->x_at_out+1, (t_float)shift);
SETFLOAT(x->x_at_out+2, (t_float)(alt?1:0));
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_mouse_shft_alt, 3, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_mouse_shft_alt, 3, x->x_at_out);
if(doit)
x->x_gui.x_fsf.x_change = 1;
x->x_doit = doit;
}
x->x_x = xpix - xpos;
x->x_y = x->x_gui.x_h - (ypix - ypos);
SETFLOAT(x->x_at_out, (t_float)x->x_x);
SETFLOAT(x->x_at_out+1, (t_float)x->x_y);
if(doit)
{
glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
(t_glistmotionfn)iem_event_motion, iem_event_key, (t_float)xpix, (t_float)ypix);
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_dragg_x_y, 2, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_dragg_x_y, 2, x->x_at_out);
}
else
{
outlet_anything(x->x_gui.x_obj.ob_outlet, x->x_move_x_y, 2, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, x->x_move_x_y, 2, x->x_at_out);
}
return (1);
}
/*static void iem_event_bang(t_iem_event *x)
{
outlet_anything(x->x_gui.x_obj.ob_outlet, atom_getsymbol(x->x_matrix), x->x_n_row*x->x_n_column+2, x->x_matrix+1);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
typedmess(x->x_gui.x_snd->s_thing, atom_getsymbol(x->x_matrix), x->x_n_row*x->x_n_column+2, x->x_matrix+1);
}*/
static void iem_event_delta(t_iem_event *x, t_symbol *s, int ac, t_atom *av)
{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
static void iem_event_pos(t_iem_event *x, t_symbol *s, int ac, t_atom *av)
{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
static void iem_event_size(t_iem_event *x, t_symbol *s, int ac, t_atom *av)
{
int h, w;
if((ac >= 2)&&IS_A_FLOAT(av, 0) && IS_A_FLOAT(av, 1))
{
w = (int)atom_getintarg(0, ac, av);
if(w < 4)
w = 4;
x->x_gui.x_w = w;
if(ac > 1)
{
h = (int)atom_getintarg(1, ac, av);
if(h < 4)
h = 4;
x->x_gui.x_h = h;
}
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}
static void iem_event_send(t_iem_event *x, t_symbol *s)
{iemgui_send(x, &x->x_gui, s);}
static void iem_event_receive(t_iem_event *x, t_symbol *s)
{iemgui_receive(x, &x->x_gui, s);}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void *iem_event_new(t_symbol *s, int argc, t_atom *argv)
{
t_iem_event *x = (t_iem_event *)pd_new(iem_event_class);
t_int w=32, h=32;
x->x_gui.x_snd = gensym("empty");
x->x_gui.x_rcv = gensym("empty");
x->x_gui.x_lab = gensym("empty");
x->x_gui.x_fsf.x_font_style = 0;
if((argc >= 6)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
&&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
&&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
&&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5)))
{
w = (int)atom_getintarg(0, argc, argv);
h = (int)atom_getintarg(1, argc, argv);
iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv));
iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(3, argc, argv));
iemgui_new_getnames(&x->x_gui, 4, argv);
}
else if((argc >= 2)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1))
{
w = (int)atom_getintarg(0, argc, argv);
h = (int)atom_getintarg(1, argc, argv);
}
x->x_gui.x_draw = (t_iemfunptr)iem_event_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if(!strcmp(x->x_gui.x_snd->s_name, "empty"))
x->x_gui.x_fsf.x_snd_able = 0;
if(!strcmp(x->x_gui.x_rcv->s_name, "empty"))
x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
if(w < 4)
w = 4;
x->x_gui.x_w = w;
if(h < 4)
h = 4;
x->x_gui.x_h = h;
iemgui_verify_snd_ne_rcv(&x->x_gui);
outlet_new(&x->x_gui.x_obj, &s_list);
x->x_mouse_shft_alt = gensym("mouse_shft_alt");
x->x_dragg_x_y = gensym("dragg_x_y");
x->x_key = gensym("key");
x->x_move_x_y = gensym("move_x_y");
x->x_x = 0;
x->x_y = 0;
x->x_doit = 0;
return (x);
}
#else
static void *iem_event_new(t_symbol *s, int argc, t_atom *argv)
{
t_iem_event *x = (t_iem_event *)pd_new(iem_event_class);
t_int w=32, h=32;
t_int iinit=0, ifstyle=0;
t_iem_init_symargs *init=(t_iem_init_symargs *)(&iinit);
t_iem_fstyle_flags *fstyle=(t_iem_fstyle_flags *)(&ifstyle);
t_symbol *srl[3];
char str[144];
x->x_gui.x_snd = gensym("empty");
x->x_gui.x_rcv = gensym("empty");
x->x_gui.x_lab = gensym("empty");
srl[0] = gensym("empty");
srl[1] = gensym("empty");
srl[2] = gensym("empty");
x->x_gui.x_fsf.x_font_style = 0;
if((argc >= 6)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
&&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
&&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
&&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5)))
{
w = (int)atom_getintarg(0, argc, argv);
h = (int)atom_getintarg(1, argc, argv);
iinit = (int)atom_getintarg(2, argc, argv);
ifstyle = (int)atom_getintarg(3, argc, argv);
if(IS_A_SYMBOL(argv,4))
srl[0] = atom_getsymbolarg(4, argc, argv);
else if(IS_A_FLOAT(argv,4))
{
sprintf(str, "%d", (int)atom_getintarg(4, argc, argv));
srl[0] = gensym(str);
}
if(IS_A_SYMBOL(argv,5))
srl[1] = atom_getsymbolarg(5, argc, argv);
else if(IS_A_FLOAT(argv,5))
{
sprintf(str, "%d", (int)atom_getintarg(5, argc, argv));
srl[1] = gensym(str);
}
}
else if((argc >= 2)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1))
{
w = (int)atom_getintarg(0, argc, argv);
h = (int)atom_getintarg(1, argc, argv);
}
iinit &= IEM_INIT_ARGS_ALL;
ifstyle &= IEM_FSTYLE_FLAGS_ALL;
x->x_gui.x_draw = (t_iemfunptr)iem_event_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
fstyle->x_snd_able = 1;
fstyle->x_rcv_able = 1;
if(!strcmp(srl[0]->s_name, "empty"))
fstyle->x_snd_able = 0;
if(!strcmp(srl[1]->s_name, "empty"))
fstyle->x_rcv_able = 0;
x->x_gui.x_unique_num = 0;
x->x_gui.x_fsf = *fstyle;
x->x_gui.x_isa = *init;
iemgui_first_dollararg2sym(&x->x_gui, srl);
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
if(w < 4)
w = 4;
x->x_gui.x_w = w;
if(h < 4)
h = 4;
x->x_gui.x_h = h;
iemgui_verify_snd_ne_rcv(&x->x_gui);
outlet_new(&x->x_gui.x_obj, &s_list);
x->x_mouse_shft_alt = gensym("mouse_shft_alt");
x->x_dragg_x_y = gensym("dragg_x_y");
x->x_key = gensym("key");
x->x_move_x_y = gensym("move_x_y");
x->x_x = 0;
x->x_y = 0;
x->x_doit = 0;
return (x);
}
#endif
static void iem_event_free(t_iem_event *x)
{
if(x->x_gui.x_fsf.x_rcv_able)
pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
gfxstub_deleteforkey(x);
}
void iem_event_setup(void)
{
iem_event_class = class_new(gensym("ivnt"), (t_newmethod)iem_event_new,
(t_method)iem_event_free, sizeof(t_iem_event), 0, A_GIMME, 0);
class_addcreator((t_newmethod)iem_event_new, gensym("iem_event"),
A_GIMME, 0);
//class_addbang(iem_event_class,iem_event_bang);
class_addmethod(iem_event_class, (t_method)iem_event_motion,
gensym("motion"), A_FLOAT, A_FLOAT, 0);
class_addmethod(iem_event_class, (t_method)iem_event_size,
gensym("size"), A_GIMME, 0);
class_addmethod(iem_event_class, (t_method)iem_event_delta,
gensym("delta"), A_GIMME, 0);
class_addmethod(iem_event_class, (t_method)iem_event_pos,
gensym("pos"), A_GIMME, 0);
class_addmethod(iem_event_class, (t_method)iem_event_send,
gensym("send"), A_DEFSYM, 0);
class_addmethod(iem_event_class, (t_method)iem_event_receive,
gensym("receive"), A_DEFSYM, 0);
iem_event_widgetbehavior.w_getrectfn = iem_event_getrect;
iem_event_widgetbehavior.w_displacefn = iemgui_displace;
iem_event_widgetbehavior.w_selectfn = iemgui_select;
iem_event_widgetbehavior.w_activatefn = NULL;
iem_event_widgetbehavior.w_deletefn = iemgui_delete;
iem_event_widgetbehavior.w_visfn = iemgui_vis;
iem_event_widgetbehavior.w_clickfn = iem_event_click;
#if((PD_MAJOR_VERSION)&&(PD_MINOR_VERSION < 37))
iem_event_widgetbehavior.w_propertiesfn = NULL;
iem_event_widgetbehavior.w_savefn = iem_event_save;
#else
class_setsavefn(iem_event_class, iem_event_save);
#endif
class_setwidget(iem_event_class, &iem_event_widgetbehavior);
class_sethelpsymbol(iem_event_class, gensym("iemhelp2/help-iem_event"));
}
--- NEW FILE: sym_dial.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include "t_tk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
#define IEM_SDL_FLASH_TIME 200
t_widgetbehavior sym_dial_widgetbehavior;
static t_class *sym_dial_class;
typedef struct _sym_dial
{
t_iemgui x_gui;
t_clock *x_clock;
void *x_outlet;
int x_index;
t_symbol **x_syms;
int x_ac;
int x_max_ac;
int x_symwidth;
int x_snd_flt0_sym1;
} t_sym_dial;
/* widget helper functions */
static void sym_dial_draw_swap(t_sym_dial *x, t_glist *glist, int swap)
{
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n",
canvas, x,
swap?x->x_gui.x_fcol:x->x_gui.x_bcol);
sys_vgui(".x%x.c itemconfigure %xSYMBOL -fill #%6.6x\n",
canvas, x,
swap?x->x_gui.x_bcol:x->x_gui.x_fcol);
}
static void sym_dial_tick(t_sym_dial *x)
{
sym_dial_draw_swap(x, x->x_gui.x_glist, 0);
}
static void sym_dial_inc(t_sym_dial *x)
{
x->x_index = (x->x_index + 1) % x->x_ac;
}
void sym_dial_calc_fontwidth(t_sym_dial *x)
{
int w, f=31;
if(x->x_gui.x_fsf.x_font_style == 1)
f = 27;
else if(x->x_gui.x_fsf.x_font_style == 2)
f = 25;
w = x->x_gui.x_fontsize * f * x->x_gui.x_w;
w /= 36;
x->x_symwidth = w + (x->x_gui.x_h / 2) + 4;
}
static void sym_dial_draw_update(t_sym_dial *x, t_glist *glist)
{
if (glist_isvisible(glist))
{
char string[200];
int l;
strcpy(string, x->x_syms[x->x_index]->s_name);
l = strlen(string);
if(l > x->x_gui.x_w)
{
string[x->x_gui.x_w-1] = '~';
string[x->x_gui.x_w] = 0;
}
sys_vgui(".x%x.c itemconfigure %xSYMBOL -fill #%6.6x -text {%s} \n",
glist_getcanvas(glist), x,
x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
string);
}
}
static void sym_dial_draw_new(t_sym_dial *x, t_glist *glist)
{
int half=x->x_gui.x_h/2, d=x->x_gui.x_h/34;
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
char string[200];
int l;
strcpy(string, x->x_syms[x->x_index]->s_name);
l = strlen(string);
if(l > x->x_gui.x_w)
{
string[x->x_gui.x_w] = '~';
string[x->x_gui.x_w+1] = 0;
}
sys_vgui(".x%x.c create polygon %d %d %d %d %d %d %d %d %d %d %d %d -outline #%6.6x -fill #%6.6x -tags %xBASE\n",
canvas, xpos-1, ypos,
xpos + x->x_symwidth-4, ypos,
xpos + x->x_symwidth, ypos+4,
xpos + x->x_symwidth, ypos + x->x_gui.x_h,
xpos-1, ypos + x->x_gui.x_h,
xpos+half-1, ypos+half,
IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
-font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
-font {%s %d bold} -fill #%6.6x -tags %xSYMBOL\n",
canvas, xpos+half+2, ypos+half+d,
string, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
if(!x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
canvas,
xpos, ypos + x->x_gui.x_h-1,
xpos+IOWIDTH, ypos + x->x_gui.x_h,
x, 0);
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
canvas,
xpos+x->x_symwidth-IOWIDTH, ypos + x->x_gui.x_h-1,
xpos+x->x_symwidth, ypos + x->x_gui.x_h, x, 1);
}
if(!x->x_gui.x_fsf.x_rcv_able)
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
canvas, xpos, ypos, xpos+IOWIDTH, ypos+1, x, 0);
}
static void sym_dial_draw_move(t_sym_dial *x, t_glist *glist)
{
int half = x->x_gui.x_h/2, d=x->x_gui.x_h/34;
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xBASE %d %d %d %d %d %d %d %d %d %d %d %d\n",
canvas, x, xpos-1, ypos,
xpos + x->x_symwidth-4, ypos,
xpos + x->x_symwidth, ypos+4,
xpos + x->x_symwidth, ypos + x->x_gui.x_h,
xpos-1, ypos + x->x_gui.x_h,
xpos+half-1, ypos+half);
sys_vgui(".x%x.c coords %xLABEL %d %d\n",
canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
sys_vgui(".x%x.c coords %xSYMBOL %d %d\n",
canvas, x, xpos+half+2, ypos+half+d);
if(!x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
canvas, x, 0,
xpos, ypos + x->x_gui.x_h-1,
xpos+IOWIDTH, ypos + x->x_gui.x_h);
sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
canvas, x, 1,
xpos+x->x_symwidth-IOWIDTH, ypos + x->x_gui.x_h-1,
xpos+x->x_symwidth, ypos + x->x_gui.x_h);
}
if(!x->x_gui.x_fsf.x_rcv_able)
sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
canvas, x, 0,
xpos, ypos,
xpos+IOWIDTH, ypos+1);
}
static void sym_dial_draw_erase(t_sym_dial* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
sys_vgui(".x%x.c delete %xSYMBOL\n", canvas, x);
if(!x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
}
if(!x->x_gui.x_fsf.x_rcv_able)
sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
}
static void sym_dial_draw_config(t_sym_dial* x,t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
sys_vgui(".x%x.c itemconfigure %xSYMBOL -font {%s %d bold} -fill #%6.6x \n",
canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas,
x, x->x_gui.x_bcol);
}
static void sym_dial_draw_io(t_sym_dial* x,t_glist* glist, int old_snd_rcv_flags)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
canvas,
xpos, ypos + x->x_gui.x_h-1,
xpos+IOWIDTH, ypos + x->x_gui.x_h,
x, 0);
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
canvas,
xpos+x->x_symwidth-IOWIDTH, ypos + x->x_gui.x_h-1,
xpos+x->x_symwidth, ypos + x->x_gui.x_h,
x, 1);
}
if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
{
sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1);
}
if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
canvas,
xpos, ypos,
xpos+IOWIDTH, ypos+1,
x, 0);
if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
}
static void sym_dial_draw_select(t_sym_dial *x, t_glist *glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
// pd_bind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym2);
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
sys_vgui(".x%x.c itemconfigure %xSYMBOL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED);
}
else
{
// pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym2);
sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL);
sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol);
sys_vgui(".x%x.c itemconfigure %xSYMBOL -fill #%6.6x\n", canvas, x, x->x_gui.x_fcol);
}
}
void sym_dial_draw(t_sym_dial *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_UPDATE)
sym_dial_draw_update(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_MOVE)
sym_dial_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
sym_dial_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
sym_dial_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
sym_dial_draw_erase(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
sym_dial_draw_config(x, glist);
else if(mode >= IEM_GUI_DRAW_MODE_IO)
sym_dial_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
}
/* ------------------------ vsl widgetbehaviour----------------------------- */
static void sym_dial_getrect(t_gobj *z, t_glist *glist,
int *xp1, int *yp1, int *xp2, int *yp2)
{
t_sym_dial* x = (t_sym_dial*)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_symwidth;
*yp2 = *yp1 + x->x_gui.x_h;
}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void sym_dial_save(t_gobj *z, t_binbuf *b)
{
t_sym_dial *x = (t_sym_dial *)z;
int bflcol[3];
t_symbol *srl[3];
int i;
iemgui_save(&x->x_gui, srl, bflcol);
binbuf_addv(b, "ssiisiiiisssiiiiiiiii", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("sdl"), x->x_gui.x_w, x->x_gui.x_h,
iem_symargstoint(&x->x_gui.x_isa), x->x_snd_flt0_sym1,
srl[0], srl[1], srl[2],
x->x_gui.x_ldx, x->x_gui.x_ldy,
iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
bflcol[0], bflcol[1], bflcol[2],
x->x_index, x->x_ac);
for(i=0; i<x->x_ac; i++) /*16 + ac syms*/
{
binbuf_addv(b, "s", x->x_syms[i]);
}
binbuf_addv(b, ";");
}
#else
static void sym_dial_save(t_gobj *z, t_binbuf *b)
{
t_sym_dial *x = (t_sym_dial *)z;
int bflcol[3], *ip1, *ip2;
t_symbol *srl[3];
int i;
iemgui_save(&x->x_gui, srl, bflcol);
ip1 = (int *)(&x->x_gui.x_isa);
ip2 = (int *)(&x->x_gui.x_fsf);
binbuf_addv(b, "ssiisiiiisssiiiiiiiii", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("sdl"), x->x_gui.x_w, x->x_gui.x_h,
(*ip1)&IEM_INIT_ARGS_ALL, x->x_snd_flt0_sym1,
srl[0], srl[1], srl[2],
x->x_gui.x_ldx, x->x_gui.x_ldy,
(*ip2)&IEM_FSTYLE_FLAGS_ALL, x->x_gui.x_fontsize,
bflcol[0], bflcol[1], bflcol[2],
x->x_index, x->x_ac);
for(i=0; i<x->x_ac; i++) /*16 + ac syms*/
{
binbuf_addv(b, "s", x->x_syms[i]);
}
binbuf_addv(b, ";");
}
#endif
static void sym_dial_properties(t_gobj *z, t_glist *owner)
{
t_sym_dial *x = (t_sym_dial *)z;
char buf[800];
t_symbol *srl[3];
iemgui_properties(&x->x_gui, srl);
sprintf(buf, "pdtk_iemgui_dialog %%s SYM_DIAL \
-------dimensions(digits)(pix):------- %d %d width: %d %d height: \
empty 0 empty 0 empty 0 \
%d snd_flt snd_sym %d %d empty -1 \
%s %s \
%s %d %d \
%d %d \
%d %d %d\n",
x->x_gui.x_w, 1, x->x_gui.x_h, 8,
/*no_schedule*/
x->x_snd_flt0_sym1, x->x_gui.x_isa.x_loadinit, -1,/*no multi, but iem-characteristic*/
srl[0]->s_name, srl[1]->s_name,
srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol, 0xffffff & x->x_gui.x_lcol);
gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
}
static void sym_dial_out(t_sym_dial *x)
{
outlet_symbol(x->x_outlet, x->x_syms[x->x_index]);
outlet_float(x->x_gui.x_obj.ob_outlet, x->x_index);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
{
if(x->x_snd_flt0_sym1)
pd_symbol(x->x_gui.x_snd->s_thing, x->x_syms[x->x_index]);
else
pd_float(x->x_gui.x_snd->s_thing, x->x_index);
}
}
static void sym_dial_bang(t_sym_dial *x)
{
sym_dial_inc(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
sym_dial_out(x);
}
static void sym_dial_dialog(t_sym_dial *x, t_symbol *s, int argc, t_atom *argv)
{
t_symbol *srl[3];
int w = (int)atom_getintarg(0, argc, argv);
int h = (int)atom_getintarg(1, argc, argv);
int snd_fs = (int)atom_getintarg(4, argc, argv);
int sr_flags;
if(snd_fs != 0) snd_fs = 1;
x->x_snd_flt0_sym1 = snd_fs;
sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
if(w < 1)
w = 1;
x->x_gui.x_w = w;
if(h < 8)
h = 8;
x->x_gui.x_h = h;
sym_dial_calc_fontwidth(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void sym_dial_click(t_sym_dial *x, t_floatarg xpos, t_floatarg ypos, t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
sym_dial_inc(x);
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
sym_dial_draw_swap(x, x->x_gui.x_glist, 1);
clock_delay(x->x_clock, IEM_SDL_FLASH_TIME);
sym_dial_out(x);
}
static int sym_dial_newclick(t_gobj *z, struct _glist *glist,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
if(doit)
{
sym_dial_click((t_sym_dial *)z, (t_floatarg)xpix, (t_floatarg)ypix, (t_floatarg)shift, 0, (t_floatarg)alt);
}
return (1);
}
static void sym_dial_set(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{
if(ac > 0)
{
int i=0;
if(IS_A_FLOAT(av, 0))
{
i=(int)atom_getintarg(0, ac, av);
if(i < 0)
i = 0;
else if(i >= x->x_ac)
i = x->x_ac - 1;
x->x_index = i;
}
else if(IS_A_SYMBOL(av, 0))
{
t_symbol *s=atom_getsymbolarg(0, ac, av);
for(i=0; i<x->x_ac; i++)
{
if(x->x_syms[i] == s)
break;
}
x->x_index = i;
}
}
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
static void sym_dial_float(t_sym_dial *x, t_floatarg f)
{
int i=(int)f;
if(i < 0)
i = 0;
else if(i >= x->x_ac)
i = x->x_ac - 1;
x->x_index = i;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
if(x->x_gui.x_fsf.x_put_in2out)
sym_dial_out(x);
}
static void sym_dial_symbol(t_sym_dial *x, t_symbol *s)
{
int i;
for(i=0; i<x->x_ac; i++)
{
if(x->x_syms[i] == s)
break;
}
x->x_index = i;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
if(x->x_gui.x_fsf.x_put_in2out)
sym_dial_out(x);
}
static void sym_dial_size(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{
int h, w;
w = (int)atom_getintarg(0, ac, av);
if(w < 1)
w = 1;
x->x_gui.x_w = w;
if(ac > 1)
{
h = (int)atom_getintarg(1, ac, av);
if(h < 8)
h = 8;
x->x_gui.x_h = h;
}
sym_dial_calc_fontwidth(x);
iemgui_size((void *)x, &x->x_gui);
}
static void sym_dial_delta(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
static void sym_dial_pos(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
static void sym_dial_color(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
static void sym_dial_send(t_sym_dial *x, t_symbol *s)
{iemgui_send(x, &x->x_gui, s);}
static void sym_dial_receive(t_sym_dial *x, t_symbol *s)
{iemgui_receive(x, &x->x_gui, s);}
static void sym_dial_label(t_sym_dial *x, t_symbol *s)
{iemgui_label((void *)x, &x->x_gui, s);}
static void sym_dial_label_pos(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
static void sym_dial_label_font(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{
int f = (int)atom_getintarg(1, ac, av);
if(f < 4)
f = 4;
x->x_gui.x_fontsize = f;
f = (int)atom_getintarg(0, ac, av);
if((f < 0) || (f > 2))
f = 0;
x->x_gui.x_fsf.x_font_style = f;
sym_dial_calc_fontwidth(x);
iemgui_label_font((void *)x, &x->x_gui, s, ac, av);
}
static void sym_dial_send_sym(t_sym_dial *x)
{
x->x_snd_flt0_sym1 = 1;
}
static void sym_dial_send_flt(t_sym_dial *x)
{
x->x_snd_flt0_sym1 = 0;
}
static void sym_dial_init(t_sym_dial *x, t_floatarg f)
{
x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
}
static void sym_dial_loadbang(t_sym_dial *x)
{
if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
sym_dial_bang(x);
}
}
static void sym_dial_set_item_name(t_sym_dial *x, t_symbol *name, t_float findex)
{
int i = (int)findex;
if(i < 0)
i = 0;
else if(i >= x->x_max_ac)
{
x->x_syms = (t_symbol **)t_resizebytes(x->x_syms, x->x_max_ac * sizeof(t_symbol *),
x->x_max_ac * (2*sizeof(t_symbol *)));
x->x_max_ac *= 2;
}
if(i >= x->x_ac)
{
t_symbol *default_sym=gensym("no_entry");
int j;
for(j=x->x_ac; j<i; j++)
x->x_syms[j] = default_sym;
x->x_ac++;
}
x->x_syms[i] = gensym(name->s_name);
if(i == x->x_index)
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
}
/*static void sym_dial_list(t_sym_dial *x, t_symbol *s, int ac, t_atom *av)
{
int l=iemgui_list((void *)x, &x->x_gui, s, ac, av);
if(l < 0)
{
if((ac==2)&&(IS_A_FLOAT(av,0))&&(IS_A_SYMBOL(av,1)))
{
sym_dial_float(x, atom_getfloatarg(0, ac, av));
}
}
if(l > 0)
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
}*/
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void *sym_dial_new(t_symbol *s, int argc, t_atom *argv)
{
t_sym_dial *x = (t_sym_dial *)pd_new(sym_dial_class);
int bflcol[]={-262144, -1, -1};
int w=6, h=14, ac=0, i, j;
int snd_fs=0, f=0, ldx=59, ldy=7;
int fs=9, index=0;
char str[144];
iem_inttosymargs(&x->x_gui.x_isa, 0);
iem_inttofstyle(&x->x_gui.x_fsf, 0);
if((argc >= 16)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
&&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
&&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
&&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5))
&&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
&&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)
&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
&&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15))
{
w = (int)atom_getintarg(0, argc, argv);
h = (int)atom_getintarg(1, argc, argv);
iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(2, argc, argv));
snd_fs = (int)atom_getintarg(3, argc, argv);
iemgui_new_getnames(&x->x_gui, 4, argv);
ldx = (int)atom_getintarg(7, argc, argv);
ldy = (int)atom_getintarg(8, argc, argv);
iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(9, argc, argv));
fs = (int)atom_getintarg(10, argc, argv);
bflcol[0] = (int)atom_getintarg(11, argc, argv);
bflcol[1] = (int)atom_getintarg(12, argc, argv);
bflcol[2] = (int)atom_getintarg(13, argc, argv);
index = atom_getintarg(14, argc, argv);
ac = (int)atom_getintarg(15, argc, argv);
if((ac+16) == argc)
{
x->x_ac = ac;
x->x_max_ac = ac;
x->x_syms = (t_symbol **)getbytes(x->x_max_ac * sizeof(t_symbol *));
for(i=0, j=16; i<ac; i++, j++)
{
if(IS_A_SYMBOL(argv, j))
x->x_syms[i] = atom_getsymbolarg(j, argc, argv);
else if(IS_A_FLOAT(argv, j))
{
sprintf(str, "%d", (int)atom_getintarg(j, argc, argv));
x->x_syms[i] = gensym(str);
}
}
}
}
else
{
iemgui_new_getnames(&x->x_gui, 1, 0);
x->x_ac = 1;
x->x_max_ac = 10;
x->x_syms = (t_symbol **)getbytes(x->x_max_ac * sizeof(t_symbol *));
x->x_syms[0] = gensym("sdl");
index = 0;
}
x->x_gui.x_draw = (t_iemfunptr)sym_dial_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if(x->x_gui.x_isa.x_loadinit)
x->x_index = index;
else
x->x_index = 0;
if(snd_fs != 0)
snd_fs = 1;
x->x_snd_flt0_sym1 = snd_fs;
if(!strcmp(x->x_gui.x_snd->s_name, "empty"))
x->x_gui.x_fsf.x_snd_able = 0;
if(!strcmp(x->x_gui.x_rcv->s_name, "empty"))
x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_font_style == 1)
strcpy(x->x_gui.x_font, "helvetica");
else if(x->x_gui.x_fsf.x_font_style == 2)
strcpy(x->x_gui.x_font, "times");
else
{
x->x_gui.x_fsf.x_font_style = 0;
strcpy(x->x_gui.x_font, "courier");
}
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
fs = 4;
x->x_gui.x_fontsize = fs;
if(w < 1)
w = 1;
x->x_gui.x_w = w;
if(h < 8)
h = 8;
x->x_gui.x_h = h;
sym_dial_calc_fontwidth(x);
iemgui_all_colfromload(&x->x_gui, bflcol);
iemgui_verify_snd_ne_rcv(&x->x_gui);
x->x_clock = clock_new(x, (t_method)sym_dial_tick);
outlet_new(&x->x_gui.x_obj, &s_float);
x->x_outlet = outlet_new(&x->x_gui.x_obj, &s_symbol);
return (x);
}
#else
static void *sym_dial_new(t_symbol *s, int argc, t_atom *argv)
{
t_sym_dial *x = (t_sym_dial *)pd_new(sym_dial_class);
int bflcol[]={-262144, -1, -1};
t_symbol *srl[3];
int w=6, h=14, ac=0, i, j;
int snd_fs=0, f=0, ldx=59, ldy=7;
int fs=9, iinit=0, ifstyle=0, index=0;
t_iem_init_symargs *init=(t_iem_init_symargs *)(&iinit);
t_iem_fstyle_flags *fstyle=(t_iem_fstyle_flags *)(&ifstyle);
char str[144];
srl[0] = gensym("empty");
srl[1] = gensym("empty");
srl[2] = gensym("empty");
if((argc >= 16)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
&&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
&&(IS_A_SYMBOL(argv,4)||IS_A_FLOAT(argv,4))
&&(IS_A_SYMBOL(argv,5)||IS_A_FLOAT(argv,5))
&&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
&&IS_A_FLOAT(argv,7)&&IS_A_FLOAT(argv,8)
&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
&&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
&&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15))
{
w = (int)atom_getintarg(0, argc, argv);
h = (int)atom_getintarg(1, argc, argv);
iinit = (int)atom_getintarg(2, argc, argv);
snd_fs = (int)atom_getintarg(3, argc, argv);
srl[0] = atom_getsymbolarg(4, argc, argv);
srl[1] = atom_getsymbolarg(5, argc, argv);
srl[2] = atom_getsymbolarg(6, argc, argv);
if(IS_A_SYMBOL(argv,4))
srl[0] = atom_getsymbolarg(4, argc, argv);
else if(IS_A_FLOAT(argv,4))
{
sprintf(str, "%d", (int)atom_getintarg(4, argc, argv));
srl[0] = gensym(str);
}
if(IS_A_SYMBOL(argv,5))
srl[1] = atom_getsymbolarg(5, argc, argv);
else if(IS_A_FLOAT(argv,5))
{
sprintf(str, "%d", (int)atom_getintarg(5, argc, argv));
srl[1] = gensym(str);
}
if(IS_A_SYMBOL(argv,6))
srl[2] = atom_getsymbolarg(6, argc, argv);
else if(IS_A_FLOAT(argv,6))
{
sprintf(str, "%d", (int)atom_getintarg(6, argc, argv));
srl[2] = gensym(str);
}
ldx = (int)atom_getintarg(7, argc, argv);
ldy = (int)atom_getintarg(8, argc, argv);
ifstyle = (int)atom_getintarg(9, argc, argv);
fs = (int)atom_getintarg(10, argc, argv);
bflcol[0] = (int)atom_getintarg(11, argc, argv);
bflcol[1] = (int)atom_getintarg(12, argc, argv);
bflcol[2] = (int)atom_getintarg(13, argc, argv);
index = atom_getintarg(14, argc, argv);
ac = (int)atom_getintarg(15, argc, argv);
if((ac+16) == argc)
{
x->x_ac = ac;
x->x_max_ac = ac;
x->x_syms = (t_symbol **)getbytes(x->x_max_ac * sizeof(t_symbol *));
for(i=0, j=16; i<ac; i++, j++)
{
if(IS_A_SYMBOL(argv, j))
x->x_syms[i] = atom_getsymbolarg(j, argc, argv);
else if(IS_A_FLOAT(argv, j))
{
sprintf(str, "%d", (int)atom_getintarg(j, argc, argv));
x->x_syms[i] = gensym(str);
}
}
}
}
else
{
x->x_ac = 1;
x->x_max_ac = 10;
x->x_syms = (t_symbol **)getbytes(x->x_max_ac * sizeof(t_symbol *));
x->x_syms[0] = gensym("sdl");
index = 0;
}
x->x_gui.x_draw = (t_iemfunptr)sym_dial_draw;
iinit &= IEM_INIT_ARGS_ALL;
ifstyle &= IEM_FSTYLE_FLAGS_ALL;
fstyle->x_snd_able = 1;
fstyle->x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_gui.x_isa = *init;
if(x->x_gui.x_isa.x_loadinit)
x->x_index = index;
else
x->x_index = 0;
if(snd_fs != 0) snd_fs = 1;
x->x_snd_flt0_sym1 = snd_fs;
if(!strcmp(srl[0]->s_name, "empty")) fstyle->x_snd_able = 0;
if(!strcmp(srl[1]->s_name, "empty")) fstyle->x_rcv_able = 0;
x->x_gui.x_unique_num = 0;
if(fstyle->x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
else if(fstyle->x_font_style == 2) strcpy(x->x_gui.x_font, "times");
else { fstyle->x_font_style = 0;
strcpy(x->x_gui.x_font, "courier"); }
x->x_gui.x_fsf = *fstyle;
iemgui_first_dollararg2sym(&x->x_gui, srl);
if(x->x_gui.x_fsf.x_rcv_able) pd_bind(&x->x_gui.x_obj.ob_pd, srl[1]);
x->x_gui.x_snd = srl[0];
x->x_gui.x_rcv = srl[1];
x->x_gui.x_lab = srl[2];
x->x_gui.x_ldx = ldx;
x->x_gui.x_ldy = ldy;
if(fs < 4)
fs = 4;
x->x_gui.x_fontsize = fs;
if(w < 1)
w = 1;
x->x_gui.x_w = w;
if(h < 8)
h = 8;
x->x_gui.x_h = h;
sym_dial_calc_fontwidth(x);
iemgui_all_colfromload(&x->x_gui, bflcol);
iemgui_verify_snd_ne_rcv(&x->x_gui);
x->x_clock = clock_new(x, (t_method)sym_dial_tick);
outlet_new(&x->x_gui.x_obj, &s_float);
x->x_outlet = outlet_new(&x->x_gui.x_obj, &s_symbol);
return (x);
}
#endif
static void sym_dial_free(t_sym_dial *x)
{
// if(x->x_gui.x_fsf.x_selected)
// pd_unbind(&x->x_gui.x_obj.ob_pd, iemgui_key_sym2);
if(x->x_gui.x_fsf.x_rcv_able)
pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
freebytes(x->x_syms, x->x_max_ac * sizeof(t_symbol *));
clock_free(x->x_clock);
}
void sym_dial_setup(void)
{
sym_dial_class = class_new(gensym("sdl"), (t_newmethod)sym_dial_new,
(t_method)sym_dial_free, sizeof(t_sym_dial), 0, A_GIMME, 0);
class_addcreator((t_newmethod)sym_dial_new, gensym("sym_dial"), A_GIMME, 0);
class_addbang(sym_dial_class,sym_dial_bang);
class_addfloat(sym_dial_class,sym_dial_float);
// class_addlist(sym_dial_class, sym_dial_list);
class_addsymbol(sym_dial_class, sym_dial_symbol);
class_addmethod(sym_dial_class, (t_method)sym_dial_click, gensym("click"),
A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_dialog, gensym("dialog"),
A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_loadbang, gensym("loadbang"), 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_set, gensym("set"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_size, gensym("size"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_delta, gensym("delta"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_pos, gensym("pos"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_color, gensym("color"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_send, gensym("send"), A_DEFSYM, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_receive, gensym("receive"), A_DEFSYM, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_label, gensym("label"), A_DEFSYM, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_label_pos, gensym("label_pos"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_label_font, gensym("label_font"), A_GIMME, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_send_flt, gensym("send_flt"), 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_send_sym, gensym("send_sym"), 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_init, gensym("init"), A_FLOAT, 0);
class_addmethod(sym_dial_class, (t_method)sym_dial_set_item_name, gensym("set_item_name"), A_SYMBOL, A_FLOAT, 0);
// if(!iemgui_key_sym2)
// iemgui_key_sym2 = gensym("#keyname");
sym_dial_widgetbehavior.w_getrectfn = sym_dial_getrect;
sym_dial_widgetbehavior.w_displacefn = iemgui_displace;
sym_dial_widgetbehavior.w_selectfn = iemgui_select;
sym_dial_widgetbehavior.w_activatefn = NULL;
sym_dial_widgetbehavior.w_deletefn = iemgui_delete;
sym_dial_widgetbehavior.w_visfn = iemgui_vis;
sym_dial_widgetbehavior.w_clickfn = sym_dial_newclick;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(sym_dial_class, sym_dial_save);
class_setpropertiesfn(sym_dial_class, sym_dial_properties);
#else
sym_dial_widgetbehavior.w_savefn = sym_dial_save;
sym_dial_widgetbehavior.w_propertiesfn = sym_dial_properties;
#endif
class_setwidget(sym_dial_class, &sym_dial_widgetbehavior);
class_sethelpsymbol(sym_dial_class, gensym("iemhelp2/help-sym_dial"));
}
--- NEW FILE: iemlib.h ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemlib.h written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#ifndef __IEMLIB_H__
#define __IEMLIB_H__
#define IS_A_POINTER(atom,index) ((atom+index)->a_type == A_POINTER)
#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
#define IS_A_DOLLAR(atom,index) ((atom+index)->a_type == A_DOLLAR)
#define IS_A_DOLLSYM(atom,index) ((atom+index)->a_type == A_DOLLSYM)
#define IS_A_SEMI(atom,index) ((atom+index)->a_type == A_SEMI)
#define IS_A_COMMA(atom,index) ((atom+index)->a_type == A_COMMA)
#ifdef MSW
int sys_noloadbang;
//t_symbol *iemgui_key_sym=0;
#include <io.h>
#else
extern int sys_noloadbang;
//extern t_symbol *iemgui_key_sym;
#include <unistd.h>
#endif
#define DEFDELVS 64
#define XTRASAMPS 4
#define SAMPBLK 4
#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
/* machine-dependent definitions. These ifdefs really
should have been by CPU type and not by operating system! */
#ifdef IRIX
/* big-endian. Most significant byte is at low address in memory */
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#define int32 long /* a data type that has 32 bits */
#else
#ifdef MSW
/* little-endian; most significant byte is at highest address */
#define HIOFFSET 1
#define LOWOFFSET 0
#define int32 long
#else
#ifdef __FreeBSD__
#include <machine/endian.h>
#if BYTE_ORDER == LITTLE_ENDIAN
#define HIOFFSET 1
#define LOWOFFSET 0
#else
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#endif /* BYTE_ORDER */
#include <sys/types.h>
#define int32 int32_t
#endif
#ifdef __linux__
#include <endian.h>
#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
#error No byte order defined
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define HIOFFSET 1
#define LOWOFFSET 0
#else
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#endif /* __BYTE_ORDER */
#include <sys/types.h>
#define int32 int32_t
#else
#ifdef __APPLE__
#define HIOFFSET 0 /* word offset to find MSB */
#define LOWOFFSET 1 /* word offset to find LSB */
#define int32 int /* a data type that has 32 bits */
#endif /* __APPLE__ */
#endif /* __linux__ */
#endif /* MSW */
#endif /* SGI */
union tabfudge
{
double tf_d;
int32 tf_i[2];
};
#define IEM_DENORMAL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
(((*(unsigned int*)&(f))&0x60000000)==0x60000000))
/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
#endif
--- NEW FILE: numberbox_matrix.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2005 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include "t_tk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifdef MSW
#include <io.h>
[...1343 lines suppressed...]
gensym("font"), A_GIMME, 0);
numberbox_matrix_widgetbehavior.w_getrectfn = numberbox_matrix_getrect;
numberbox_matrix_widgetbehavior.w_displacefn = iemgui_displace;
numberbox_matrix_widgetbehavior.w_selectfn = iemgui_select;
numberbox_matrix_widgetbehavior.w_activatefn = NULL;
numberbox_matrix_widgetbehavior.w_deletefn = iemgui_delete;
numberbox_matrix_widgetbehavior.w_visfn = iemgui_vis;
numberbox_matrix_widgetbehavior.w_clickfn = numberbox_matrix_newclick;
#if((PD_MAJOR_VERSION)&&(PD_MINOR_VERSION < 37))
numberbox_matrix_widgetbehavior.w_propertiesfn = NULL;
numberbox_matrix_widgetbehavior.w_savefn = numberbox_matrix_save;
#else
class_setsavefn(numberbox_matrix_class, numberbox_matrix_save);
#endif
class_setwidget(numberbox_matrix_class, &numberbox_matrix_widgetbehavior);
class_sethelpsymbol(numberbox_matrix_class, gensym("iemhelp2/help-numberbox_matrix"));
}
--- NEW FILE: iemgui.h ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#ifndef __IEMGUI_H__
#define __IEMGUI_H__
//t_symbol *iemgui_key_sym2=0;
typedef struct _my_iemgui_4hex
{
unsigned int dummy : 8;
unsigned int hex4 : 6;
unsigned int hex3 : 6;
unsigned int hex2 : 6;
unsigned int hex1 : 6;
} t_my_iemgui_4hex;
typedef struct _my_iemgui_3byte
{
unsigned int dummy : 8;
unsigned int byte3 : 8;
unsigned int byte2 : 8;
unsigned int byte1 : 8;
} t_my_iemgui_3byte;
typedef union _my_iemgui_3u4
{
t_my_iemgui_4hex h4;
t_my_iemgui_3byte b3;
} t_my_iemgui_3u4;
extern char my_iemgui_black_vscale_gif[];
extern char my_iemgui_black_hlscale_gif[];
extern char my_iemgui_black_hrscale_gif[];
extern char my_iemgui_base64[];
extern int my_iemgui_color_hex[];
extern int simularca_color_hex[];
extern void my_iemgui_change_scale_col(char *gif, int color);
#endif
--- NEW FILE: vfad_scale.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "iemgui.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include <string.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
/* ------------------------ setup routine ------------------------- */
t_widgetbehavior vfad_scale_widgetbehavior;
static t_class *vfad_scale_class;
typedef struct _vfad_scale
{
t_iemgui x_gui;
char x_gif[720];
} t_vfad_scale;
static void vfad_scale_draw_new(t_vfad_scale *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui("image create photo %xPHOTOIMAGE -format gif -data {%s} -width %d -height %d\n",
x, x->x_gif, x->x_gui.x_w, x->x_gui.x_h);
sys_vgui(".x%x.c create image %d %d -image %xPHOTOIMAGE -tags %xPHOTO\n",
canvas, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2, x, x);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos,
xpos + x->x_gui.x_w, ypos + x->x_gui.x_h,
IEM_GUI_COLOR_SELECTED, x);
}
static void vfad_scale_draw_move(t_vfad_scale *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
sys_vgui(".x%x.c coords %xPHOTO %d %d\n",
canvas, x, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos,
xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void vfad_scale_draw_erase(t_vfad_scale* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
sys_vgui("image delete %xPHOTOIMAGE\n", x);
sys_vgui(".x%x.c delete %xPHOTO\n", canvas, x);
}
static void vfad_scale_draw_select(t_vfad_scale* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w,
ypos + x->x_gui.x_h, IEM_GUI_COLOR_SELECTED, x);
}
else
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
}
static void vfad_scale_draw(t_vfad_scale *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
vfad_scale_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
vfad_scale_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
vfad_scale_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
vfad_scale_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void vfad_scale_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_vfad_scale *x = (t_vfad_scale *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h;
}
static void vfad_scale_color(t_vfad_scale *x, t_symbol *s, int argc, t_atom *argv)
{
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
int j, i = (int)atom_getintarg(0, argc, argv);
if(i >= 0)
{
j = iemgui_modulo_color(i);
x->x_gui.x_lcol = my_iemgui_color_hex[j];
}
else
x->x_gui.x_lcol = (-1 - i) & 0xffffff;
my_iemgui_change_scale_col(x->x_gif, x->x_gui.x_lcol);
if(glist_isvisible(x->x_gui.x_glist))
sys_vgui("%xPHOTOIMAGE configure -data {%s}\n", x, x->x_gif);
}
}
static void vfad_scale_save(t_gobj *z, t_binbuf *b)
{
t_vfad_scale *x = (t_vfad_scale *)z;
binbuf_addv(b, "ssiisi", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("vfad_scale"), -1 - (((0xfc0000 & x->x_gui.x_lcol) >> 6)|
((0xfc00 & x->x_gui.x_lcol) >> 4)|((0xfc & x->x_gui.x_lcol) >> 2)));
binbuf_addv(b, ";");
}
static void *vfad_scale_new(t_symbol *s, int argc, t_atom *argv)
{
t_vfad_scale *x = (t_vfad_scale *)pd_new(vfad_scale_class);
if((argc >= 1)&&IS_A_FLOAT(argv,0))
{
int j, i = (int)atom_getintarg(0, argc, argv);
if(i >= 0)
{
j = iemgui_modulo_color(i);
x->x_gui.x_lcol = my_iemgui_color_hex[j];
}
else
{
j = -1 - i;
x->x_gui.x_lcol = ((j & 0x3f000) << 6)|((j & 0xfc0) << 4)|((j & 0x3f) << 2);
}
}
else
x->x_gui.x_lcol = 0;
x->x_gui.x_draw = (t_iemfunptr)vfad_scale_draw;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
x->x_gui.x_w = 12;
x->x_gui.x_h = 126;
strcpy(x->x_gif, my_iemgui_black_vscale_gif);
my_iemgui_change_scale_col(x->x_gif, x->x_gui.x_lcol);
x->x_gui.x_fsf.x_selected = 0;
return(x);
}
static void vfad_scale_ff(t_vfad_scale *x)
{
gfxstub_deleteforkey(x);
}
void vfad_scale_setup(void)
{
vfad_scale_class = class_new(gensym("vfad_scale"), (t_newmethod)vfad_scale_new,
(t_method)vfad_scale_ff, sizeof(t_vfad_scale), 0, A_GIMME, 0);
class_addmethod(vfad_scale_class, (t_method)vfad_scale_color, gensym("color"), A_GIMME, 0);
vfad_scale_widgetbehavior.w_getrectfn = vfad_scale_getrect;
vfad_scale_widgetbehavior.w_displacefn = iemgui_displace;
vfad_scale_widgetbehavior.w_selectfn = iemgui_select;
vfad_scale_widgetbehavior.w_activatefn = NULL;
vfad_scale_widgetbehavior.w_deletefn = iemgui_delete;
vfad_scale_widgetbehavior.w_visfn = iemgui_vis;
vfad_scale_widgetbehavior.w_clickfn = NULL;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(vfad_scale_class, vfad_scale_save);
#else
vfad_scale_widgetbehavior.w_propertiesfn = NULL;
vfad_scale_widgetbehavior.w_savefn = vfad_scale_save;
#endif
class_setwidget(vfad_scale_class, &vfad_scale_widgetbehavior);
class_sethelpsymbol(vfad_scale_class, gensym("iemhelp2/help-vfad_scale"));
}
--- NEW FILE: iem_image.c ---
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
iemgui written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
#include "m_pd.h"
#include "iemlib.h"
#include "g_canvas.h"
#include "g_all_guis.h"
#include <stdio.h>
#include <string.h>
#ifdef MSW
#include <io.h>
#else
#include <unistd.h>
#endif
/* ------------------------ setup routine ------------------------- */
t_widgetbehavior iem_image_widgetbehavior;
static t_class *iem_image_class;
typedef struct _iem_image
{
t_iemgui x_gui;
t_symbol *x_gifsym;
t_atom x_at_out[2];
} t_iem_image;
static t_symbol *iem_image_calc_size(t_iem_image *x)
{
char dirbuf[MAXPDSTRING], *namebufptr;
char namebuf[MAXPDSTRING];
unsigned char buf[222];
unsigned int i;
char *c;
int fd;
FILE *fh;
if(!x->x_gifsym || !x->x_gifsym->s_name)
{
post("iem_image-ERROR: no gifname");
x->x_gifsym = (t_symbol *)0;
return((t_symbol *)0);
}
fd = open_via_path(canvas_getdir(glist_getcanvas(x->x_gui.x_glist))->s_name, x->x_gifsym->s_name,
"", dirbuf, &namebufptr, MAXPDSTRING, 1);
if (fd < 0)
{
post("iem_image-ERROR: cannot open %s first time", x->x_gifsym->s_name);
x->x_gifsym = (t_symbol *)0;
return((t_symbol *)0);
}
else
{
if(fd >= 0)
close(fd);
strcpy(namebuf, dirbuf);
strcat(namebuf, "/");
strcat(namebuf, namebufptr);
fh = fopen(namebuf, "r");
if(fh == NULL)
{
post("iem_image-ERROR: cannot open %s second time", namebuf);
x->x_gifsym = (t_symbol *)0;
return((t_symbol *)0);
}
else
{
fread(buf, 22, sizeof(unsigned char), fh);
fclose(fh);
c = (char *)buf;
if((c[0] != 'G')||(c[1] != 'I')||(c[2] != 'F'))
{
post("iem_image-ERROR: %s is not a GIF-file", namebuf);
x->x_gifsym = (t_symbol *)0;
return((t_symbol *)0);
}
i = 256*(unsigned int)buf[7];
i += (unsigned int)buf[6];
x->x_gui.x_w = (int)i;
i = 256*(unsigned int)buf[9];
i += (unsigned int)buf[8];
x->x_gui.x_h = (int)i;
SETFLOAT(x->x_at_out, (t_float)x->x_gui.x_w);
SETFLOAT(x->x_at_out+1, (t_float)x->x_gui.x_h);
outlet_list(x->x_gui.x_obj.ob_outlet, &s_list, 2, x->x_at_out);
if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
pd_list(x->x_gui.x_snd->s_thing, &s_list, 2, x->x_at_out);
return(gensym(namebuf));
}
}
}
static void iem_image_draw_new(t_iem_image *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
t_symbol *correct_name;
if(correct_name = iem_image_calc_size(x))
{
sys_vgui("image create photo %xPHOTOIMAGE -file {%s} -format gif -width %d -height %d\n",
x, correct_name->s_name, x->x_gui.x_w, x->x_gui.x_h);
sys_vgui(".x%x.c create image %d %d -image %xPHOTOIMAGE -tags %xPHOTO\n",
canvas, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2, x, x);
}
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h, IEM_GUI_COLOR_SELECTED, x);
}
static void iem_image_draw_move(t_iem_image *x, t_glist *glist)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gifsym)
sys_vgui(".x%x.c coords %xPHOTO %d %d\n", canvas, x, xpos+x->x_gui.x_w/2, ypos+x->x_gui.x_h/2);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n",
canvas, x, xpos, ypos, xpos + x->x_gui.x_w, ypos + x->x_gui.x_h);
canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
}
static void iem_image_draw_erase(t_iem_image* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
if(x->x_gifsym)
{
sys_vgui("image delete %xPHOTOIMAGE\n", x);
sys_vgui(".x%x.c delete %xPHOTO\n", canvas, x);
}
}
static void iem_image_draw_select(t_iem_image* x, t_glist* glist)
{
t_canvas *canvas=glist_getcanvas(glist);
if(x->x_gui.x_fsf.x_selected)
{
int xpos=text_xpix(&x->x_gui.x_obj, glist);
int ypos=text_ypix(&x->x_gui.x_obj, glist);
sys_vgui(".x%x.c create rectangle %d %d %d %d -outline #%6.6x -tags %xBASE\n",
canvas, xpos, ypos, xpos + x->x_gui.x_w,
ypos + x->x_gui.x_h, IEM_GUI_COLOR_SELECTED, x);
}
else
sys_vgui(".x%x.c delete %xBASE\n", canvas, x);
}
static void iem_image_draw(t_iem_image *x, t_glist *glist, int mode)
{
if(mode == IEM_GUI_DRAW_MODE_MOVE)
iem_image_draw_move(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_NEW)
iem_image_draw_new(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_SELECT)
iem_image_draw_select(x, glist);
else if(mode == IEM_GUI_DRAW_MODE_ERASE)
iem_image_draw_erase(x, glist);
}
/* ------------------------ cnv widgetbehaviour----------------------------- */
static void iem_image_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2)
{
t_iem_image *x = (t_iem_image *)z;
*xp1 = text_xpix(&x->x_gui.x_obj, glist);
*yp1 = text_ypix(&x->x_gui.x_obj, glist);
*xp2 = *xp1 + x->x_gui.x_w;
*yp2 = *yp1 + x->x_gui.x_h;
}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void iem_image_save(t_gobj *z, t_binbuf *b)
{
t_iem_image *x = (t_iem_image *)z;
t_symbol *srl[3];
srl[0] = x->x_gui.x_snd;
srl[1] = x->x_gui.x_rcv;
srl[2] = gensym("empty");
if(x->x_gifsym)
binbuf_addv(b, "ssiissiiss", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("iem_image"), x->x_gifsym, iem_symargstoint(&x->x_gui.x_isa),
iem_fstyletoint(&x->x_gui.x_fsf), srl[0], srl[1]);
else
binbuf_addv(b, "ssiisiiiss", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("iem_image"), 0, iem_symargstoint(&x->x_gui.x_isa),
iem_fstyletoint(&x->x_gui.x_fsf), srl[0], srl[1]);
binbuf_addv(b, ";");
}
#else
static void iem_image_save(t_gobj *z, t_binbuf *b)
{
t_iem_image *x = (t_iem_image *)z;
int *ip1, *ip2;
t_symbol *srl[3];
srl[0] = x->x_gui.x_snd;
srl[1] = x->x_gui.x_rcv;
srl[2] = gensym("empty");
iemgui_all_unique2dollarzero(&x->x_gui, srl);
iemgui_all_sym2dollararg(&x->x_gui, srl);
ip1 = (int *)(&x->x_gui.x_isa);
ip2 = (int *)(&x->x_gui.x_fsf);
if(x->x_gifsym)
binbuf_addv(b, "ssiissiiss", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("iem_image"), x->x_gifsym, (*ip1)&IEM_INIT_ARGS_ALL,
(*ip2)&IEM_FSTYLE_FLAGS_ALL, srl[0], srl[1]);
else
binbuf_addv(b, "ssiisiiiss", gensym("#X"),gensym("obj"),
(t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
gensym("iem_image"), 0, (*ip1)&IEM_INIT_ARGS_ALL,
(*ip2)&IEM_FSTYLE_FLAGS_ALL, srl[0], srl[1]);
binbuf_addv(b, ";");
}
#endif
static void iem_image_clear(t_iem_image *x)
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
x->x_gifsym = (t_symbol *)0;
}
static void iem_image_open(t_iem_image *x, t_symbol *name)
{
if(name && name->s_name)
{
if(x->x_gifsym)
{
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_ERASE);
x->x_gifsym = (t_symbol *)0;
}
x->x_gifsym = name;
(*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_NEW);
}
}
static void iem_image_delta(t_iem_image *x, t_symbol *s, int ac, t_atom *av)
{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
static void iem_image_pos(t_iem_image *x, t_symbol *s, int ac, t_atom *av)
{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
static void iem_image_send(t_iem_image *x, t_symbol *s)
{iemgui_send(x, &x->x_gui, s);}
static void iem_image_receive(t_iem_image *x, t_symbol *s)
{iemgui_receive(x, &x->x_gui, s);}
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
static void *iem_image_new(t_symbol *s, int argc, t_atom *argv)
{
t_iem_image *x = (t_iem_image *)pd_new(iem_image_class);
t_symbol *gifsym=(t_symbol *)0;
x->x_gui.x_snd = gensym("empty");
x->x_gui.x_rcv = gensym("empty");
x->x_gui.x_lab = gensym("empty");
x->x_gui.x_fsf.x_font_style = 0;
if(argc >= 1)
{
if(IS_A_SYMBOL(argv,0))
gifsym = atom_getsymbolarg(0, argc, argv);
else if(IS_A_FLOAT(argv,0))
gifsym = (t_symbol *)0;
}
else if(argc >= 5)
{
if(IS_A_SYMBOL(argv,0))
gifsym = atom_getsymbolarg(0, argc, argv);
else if(IS_A_FLOAT(argv,0))
gifsym = (t_symbol *)0;
iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(1, argc, argv));
iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(2, argc, argv));
iemgui_new_getnames(&x->x_gui, 3, argv);
}
x->x_gui.x_draw = (t_iemfunptr)iem_image_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
if(!strcmp(x->x_gui.x_snd->s_name, "empty"))
x->x_gui.x_fsf.x_snd_able = 0;
if(!strcmp(x->x_gui.x_rcv->s_name, "empty"))
x->x_gui.x_fsf.x_rcv_able = 0;
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_w = 100;
x->x_gui.x_h = 60;
x->x_gifsym = gifsym;
x->x_gui.x_fsf.x_selected = 0;
iemgui_verify_snd_ne_rcv(&x->x_gui);
outlet_new(&x->x_gui.x_obj, &s_list);
return(x);
}
#else
static void *iem_image_new(t_symbol *s, int argc, t_atom *argv)
{
t_iem_image *x = (t_iem_image *)pd_new(iem_image_class);
t_symbol *gifsym=(t_symbol *)0;
t_int iinit=0, ifstyle=0;
t_iem_init_symargs *init=(t_iem_init_symargs *)(&iinit);
t_iem_fstyle_flags *fstyle=(t_iem_fstyle_flags *)(&ifstyle);
t_symbol *srl[3];
char str[144];
x->x_gui.x_snd = gensym("empty");
x->x_gui.x_rcv = gensym("empty");
x->x_gui.x_lab = gensym("empty");
srl[0] = gensym("empty");
srl[1] = gensym("empty");
srl[2] = gensym("empty");
x->x_gui.x_fsf.x_font_style = 0;
if(argc >= 1)
{
if(IS_A_SYMBOL(argv,0))
gifsym = atom_getsymbolarg(0, argc, argv);
else if(IS_A_FLOAT(argv,0))
gifsym = (t_symbol *)0;
}
else if(argc >= 5)
{
if(IS_A_SYMBOL(argv,0))
gifsym = atom_getsymbolarg(0, argc, argv);
else if(IS_A_FLOAT(argv,0))
gifsym = (t_symbol *)0;
iinit = (int)atom_getintarg(1, argc, argv);
ifstyle = (int)atom_getintarg(2, argc, argv);
if(IS_A_SYMBOL(argv, 3))
srl[0] = atom_getsymbolarg(3, argc, argv);
else if(IS_A_FLOAT(argv,3))
{
sprintf(str, "%d", (int)atom_getintarg(3, argc, argv));
srl[0] = gensym(str);
}
if(IS_A_SYMBOL(argv,4))
srl[1] = atom_getsymbolarg(4, argc, argv);
else if(IS_A_FLOAT(argv,4))
{
sprintf(str, "%d", (int)atom_getintarg(4, argc, argv));
srl[1] = gensym(str);
}
}
iinit &= IEM_INIT_ARGS_ALL;
ifstyle &= IEM_FSTYLE_FLAGS_ALL;
x->x_gui.x_draw = (t_iemfunptr)iem_image_draw;
x->x_gui.x_fsf.x_snd_able = 1;
x->x_gui.x_fsf.x_rcv_able = 1;
x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
fstyle->x_snd_able = 1;
fstyle->x_rcv_able = 1;
if(!strcmp(srl[0]->s_name, "empty"))
fstyle->x_snd_able = 0;
if(!strcmp(srl[1]->s_name, "empty"))
fstyle->x_rcv_able = 0;
x->x_gui.x_unique_num = 0;
x->x_gui.x_fsf = *fstyle;
x->x_gui.x_isa = *init;
iemgui_first_dollararg2sym(&x->x_gui, sr);
if(x->x_gui.x_fsf.x_rcv_able)
pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
x->x_gui.x_w = 100;
x->x_gui.x_h = 60;
x->x_gifsym = gifsym;
x->x_gui.x_fsf.x_selected = 0;
iemgui_verify_snd_ne_rcv(&x->x_gui);
outlet_new(&x->x_gui.x_obj, &s_list);
return(x);
}
#endif
static void iem_image_ff(t_iem_image *x)
{
gfxstub_deleteforkey(x);
}
void iem_image_setup(void)
{
iem_image_class = class_new(gensym("iem_image"), (t_newmethod)iem_image_new,
(t_method)iem_image_ff, sizeof(t_iem_image), 0, A_GIMME, 0);
class_addmethod(iem_image_class, (t_method)iem_image_open, gensym("open"), A_SYMBOL, 0);
class_addmethod(iem_image_class, (t_method)iem_image_clear, gensym("clear"), 0);
class_addmethod(iem_image_class, (t_method)iem_image_delta,
gensym("delta"), A_GIMME, 0);
class_addmethod(iem_image_class, (t_method)iem_image_pos,
gensym("pos"), A_GIMME, 0);
class_addmethod(iem_image_class, (t_method)iem_image_send,
gensym("send"), A_DEFSYM, 0);
class_addmethod(iem_image_class, (t_method)iem_image_receive,
gensym("receive"), A_DEFSYM, 0);
iem_image_widgetbehavior.w_getrectfn = iem_image_getrect;
iem_image_widgetbehavior.w_displacefn = iemgui_displace;
iem_image_widgetbehavior.w_selectfn = iemgui_select;
iem_image_widgetbehavior.w_activatefn = NULL;
iem_image_widgetbehavior.w_deletefn = iemgui_delete;
iem_image_widgetbehavior.w_visfn = iemgui_vis;
iem_image_widgetbehavior.w_clickfn = NULL;
#if defined(PD_MAJOR_VERSION) && (PD_MINOR_VERSION >= 37)
class_setsavefn(iem_image_class, iem_image_save);
#else
iem_image_widgetbehavior.w_propertiesfn = NULL;
iem_image_widgetbehavior.w_savefn = iem_image_save;
#endif
class_setwidget(iem_image_class, &iem_image_widgetbehavior);
class_sethelpsymbol(iem_image_class, gensym("iemhelp2/help-iem_image"));
// post("iem_image library loaded!");
}