Skip to content

Commit

Permalink
create messbox
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Jul 20, 2020
1 parent 44f1d95 commit be0dc89
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 50 deletions.
130 changes: 82 additions & 48 deletions Classes/Source/messbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@
#define BORDER 5

typedef struct _messbox{
t_object x_obj;
t_canvas *x_canvas;
t_glist *x_glist;
t_symbol *x_bind_sym;
int x_height;
int x_open;
int x_width;
int x_resizing;
int x_active;
t_symbol *x_bgcolor;
t_symbol *x_fgcolor;
int x_font_size;
t_symbol *x_font_weight;
int x_selected;
char *tcl_namespace;
char *x_cv_id;
char *frame_id;
char *text_id;
char *handle_id;
char *window_tag;
char *all_tag;
t_outlet* x_data_outlet;
t_clock *x_clock;
t_object x_obj;
t_canvas *x_canvas;
t_glist *x_glist;
t_symbol *x_bind_sym;
int x_height;
int x_open;
int x_width;
int x_resizing;
int x_active;
char x_fgcolor[8];
unsigned int x_fg[3]; // fg RGB color
char x_bgcolor[8];
unsigned int x_bg[3]; // bg RGB color
int x_font_size;
t_symbol *x_font_weight;
int x_selected;
char *tcl_namespace;
char *x_cv_id;
char *frame_id;
char *text_id;
char *handle_id;
char *window_tag;
char *all_tag;
t_outlet *x_data_outlet;
t_clock *x_clock;
}t_messbox;

static t_class *messbox_class;
Expand Down Expand Up @@ -72,7 +74,7 @@ static void set_tk_widget_ids(t_messbox *x, t_canvas *canvas){
static void draw_box(t_messbox *x){
int xpos = text_xpix(&x->x_obj, x->x_glist), ypos = text_ypix(&x->x_obj, x->x_glist);
sys_vgui("%s create rectangle %d %d %d %d -outline black -fill \"%s\" -width 1 -tags %x_outline\n",
x->x_cv_id, xpos, ypos, xpos+x->x_width, ypos+x->x_height, x->x_bgcolor->s_name, x);
x->x_cv_id, xpos, ypos, xpos+x->x_width, ypos+x->x_height, x->x_bgcolor, x);
sys_vgui("%s create rectangle %d %d %d %d -fill black -tags {%x_inlet %s}\n",
x->x_cv_id, xpos, ypos, xpos+IOWIDTH, ypos+IHEIGHT, x, x->all_tag);
sys_vgui("%s create rectangle %d %d %d %d -fill black -tags {%x_outlet %s}\n",
Expand All @@ -82,7 +84,6 @@ static void draw_box(t_messbox *x){
static void erase_box(t_messbox *x){
sys_vgui("%s delete %x_outline\n", x->x_cv_id, x);
sys_vgui("%s delete %x_inlet\n", x->x_cv_id, x);
// sys_vgui("destroy %s\n", x->inlet_id);
sys_vgui("%s delete %x_outlet\n", x->x_cv_id, x);
}

Expand All @@ -96,7 +97,7 @@ static void messbox_draw(t_messbox *x, t_glist *glist){
sys_vgui("frame %s\n", x->frame_id);
sys_vgui("text %s -font {{%s} %d %s} -highlightthickness 0 -bg \"%s\" -fg \"%s\"\n",
x->text_id, FONT_NAME, x->x_font_size, x->x_font_weight->s_name,
x->x_bgcolor->s_name, x->x_fgcolor->s_name);
x->x_bgcolor, x->x_fgcolor);
sys_vgui("pack %s -side left -fill both -expand 1\n", x->text_id);
sys_vgui("pack %s -side bottom -fill both -expand 1\n", x->frame_id);
// bind_button_events;
Expand Down Expand Up @@ -128,6 +129,9 @@ static void messbox_draw(t_messbox *x, t_glist *glist){
static void messbox_erase(t_messbox* x,t_glist* glist){
// post("messbox_erase");
set_tk_widget_ids(x, glist_getcanvas(glist));
sys_vgui("%s delete %x_outline\n", x->x_cv_id, x);
sys_vgui("%s delete %x_inlet\n", x->x_cv_id, x);
sys_vgui("%s delete %x_outlet\n", x->x_cv_id, x);
sys_vgui("destroy %s\n", x->frame_id);
sys_vgui("%s delete %s\n", x->x_cv_id, x->all_tag);
}
Expand Down Expand Up @@ -181,7 +185,7 @@ static void messbox_select(t_gobj *z, t_glist *glist, int state){
x->handle_id, x->x_bind_sym->s_name);
}
else{
sys_vgui("%s configure -fg %s -state normal -cursor xterm\n", x->text_id, x->x_fgcolor->s_name);
sys_vgui("%s configure -fg %s -state normal -cursor xterm\n", x->text_id, x->x_fgcolor);
sys_vgui("destroy %s\n", x->handle_id);
x->x_selected = 0;
}
Expand Down Expand Up @@ -278,14 +282,21 @@ static void messbox_set(t_messbox* x, t_symbol *s, int argc, t_atom *argv){
sys_vgui("%s configure -state disabled\n", x->text_id);
}

void messbox_bgcolor(t_messbox* x, t_symbol* bgcol){
x->x_bgcolor = bgcol;
sys_vgui("%s configure -background \"%s\" \n", x->text_id, x->x_bgcolor->s_name);
void messbox_bgcolor(t_messbox* x, t_floatarg r, t_floatarg g, t_floatarg b){
x->x_bg[0] = r < 0 ? 0 : r > 255 ? 255 : (int)r;
x->x_bg[1] = g < 1 ? 0 : g > 255 ? 255 : (int)g;
x->x_bg[2] = b < 2 ? 0 : b > 255 ? 255 : (int)b;
sprintf(x->x_bgcolor, "#%2.2x%2.2x%2.2x", x->x_bg[0], x->x_bg[1], x->x_bg[2]);
sys_vgui("%s configure -background \"%s\"\n", x->text_id, x->x_bgcolor);
sys_vgui("%s itemconfigure %x_outline -fill %s\n", x->x_cv_id, (unsigned long)x, x->x_bgcolor);
}

void messbox_fgcolor(t_messbox* x, t_symbol* fgcol){
x->x_fgcolor = fgcol;
sys_vgui("%s configure -foreground \"%s\" \n", x->text_id, x->x_fgcolor->s_name);
void messbox_fgcolor(t_messbox* x, t_floatarg r, t_floatarg g, t_floatarg b){
x->x_fg[0] = r < 0 ? 0 : r > 255 ? 255 : (int)r;
x->x_fg[1] = g < 1 ? 0 : g > 255 ? 255 : (int)g;
x->x_fg[2] = b < 2 ? 0 : b > 255 ? 255 : (int)b;
sprintf(x->x_fgcolor, "#%2.2x%2.2x%2.2x", x->x_fg[0], x->x_fg[1], x->x_fg[2]);
sys_vgui("%s configure -foreground \"%s\" \n", x->text_id, x->x_fgcolor);
}

static void messbox_bold(t_messbox *x, t_float bold){
Expand All @@ -306,7 +317,7 @@ static void messbox_size(t_messbox *x, t_float width, t_float height){
x->x_width = width < MIN_WIDTH ? MIN_WIDTH : (int)width;
if(glist_isvisible(x->x_glist)){
sys_vgui("%s itemconfigure %s -width %d -height %d\n",
x->x_cv_id, x->window_tag, x->x_width, x->x_height);
x->x_cv_id, x->window_tag, x->x_width-BORDER*2, x->x_height-BORDER*2);
canvas_fixlinesfor(x->x_glist, (t_text *)x);
erase_box(x), draw_box(x);
}
Expand All @@ -328,7 +339,6 @@ static void messbox_key(void *z, t_floatarg f){

static int messbox_click(t_gobj *z, t_glist *glist, int xpix, int ypix, int shift, int alt, int dbl, int doit){
xpix = ypix = alt = dbl = 0;
// post("click = %d", doit);
if(doit){
t_messbox *x = (t_messbox *)z;
x->x_active = 1;
Expand All @@ -350,8 +360,20 @@ static void messbox_motion_callback(t_messbox *x, t_floatarg f1, t_floatarg f2){
// post("messbox_motion_callback");
if(x->x_resizing){
int dx = (int)f1, dy = (int)f2;
int w = x->x_width, h = x->x_height;
if(glist_isvisible(x->x_glist)){
x->x_width += dx, x->x_height += dy;
if(w+dx < MIN_WIDTH){
x->x_width = MIN_WIDTH;
dx = MIN_WIDTH - w;
}
else
x->x_width+=dx;
if(h+dy < MIN_HEIGHT){
x->x_height = MIN_HEIGHT;
dy = MIN_HEIGHT-h;
}
else
x->x_height+=dy;
sys_vgui("%s itemconfigure %s -width %d -height %d\n",
x->x_cv_id, x->window_tag, x->x_width-BORDER*2, x->x_height-BORDER*2);
sys_vgui("%s move RSZ %d %d\n", x->x_cv_id, dx, dy);
Expand All @@ -363,10 +385,11 @@ static void messbox_motion_callback(t_messbox *x, t_floatarg f1, t_floatarg f2){

static void messbox_save(t_gobj *z, t_binbuf *b){
t_messbox *x = (t_messbox *)z;
binbuf_addv(b, "ssiisiiss;", &s__X, gensym("obj"),
x->x_obj.te_xpix, x->x_obj.te_ypix,
atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
x->x_width, x->x_height, x->x_bgcolor, x->x_fgcolor);
binbuf_addv(b, "ssiisiiiiiiiiii;", &s__X, gensym("obj"),
x->x_obj.te_xpix, x->x_obj.te_ypix, atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
x->x_width, x->x_height, x->x_bg[0], x->x_bg[1], x->x_bg[2],
x->x_fg[0], x->x_fg[1], x->x_fg[2],
x->x_font_weight == gensym("bold"), x->x_font_size);
}

static void messbox_free(t_messbox *x){
Expand All @@ -380,17 +403,28 @@ static void *messbox_new(t_symbol *s, int argc, t_atom *argv){
t_messbox *x = (t_messbox *)pd_new(messbox_class);
char buf[MAXPDSTRING];
x->x_font_size = 12;
x->x_font_weight = gensym("normal");
int weigth = 0;
x->x_selected = 0;
x->x_width = x->x_height = 130;
x->x_bgcolor = gensym("grey90");
x->x_fgcolor = gensym("black");
if(argc == 4){
x->x_bg[0] = x->x_bg[1] = x->x_bg[2] = 235;
x->x_fg[0] = x->x_fg[1] = x->x_fg[2] = 0;
if(argc){
x->x_width = atom_getint(argv);
x->x_height = atom_getint(argv+1);
x->x_bgcolor = atom_getsymbol(argv+2);
x->x_fgcolor = atom_getsymbol(argv+3);
x->x_bg[0] = (unsigned int)atom_getfloatarg(2, argc, argv);
x->x_bg[1] = (unsigned int)atom_getfloatarg(3, argc, argv);
x->x_bg[2] = (unsigned int)atom_getfloatarg(4, argc, argv);
x->x_fg[0] = (unsigned int)atom_getfloatarg(5, argc, argv);
x->x_fg[1] = (unsigned int)atom_getfloatarg(6, argc, argv);
x->x_fg[2] = (unsigned int)atom_getfloatarg(7, argc, argv);
weigth = (int)(atom_getfloatarg(8, argc, argv) != 0);
x->x_font_size = (int)(atom_getfloatarg(9, argc, argv));
}
if(x->x_font_size < 8)
x->x_font_size = 8;
sprintf(x->x_bgcolor, "#%2.2x%2.2x%2.2x", x->x_bg[0], x->x_bg[1], x->x_bg[2]);
sprintf(x->x_fgcolor, "#%2.2x%2.2x%2.2x", x->x_fg[0], x->x_fg[1], x->x_fg[2]);
x->x_font_weight = weigth ? gensym("bold") : gensym("normal");
x->x_clock = clock_new(x, (t_method)messbox_tick);
x->x_resizing = x->x_active = x->x_open = 0;
x->x_data_outlet = outlet_new(&x->x_obj, &s_float);
Expand All @@ -416,8 +450,8 @@ void messbox_setup(void) {
class_addmethod(messbox_class, (t_method)messbox_set, gensym("set"), A_GIMME, 0);
class_addmethod(messbox_class, (t_method)messbox_append, gensym("append"), A_GIMME, 0);
class_addmethod(messbox_class, (t_method)messbox_clear, gensym("clear"), A_GIMME, 0);
class_addmethod(messbox_class, (t_method)messbox_bgcolor, gensym("bgcolor"), A_DEFSYMBOL, 0);
class_addmethod(messbox_class, (t_method)messbox_fgcolor, gensym("fgcolor"), A_DEFSYMBOL, 0);
class_addmethod(messbox_class, (t_method)messbox_bgcolor, gensym("bgcolor"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(messbox_class, (t_method)messbox_fgcolor, gensym("fgcolor"), A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(messbox_class, (t_method)messbox_click, gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
class_addmethod(messbox_class, (t_method)messbox_resize_callback, gensym("_resize"), A_FLOAT, 0);
class_addmethod(messbox_class, (t_method)messbox_motion_callback, gensym("_motion"), A_FLOAT, A_FLOAT, 0);
Expand Down
94 changes: 94 additions & 0 deletions Help-files/messbox-help.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#N canvas 743 142 559 536 10;
#X obj 306 5 cnv 15 250 40 empty empty empty 12 13 0 18 -128992 -233080
0;
#N canvas 382 141 749 319 (subpatch) 0;
#X coords 0 -1 1 1 252 42 2 0 0;
#X restore 305 4 pd;
#X obj 345 12 cnv 10 10 10 empty empty ELSE 0 15 2 30 -128992 -233080
0;
#X obj 78 41 cnv 4 4 4 empty empty message 0 28 2 18 -233017 -1 0;
#X obj 458 12 cnv 10 10 10 empty empty EL 0 6 2 13 -128992 -233080
0;
#X obj 478 12 cnv 10 10 10 empty empty Locus 0 6 2 13 -128992 -233080
0;
#X obj 515 12 cnv 10 10 10 empty empty Solus' 0 6 2 13 -128992 -233080
0;
#X obj 464 27 cnv 10 10 10 empty empty ELSE 0 6 2 13 -128992 -233080
0;
#X obj 502 27 cnv 10 10 10 empty empty library 0 6 2 13 -128992 -233080
0;
#X obj 3 4 cnv 15 301 42 empty empty messbox 20 20 2 37 -233017 -1
0;
#N canvas 0 22 450 278 (subpatch) 0;
#X coords 0 1 100 -1 302 42 1;
#X restore 3 4 graph;
#X obj 4 305 cnv 3 550 3 empty empty inlets 8 12 0 13 -228856 -1 0
;
#X obj 4 420 cnv 3 550 3 empty empty outlets 8 12 0 13 -228856 -1 0
;
#X obj 4 453 cnv 3 550 3 empty empty flags 8 12 0 13 -228856 -1 0;
#X obj 125 430 cnv 17 3 17 empty empty 0 5 9 0 16 -228856 -162280 0
;
#X obj 126 314 cnv 17 3 102 empty empty 0 5 9 0 16 -228856 -162280
0;
#X obj 4 509 cnv 15 552 21 empty empty empty 20 12 0 14 -233017 -33289
0;
#X text 195 430 anything;
#X obj 4 481 cnv 3 550 3 empty empty click 8 12 0 13 -228856 -1 0;
#X text 249 430 - the message;
#X obj 180 274 else/display;
#N canvas 1081 283 428 454 syntax 0;
#X text 38 19 Like a regular message box \, a comma will split the
message in different ones inside the same box.;
#X obj 106 186 print Message;
#X obj 120 398 print Message;
#X obj 347 324 r f;
#X obj 347 350 else/display;
#X obj 120 287 bng 15 250 50 0 empty empty empty 17 7 0 10 -228856
-1 -1;
#X obj 106 109 else/messbox 200 60 235 235 235 0 0 0 0 12;
#X msg 107 75 set 1 \\\, 2 \\\, 3 \, bang;
#X obj 120 318 else/messbox 200 60 235 235 235 0 0 0 0 12;
#X text 338 242 \; f 8;
#X text 42 229 It can also deal with semicolons \, which turn the message
box into a send object. Try typing something like =>;
#X connect 3 0 4 0;
#X connect 5 0 8 0;
#X connect 6 0 1 0;
#X connect 7 0 6 0;
#X connect 8 0 2 0;
#X restore 475 277 pd syntax;
#X text 218 313 bang;
#X obj 35 41 cnv 4 4 4 empty empty GUI 0 28 2 18 -233017 -1 0;
#X text 39 244 see also:;
#X text 248 313 - outputs the message, f 33;
#X obj 150 41 cnv 4 4 4 empty empty box 0 28 2 18 -233017 -1 0;
#X obj 180 198 else/messbox 200 60 235 235 235 0 0 0 0 12;
#X text 71 87 The [messbox] object is an object you can type in messages
while in run mode \, like atom boxes. Any message type is possible.
It deals with comma and semicolons in the same way as regular message
boxes. See [pd syntax] for more details., f 69;
#X obj 41 266 else/message;
#X obj 180 164 bng 15 250 50 0 empty empty empty 17 7 0 10 -228856
-1 -1;
#X msg 210 163 set this is a message;
#X text 351 161 <= set message;
#X text 68 164 output message =>;
#X text 68 209 click and type =>;
#X text 388 215 <= shift+click to output;
#X text 248 327 - sets the message, f 33;
#X text 158 327 set <anything>;
#X text 140 341 append <anything>;
#X text 248 341 - appends to the message, f 33;
#X text 146 356 fontsize <float>;
#X text 248 356 - sets font size, f 33;
#X text 170 370 bold <float>;
#X text 248 370 - non zero sets to bold, f 33;
#X text 248 384 - RGB background color, f 33;
#X text 140 384 bgcolor <f \, f \, f>;
#X text 140 399 fgcolor <f \, f \, f>;
#X text 248 399 - RGB foreground (text) color, f 33;
#X text 161 488 "shift + clicking" on the outputs the message;
#X connect 27 0 20 0;
#X connect 30 0 27 0;
#X connect 31 0 27 0;
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ nbang.class.sources := Classes/Source/nbang.c
merge.class.sources := Classes/Source/merge.c
format.class.sources := Classes/Source/format.c
message.class.sources := Classes/Source/message.c
messbox.class.sources := Classes/Source/messbox.c
mouse.class.sources := Classes/Source/mouse.c
note.in.class.sources := Classes/Source/note.in.c
note.out.class.sources := Classes/Source/note.out.c
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@




This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2,
as published by Sam Hocevar. See License.txt <https://github.com/porres/pd-else/blob/master/License.txt> and <http://www.wtfpl.net/> for more details
Expand Down Expand Up @@ -109,7 +110,7 @@ Cross compiling is also possible with something like this

--------------------------------------------------------------------------

## Current Object list (369 objects):
## Current Object list (370 objects):

**ASSORTED: [04]**
- [table~]
Expand Down Expand Up @@ -483,6 +484,7 @@ Cross compiling is also possible with something like this
- [trighold~]

**ANALYSIS: [13]**

- [changed~]
- [changed2~]
- [detect~]
Expand All @@ -497,9 +499,10 @@ Cross compiling is also possible with something like this
- [vu~]
- [zerocross~]

**GUI: [30]**
**GUI: [31]**

- [gui]
- [messbox]
- [mtx.ctl]
- [biplot]
- [pic]
Expand Down
1 change: 1 addition & 0 deletions extra/else-v1.0beta29-objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ median~ x
median x
merge x
message x
messbox x
meter x
meter~ x
meter2~ x
Expand Down

0 comments on commit be0dc89

Please sign in to comment.