summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/g_numbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_numbox.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/g_numbox.c906
1 files changed, 0 insertions, 906 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_numbox.c b/apps/plugins/pdbox/PDa/src/g_numbox.c
index e7421204d3..1c4dbb5e48 100644
--- a/apps/plugins/pdbox/PDa/src/g_numbox.c
+++ b/apps/plugins/pdbox/PDa/src/g_numbox.c
@@ -905,910 +905,4 @@ void g_numbox_setup(void)
905 class_setsavefn(my_numbox_class, my_numbox_save); 905 class_setsavefn(my_numbox_class, my_numbox_save);
906 class_setpropertiesfn(my_numbox_class, my_numbox_properties); 906 class_setpropertiesfn(my_numbox_class, my_numbox_properties);
907} 907}
908/* Copyright (c) 1997-1999 Miller Puckette.
909 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
910 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
911
912/* my_numbox.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */
913
914#include <stdlib.h>
915#include <string.h>
916#include <stdio.h>
917#include <ctype.h>
918#include "m_pd.h"
919#include "g_canvas.h"
920#include "t_tk.h"
921#include "g_all_guis.h"
922#include <math.h>
923
924#ifdef MSW
925#include <io.h>
926#else
927#include <unistd.h>
928#endif
929
930/*------------------ global varaibles -------------------------*/
931
932
933/*------------------ global functions -------------------------*/
934
935static void my_numbox_key(void *z, t_floatarg fkey);
936
937/* ------------ nmx gui-my number box ----------------------- */
938
939t_widgetbehavior my_numbox_widgetbehavior;
940static t_class *my_numbox_class;
941
942/* widget helper functions */
943
944static void my_numbox_tick_reset(t_my_numbox *x)
945{
946 if(x->x_gui.x_fsf.x_change)
947 {
948 x->x_gui.x_fsf.x_change = 0;
949 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
950 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
951 }
952}
953
954static void my_numbox_tick_wait(t_my_numbox *x)
955{
956 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
957}
958
959void my_numbox_clip(t_my_numbox *x)
960{
961 if(x->x_val < x->x_min)
962 x->x_val = x->x_min;
963 if(x->x_val > x->x_max)
964 x->x_val = x->x_max;
965}
966
967void my_numbox_calc_fontwidth(t_my_numbox *x)
968{
969 int w, f=31;
970
971 if(x->x_gui.x_fsf.x_font_style == 1)
972 f = 27;
973 else if(x->x_gui.x_fsf.x_font_style == 2)
974 f = 25;
975
976 w = x->x_gui.x_fontsize * f * x->x_gui.x_w;
977 w /= 36;
978 x->x_numwidth = w + (x->x_gui.x_h / 2) + 4;
979}
980
981void my_numbox_ftoa(t_my_numbox *x)
982{
983 double f=x->x_val;
984 int bufsize, is_exp=0, i, idecimal;
985
986 sprintf(x->x_buf, "%g", f);
987 bufsize = strlen(x->x_buf);
988 if(bufsize >= 5)/* if it is in exponential mode */
989 {
990 i = bufsize - 4;
991 if((x->x_buf[i] == 'e') || (x->x_buf[i] == 'E'))
992 is_exp = 1;
993 }
994 if(bufsize > x->x_gui.x_w)/* if to reduce */
995 {
996 if(is_exp)
997 {
998 if(x->x_gui.x_w <= 5)
999 {
1000 x->x_buf[0] = (f < 0.0 ? '-' : '+');
1001 x->x_buf[1] = 0;
1002 }
1003 i = bufsize - 4;
1004 for(idecimal=0; idecimal < i; idecimal++)
1005 if(x->x_buf[idecimal] == '.')
1006 break;
1007 if(idecimal > (x->x_gui.x_w - 4))
1008 {
1009 x->x_buf[0] = (f < 0.0 ? '-' : '+');
1010 x->x_buf[1] = 0;
1011 }
1012 else
1013 {
1014 int new_exp_index=x->x_gui.x_w-4, old_exp_index=bufsize-4;
1015
1016 for(i=0; i < 4; i++, new_exp_index++, old_exp_index++)
1017 x->x_buf[new_exp_index] = x->x_buf[old_exp_index];
1018 x->x_buf[x->x_gui.x_w] = 0;
1019 }
1020
1021 }
1022 else
1023 {
1024 for(idecimal=0; idecimal < bufsize; idecimal++)
1025 if(x->x_buf[idecimal] == '.')
1026 break;
1027 if(idecimal > x->x_gui.x_w)
1028 {
1029 x->x_buf[0] = (f < 0.0 ? '-' : '+');
1030 x->x_buf[1] = 0;
1031 }
1032 else
1033 x->x_buf[x->x_gui.x_w] = 0;
1034 }
1035 }
1036}
1037
1038static void my_numbox_draw_update(t_my_numbox *x, t_glist *glist)
1039{
1040 if (glist_isvisible(glist))
1041 {
1042 if(x->x_gui.x_fsf.x_change)
1043 {
1044 if(x->x_buf[0])
1045 {
1046 char *cp=x->x_buf;
1047 int sl = strlen(x->x_buf);
1048
1049 x->x_buf[sl] = '>';
1050 x->x_buf[sl+1] = 0;
1051 if(sl >= x->x_gui.x_w)
1052 cp += sl - x->x_gui.x_w + 1;
1053 sys_vgui(
1054 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
1055 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, cp);
1056 x->x_buf[sl] = 0;
1057 }
1058 else
1059 {
1060 my_numbox_ftoa(x);
1061 sys_vgui(
1062 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
1063 glist_getcanvas(glist), x, IEM_GUI_COLOR_EDITED, x->x_buf);
1064 x->x_buf[0] = 0;
1065 }
1066 }
1067 else
1068 {
1069 my_numbox_ftoa(x);
1070 sys_vgui(
1071 ".x%x.c itemconfigure %xNUMBER -fill #%6.6x -text {%s} \n",
1072 glist_getcanvas(glist), x,
1073 x->x_gui.x_fsf.x_selected?
1074 IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol,
1075 x->x_buf);
1076 x->x_buf[0] = 0;
1077 }
1078 }
1079}
1080
1081static void my_numbox_draw_new(t_my_numbox *x, t_glist *glist)
1082{
1083 int half=x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
1084 int xpos=text_xpix(&x->x_gui.x_obj, glist);
1085 int ypos=text_ypix(&x->x_gui.x_obj, glist);
1086 t_canvas *canvas=glist_getcanvas(glist);
1087
1088 sys_vgui(
1089".x%x.c create polygon %d %d %d %d %d %d %d %d %d %d -outline #%6.6x \
1090-fill #%6.6x -tags %xBASE1\n",
1091 canvas, xpos, ypos,
1092 xpos + x->x_numwidth-4, ypos,
1093 xpos + x->x_numwidth, ypos+4,
1094 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
1095 xpos, ypos + x->x_gui.x_h,
1096 IEM_GUI_COLOR_NORMAL, x->x_gui.x_bcol, x);
1097 sys_vgui(
1098 ".x%x.c create line %d %d %d %d %d %d -fill #%6.6x -tags %xBASE2\n",
1099 canvas, xpos, ypos,
1100 xpos + half, ypos + half,
1101 xpos, ypos + x->x_gui.x_h,
1102 x->x_gui.x_fcol, x);
1103 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
1104 -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n",
1105 canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy,
1106 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"",
1107 x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x);
1108 my_numbox_ftoa(x);
1109 sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \
1110 -font {%s %d bold} -fill #%6.6x -tags %xNUMBER\n",
1111 canvas, xpos+half+2, ypos+half+d,
1112 x->x_buf, x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_fcol, x);
1113 if(!x->x_gui.x_fsf.x_snd_able)
1114 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
1115 canvas,
1116 xpos, ypos + x->x_gui.x_h-1,
1117 xpos+IOWIDTH, ypos + x->x_gui.x_h,
1118 x, 0);
1119 if(!x->x_gui.x_fsf.x_rcv_able)
1120 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
1121 canvas,
1122 xpos, ypos,
1123 xpos+IOWIDTH, ypos+1,
1124 x, 0);
1125}
1126
1127static void my_numbox_draw_move(t_my_numbox *x, t_glist *glist)
1128{
1129 int half = x->x_gui.x_h/2, d=1+x->x_gui.x_h/34;
1130 int xpos=text_xpix(&x->x_gui.x_obj, glist);
1131 int ypos=text_ypix(&x->x_gui.x_obj, glist);
1132 t_canvas *canvas=glist_getcanvas(glist);
1133
1134 sys_vgui(".x%x.c coords %xBASE1 %d %d %d %d %d %d %d %d %d %d\n",
1135 canvas, x, xpos, ypos,
1136 xpos + x->x_numwidth-4, ypos,
1137 xpos + x->x_numwidth, ypos+4,
1138 xpos + x->x_numwidth, ypos + x->x_gui.x_h,
1139 xpos, ypos + x->x_gui.x_h);
1140 sys_vgui(".x%x.c coords %xBASE2 %d %d %d %d %d %d\n",
1141 canvas, x, xpos, ypos,
1142 xpos + half, ypos + half,
1143 xpos, ypos + x->x_gui.x_h);
1144 sys_vgui(".x%x.c coords %xLABEL %d %d\n",
1145 canvas, x, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy);
1146 sys_vgui(".x%x.c coords %xNUMBER %d %d\n",
1147 canvas, x, xpos+half+2, ypos+half+d);
1148 if(!x->x_gui.x_fsf.x_snd_able)
1149 sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n",
1150 canvas, x, 0,
1151 xpos, ypos + x->x_gui.x_h-1,
1152 xpos+IOWIDTH, ypos + x->x_gui.x_h);
1153 if(!x->x_gui.x_fsf.x_rcv_able)
1154 sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n",
1155 canvas, x, 0,
1156 xpos, ypos,
1157 xpos+IOWIDTH, ypos+1);
1158}
1159
1160static void my_numbox_draw_erase(t_my_numbox* x,t_glist* glist)
1161{
1162 t_canvas *canvas=glist_getcanvas(glist);
1163
1164 sys_vgui(".x%x.c delete %xBASE1\n", canvas, x);
1165 sys_vgui(".x%x.c delete %xBASE2\n", canvas, x);
1166 sys_vgui(".x%x.c delete %xLABEL\n", canvas, x);
1167 sys_vgui(".x%x.c delete %xNUMBER\n", canvas, x);
1168 if(!x->x_gui.x_fsf.x_snd_able)
1169 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
1170 if(!x->x_gui.x_fsf.x_rcv_able)
1171 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
1172}
1173
1174static void my_numbox_draw_config(t_my_numbox* x,t_glist* glist)
1175{
1176 t_canvas *canvas=glist_getcanvas(glist);
1177
1178 sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n",
1179 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
1180 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol,
1181 strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"");
1182 sys_vgui(".x%x.c itemconfigure %xNUMBER -font {%s %d bold} -fill #%6.6x \n",
1183 canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize,
1184 x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
1185 sys_vgui(".x%x.c itemconfigure %xBASE1 -fill #%6.6x\n", canvas,
1186 x, x->x_gui.x_bcol);
1187 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n", canvas,
1188 x, x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_fcol);
1189}
1190
1191static void my_numbox_draw_io(t_my_numbox* x,t_glist* glist, int old_snd_rcv_flags)
1192{
1193 int xpos=text_xpix(&x->x_gui.x_obj, glist);
1194 int ypos=text_ypix(&x->x_gui.x_obj, glist);
1195 t_canvas *canvas=glist_getcanvas(glist);
1196
1197 if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able)
1198 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n",
1199 canvas,
1200 xpos, ypos + x->x_gui.x_h-1,
1201 xpos+IOWIDTH, ypos + x->x_gui.x_h,
1202 x, 0);
1203 if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able)
1204 sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0);
1205 if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able)
1206 sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n",
1207 canvas,
1208 xpos, ypos,
1209 xpos+IOWIDTH, ypos+1,
1210 x, 0);
1211 if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able)
1212 sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0);
1213}
1214
1215static void my_numbox_draw_select(t_my_numbox *x, t_glist *glist)
1216{
1217 t_canvas *canvas=glist_getcanvas(glist);
1218
1219 if(x->x_gui.x_fsf.x_selected)
1220 {
1221 if(x->x_gui.x_fsf.x_change)
1222 {
1223 x->x_gui.x_fsf.x_change = 0;
1224 clock_unset(x->x_clock_reset);
1225 x->x_buf[0] = 0;
1226 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1227 }
1228 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
1229 canvas, x, IEM_GUI_COLOR_SELECTED);
1230 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
1231 canvas, x, IEM_GUI_COLOR_SELECTED);
1232 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
1233 canvas, x, IEM_GUI_COLOR_SELECTED);
1234 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
1235 canvas, x, IEM_GUI_COLOR_SELECTED);
1236 }
1237 else
1238 {
1239 sys_vgui(".x%x.c itemconfigure %xBASE1 -outline #%6.6x\n",
1240 canvas, x, IEM_GUI_COLOR_NORMAL);
1241 sys_vgui(".x%x.c itemconfigure %xBASE2 -fill #%6.6x\n",
1242 canvas, x, x->x_gui.x_fcol);
1243 sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n",
1244 canvas, x, x->x_gui.x_lcol);
1245 sys_vgui(".x%x.c itemconfigure %xNUMBER -fill #%6.6x\n",
1246 canvas, x, x->x_gui.x_fcol);
1247 }
1248}
1249
1250void my_numbox_draw(t_my_numbox *x, t_glist *glist, int mode)
1251{
1252 if(mode == IEM_GUI_DRAW_MODE_UPDATE)
1253 my_numbox_draw_update(x, glist);
1254 else if(mode == IEM_GUI_DRAW_MODE_MOVE)
1255 my_numbox_draw_move(x, glist);
1256 else if(mode == IEM_GUI_DRAW_MODE_NEW)
1257 my_numbox_draw_new(x, glist);
1258 else if(mode == IEM_GUI_DRAW_MODE_SELECT)
1259 my_numbox_draw_select(x, glist);
1260 else if(mode == IEM_GUI_DRAW_MODE_ERASE)
1261 my_numbox_draw_erase(x, glist);
1262 else if(mode == IEM_GUI_DRAW_MODE_CONFIG)
1263 my_numbox_draw_config(x, glist);
1264 else if(mode >= IEM_GUI_DRAW_MODE_IO)
1265 my_numbox_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO);
1266}
1267
1268/* ------------------------ nbx widgetbehaviour----------------------------- */
1269
1270
1271static void my_numbox_getrect(t_gobj *z, t_glist *glist,
1272 int *xp1, int *yp1, int *xp2, int *yp2)
1273{
1274 t_my_numbox* x = (t_my_numbox*)z;
1275
1276 *xp1 = text_xpix(&x->x_gui.x_obj, glist);
1277 *yp1 = text_ypix(&x->x_gui.x_obj, glist);
1278 *xp2 = *xp1 + x->x_numwidth;
1279 *yp2 = *yp1 + x->x_gui.x_h;
1280}
1281
1282static void my_numbox_save(t_gobj *z, t_binbuf *b)
1283{
1284 t_my_numbox *x = (t_my_numbox *)z;
1285 int bflcol[3];
1286 t_symbol *srl[3];
1287
1288 iemgui_save(&x->x_gui, srl, bflcol);
1289 if(x->x_gui.x_fsf.x_change)
1290 {
1291 x->x_gui.x_fsf.x_change = 0;
1292 clock_unset(x->x_clock_reset);
1293 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
1294 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1295
1296 }
1297 binbuf_addv(b, "ssiisiiffiisssiiiiiiifi", gensym("#X"),gensym("obj"),
1298 (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix,
1299 gensym("nbx"), x->x_gui.x_w, x->x_gui.x_h,
1300 (float)x->x_min, (float)x->x_max,
1301 x->x_lin0_log1, iem_symargstoint(&x->x_gui.x_isa),
1302 srl[0], srl[1], srl[2],
1303 x->x_gui.x_ldx, x->x_gui.x_ldy,
1304 iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize,
1305 bflcol[0], bflcol[1], bflcol[2],
1306 x->x_val, x->x_log_height);
1307 binbuf_addv(b, ";");
1308}
1309
1310int my_numbox_check_minmax(t_my_numbox *x, double min, double max)
1311{
1312 int ret=0;
1313
1314 if(x->x_lin0_log1)
1315 {
1316 if((min == 0.0)&&(max == 0.0))
1317 max = 1.0;
1318 if(max > 0.0)
1319 {
1320 if(min <= 0.0)
1321 min = 0.01*max;
1322 }
1323 else
1324 {
1325 if(min > 0.0)
1326 max = 0.01*min;
1327 }
1328 }
1329 x->x_min = min;
1330 x->x_max = max;
1331 if(x->x_val < x->x_min)
1332 {
1333 x->x_val = x->x_min;
1334 ret = 1;
1335 }
1336 if(x->x_val > x->x_max)
1337 {
1338 x->x_val = x->x_max;
1339 ret = 1;
1340 }
1341 if(x->x_lin0_log1)
1342 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
1343 else
1344 x->x_k = 1.0;
1345 return(ret);
1346}
1347
1348static void my_numbox_properties(t_gobj *z, t_glist *owner)
1349{
1350 t_my_numbox *x = (t_my_numbox *)z;
1351 char buf[800];
1352 t_symbol *srl[3];
1353
1354 iemgui_properties(&x->x_gui, srl);
1355 if(x->x_gui.x_fsf.x_change)
1356 {
1357 x->x_gui.x_fsf.x_change = 0;
1358 clock_unset(x->x_clock_reset);
1359 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
1360 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1361 908
1362 }
1363 sprintf(buf, "pdtk_iemgui_dialog %%s NUMBERBOX \
1364 -------dimensions(digits)(pix):------- %d %d width: %d %d height: \
1365 -----------output-range:----------- %g min: %g max: %d \
1366 %d lin log %d %d log-height: %d \
1367 %s %s \
1368 %s %d %d \
1369 %d %d \
1370 %d %d %d\n",
1371 x->x_gui.x_w, 1, x->x_gui.x_h, 8,
1372 x->x_min, x->x_max, 0,/*no_schedule*/
1373 x->x_lin0_log1, x->x_gui.x_isa.x_loadinit, -1,
1374 x->x_log_height, /*no multi, but iem-characteristic*/
1375 srl[0]->s_name, srl[1]->s_name,
1376 srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy,
1377 x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize,
1378 0xffffff & x->x_gui.x_bcol, 0xffffff & x->x_gui.x_fcol,
1379 0xffffff & x->x_gui.x_lcol);
1380 gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf);
1381}
1382
1383static void my_numbox_bang(t_my_numbox *x)
1384{
1385 outlet_float(x->x_gui.x_obj.ob_outlet, x->x_val);
1386 if(x->x_gui.x_fsf.x_snd_able && x->x_gui.x_snd->s_thing)
1387 pd_float(x->x_gui.x_snd->s_thing, x->x_val);
1388}
1389
1390static void my_numbox_dialog(t_my_numbox *x, t_symbol *s, int argc,
1391 t_atom *argv)
1392{
1393 t_symbol *srl[3];
1394 int w = (int)atom_getintarg(0, argc, argv);
1395 int h = (int)atom_getintarg(1, argc, argv);
1396 double min = (double)atom_getfloatarg(2, argc, argv);
1397 double max = (double)atom_getfloatarg(3, argc, argv);
1398 int lilo = (int)atom_getintarg(4, argc, argv);
1399 int log_height = (int)atom_getintarg(6, argc, argv);
1400 int sr_flags;
1401
1402 if(lilo != 0) lilo = 1;
1403 x->x_lin0_log1 = lilo;
1404 sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv);
1405 if(w < 1)
1406 w = 1;
1407 x->x_gui.x_w = w;
1408 if(h < 8)
1409 h = 8;
1410 x->x_gui.x_h = h;
1411 if(log_height < 10)
1412 log_height = 10;
1413 x->x_log_height = log_height;
1414 my_numbox_calc_fontwidth(x);
1415 /*if(my_numbox_check_minmax(x, min, max))
1416 my_numbox_bang(x);*/
1417 my_numbox_check_minmax(x, min, max);
1418 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1419 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags);
1420 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG);
1421 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE);
1422 canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x);
1423}
1424
1425static void my_numbox_motion(t_my_numbox *x, t_floatarg dx, t_floatarg dy)
1426{
1427 double k2=1.0;
1428
1429 if(x->x_gui.x_fsf.x_finemoved)
1430 k2 = 0.01;
1431 if(x->x_lin0_log1)
1432 x->x_val *= pow(x->x_k, -k2*dy);
1433 else
1434 x->x_val -= k2*dy;
1435 my_numbox_clip(x);
1436 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1437 my_numbox_bang(x);
1438 clock_unset(x->x_clock_reset);
1439}
1440
1441static void my_numbox_click(t_my_numbox *x, t_floatarg xpos, t_floatarg ypos,
1442 t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
1443{
1444 glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.te_g,
1445 (t_glistmotionfn)my_numbox_motion, my_numbox_key, xpos, ypos);
1446}
1447
1448static int my_numbox_newclick(t_gobj *z, struct _glist *glist,
1449 int xpix, int ypix, int shift, int alt, int dbl, int doit)
1450{
1451 t_my_numbox* x = (t_my_numbox *)z;
1452
1453 if(doit)
1454 {
1455 my_numbox_click( x, (t_floatarg)xpix, (t_floatarg)ypix,
1456 (t_floatarg)shift, 0, (t_floatarg)alt);
1457 if(shift)
1458 x->x_gui.x_fsf.x_finemoved = 1;
1459 else
1460 x->x_gui.x_fsf.x_finemoved = 0;
1461 if(!x->x_gui.x_fsf.x_change)
1462 {
1463 clock_delay(x->x_clock_wait, 50);
1464 x->x_gui.x_fsf.x_change = 1;
1465 clock_delay(x->x_clock_reset, 3000);
1466 /* glist_grab(x->x_gui.x_glist, &x->x_gui.x_obj.ob_g,
1467 0, my_numbox_key, 0, 0); */
1468
1469 x->x_buf[0] = 0;
1470 }
1471 else
1472 {
1473 x->x_gui.x_fsf.x_change = 0;
1474 clock_unset(x->x_clock_reset);
1475 glist_grab(x->x_gui.x_glist, 0, 0, 0, 0, 0);
1476 x->x_buf[0] = 0;
1477 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1478 }
1479 }
1480 return (1);
1481}
1482
1483static void my_numbox_set(t_my_numbox *x, t_floatarg f)
1484{
1485 x->x_val = f;
1486 my_numbox_clip(x);
1487 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1488}
1489
1490static void my_numbox_log_height(t_my_numbox *x, t_floatarg lh)
1491{
1492 if(lh < 10.0)
1493 lh = 10.0;
1494 x->x_log_height = (int)lh;
1495 if(x->x_lin0_log1)
1496 x->x_k = exp(log(x->x_max/x->x_min)/(double)(x->x_log_height));
1497 else
1498 x->x_k = 1.0;
1499
1500}
1501
1502static void my_numbox_float(t_my_numbox *x, t_floatarg f)
1503{
1504 my_numbox_set(x, f);
1505 if(x->x_gui.x_fsf.x_put_in2out)
1506 my_numbox_bang(x);
1507}
1508
1509static void my_numbox_size(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1510{
1511 int h, w;
1512
1513 w = (int)atom_getintarg(0, ac, av);
1514 if(w < 1)
1515 w = 1;
1516 x->x_gui.x_w = w;
1517 if(ac > 1)
1518 {
1519 h = (int)atom_getintarg(1, ac, av);
1520 if(h < 8)
1521 h = 8;
1522 x->x_gui.x_h = h;
1523 }
1524 my_numbox_calc_fontwidth(x);
1525 iemgui_size((void *)x, &x->x_gui);
1526}
1527
1528static void my_numbox_delta(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1529{iemgui_delta((void *)x, &x->x_gui, s, ac, av);}
1530
1531static void my_numbox_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1532{iemgui_pos((void *)x, &x->x_gui, s, ac, av);}
1533
1534static void my_numbox_range(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1535{
1536 if(my_numbox_check_minmax(x, (double)atom_getfloatarg(0, ac, av),
1537 (double)atom_getfloatarg(1, ac, av)))
1538 {
1539 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1540 /*my_numbox_bang(x);*/
1541 }
1542}
1543
1544static void my_numbox_color(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1545{iemgui_color((void *)x, &x->x_gui, s, ac, av);}
1546
1547static void my_numbox_send(t_my_numbox *x, t_symbol *s)
1548{iemgui_send(x, &x->x_gui, s);}
1549
1550static void my_numbox_receive(t_my_numbox *x, t_symbol *s)
1551{iemgui_receive(x, &x->x_gui, s);}
1552
1553static void my_numbox_label(t_my_numbox *x, t_symbol *s)
1554{iemgui_label((void *)x, &x->x_gui, s);}
1555
1556static void my_numbox_label_pos(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1557{iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);}
1558
1559static void my_numbox_label_font(t_my_numbox *x,
1560 t_symbol *s, int ac, t_atom *av)
1561{
1562 int f = (int)atom_getintarg(1, ac, av);
1563
1564 if(f < 4)
1565 f = 4;
1566 x->x_gui.x_fontsize = f;
1567 f = (int)atom_getintarg(0, ac, av);
1568 if((f < 0) || (f > 2))
1569 f = 0;
1570 x->x_gui.x_fsf.x_font_style = f;
1571 my_numbox_calc_fontwidth(x);
1572 iemgui_label_font((void *)x, &x->x_gui, s, ac, av);
1573}
1574
1575static void my_numbox_log(t_my_numbox *x)
1576{
1577 x->x_lin0_log1 = 1;
1578 if(my_numbox_check_minmax(x, x->x_min, x->x_max))
1579 {
1580 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1581 /*my_numbox_bang(x);*/
1582 }
1583}
1584
1585static void my_numbox_lin(t_my_numbox *x)
1586{
1587 x->x_lin0_log1 = 0;
1588}
1589
1590static void my_numbox_init(t_my_numbox *x, t_floatarg f)
1591{
1592 x->x_gui.x_isa.x_loadinit = (f==0.0)?0:1;
1593}
1594
1595static void my_numbox_loadbang(t_my_numbox *x)
1596{
1597 if(!sys_noloadbang && x->x_gui.x_isa.x_loadinit)
1598 {
1599 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1600 my_numbox_bang(x);
1601 }
1602}
1603
1604static void my_numbox_key(void *z, t_floatarg fkey)
1605{
1606 t_my_numbox *x = z;
1607 char c=fkey;
1608 char buf[3];
1609 buf[1] = 0;
1610
1611 if (c == 0)
1612 {
1613 x->x_gui.x_fsf.x_change = 0;
1614 clock_unset(x->x_clock_reset);
1615 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1616 return;
1617 }
1618 if(((c>='0')&&(c<='9'))||(c=='.')||(c=='-')||
1619 (c=='e')||(c=='+')||(c=='E'))
1620 {
1621 if(strlen(x->x_buf) < (IEMGUI_MAX_NUM_LEN-2))
1622 {
1623 buf[0] = c;
1624 strcat(x->x_buf, buf);
1625 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1626 }
1627 }
1628 else if((c=='\b')||(c==127))
1629 {
1630 int sl=strlen(x->x_buf)-1;
1631
1632 if(sl < 0)
1633 sl = 0;
1634 x->x_buf[sl] = 0;
1635 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1636 }
1637 else if((c=='\n')||(c==13))
1638 {
1639 x->x_val = atof(x->x_buf);
1640 x->x_buf[0] = 0;
1641 x->x_gui.x_fsf.x_change = 0;
1642 clock_unset(x->x_clock_reset);
1643 my_numbox_clip(x);
1644 my_numbox_bang(x);
1645 (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_UPDATE);
1646 }
1647 clock_delay(x->x_clock_reset, 3000);
1648}
1649
1650static void my_numbox_list(t_my_numbox *x, t_symbol *s, int ac, t_atom *av)
1651{
1652 if (IS_A_FLOAT(av,0))
1653 {
1654 my_numbox_set(x, atom_getfloatarg(0, ac, av));
1655 my_numbox_bang(x);
1656 }
1657}
1658
1659static void *my_numbox_new(t_symbol *s, int argc, t_atom *argv)
1660{
1661 t_my_numbox *x = (t_my_numbox *)pd_new(my_numbox_class);
1662 int bflcol[]={-262144, -1, -1};
1663 int w=5, h=14;
1664 int lilo=0, f=0, ldx=0, ldy=-6;
1665 int fs=10;
1666 int log_height=256;
1667 double min=-1.0e+37, max=1.0e+37,v=0.0;
1668 char str[144];
1669
1670 if((argc >= 17)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1)
1671 &&IS_A_FLOAT(argv,2)&&IS_A_FLOAT(argv,3)
1672 &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5)
1673 &&(IS_A_SYMBOL(argv,6)||IS_A_FLOAT(argv,6))
1674 &&(IS_A_SYMBOL(argv,7)||IS_A_FLOAT(argv,7))
1675 &&(IS_A_SYMBOL(argv,8)||IS_A_FLOAT(argv,8))
1676 &&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)
1677 &&IS_A_FLOAT(argv,11)&&IS_A_FLOAT(argv,12)&&IS_A_FLOAT(argv,13)
1678 &&IS_A_FLOAT(argv,14)&&IS_A_FLOAT(argv,15)&&IS_A_FLOAT(argv,16))
1679 {
1680 w = (int)atom_getintarg(0, argc, argv);
1681 h = (int)atom_getintarg(1, argc, argv);
1682 min = (double)atom_getfloatarg(2, argc, argv);
1683 max = (double)atom_getfloatarg(3, argc, argv);
1684 lilo = (int)atom_getintarg(4, argc, argv);
1685 iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(5, argc, argv));
1686 iemgui_new_getnames(&x->x_gui, 6, argv);
1687 ldx = (int)atom_getintarg(9, argc, argv);
1688 ldy = (int)atom_getintarg(10, argc, argv);
1689 iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(11, argc, argv));
1690 fs = (int)atom_getintarg(12, argc, argv);
1691 bflcol[0] = (int)atom_getintarg(13, argc, argv);
1692 bflcol[1] = (int)atom_getintarg(14, argc, argv);
1693 bflcol[2] = (int)atom_getintarg(15, argc, argv);
1694 v = atom_getfloatarg(16, argc, argv);
1695 }
1696 else iemgui_new_getnames(&x->x_gui, 6, 0);
1697 if((argc == 18)&&IS_A_FLOAT(argv,17))
1698 {
1699 log_height = (int)atom_getintarg(17, argc, argv);
1700 }
1701 x->x_gui.x_draw = (t_iemfunptr)my_numbox_draw;
1702 x->x_gui.x_fsf.x_snd_able = 1;
1703 x->x_gui.x_fsf.x_rcv_able = 1;
1704 x->x_gui.x_glist = (t_glist *)canvas_getcurrent();
1705 if(x->x_gui.x_isa.x_loadinit)
1706 x->x_val = v;
1707 else
1708 x->x_val = 0.0;
1709 if(lilo != 0) lilo = 1;
1710 x->x_lin0_log1 = lilo;
1711 if(log_height < 10)
1712 log_height = 10;
1713 x->x_log_height = log_height;
1714 if (!strcmp(x->x_gui.x_snd->s_name, "empty"))
1715 x->x_gui.x_fsf.x_snd_able = 0;
1716 if (!strcmp(x->x_gui.x_rcv->s_name, "empty"))
1717 x->x_gui.x_fsf.x_rcv_able = 0;
1718 if(x->x_gui.x_fsf.x_font_style == 1) strcpy(x->x_gui.x_font, "helvetica");
1719 else if(x->x_gui.x_fsf.x_font_style == 2) strcpy(x->x_gui.x_font, "times");
1720 else { x->x_gui.x_fsf.x_font_style = 0;
1721 strcpy(x->x_gui.x_font, "courier"); }
1722 if (x->x_gui.x_fsf.x_rcv_able)
1723 pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1724 x->x_gui.x_ldx = ldx;
1725 x->x_gui.x_ldy = ldy;
1726 if(fs < 4)
1727 fs = 4;
1728 x->x_gui.x_fontsize = fs;
1729 if(w < 1)
1730 w = 1;
1731 x->x_gui.x_w = w;
1732 if(h < 8)
1733 h = 8;
1734 x->x_gui.x_h = h;
1735 x->x_buf[0] = 0;
1736 my_numbox_calc_fontwidth(x);
1737 my_numbox_check_minmax(x, min, max);
1738 iemgui_all_colfromload(&x->x_gui, bflcol);
1739 iemgui_verify_snd_ne_rcv(&x->x_gui);
1740 x->x_clock_reset = clock_new(x, (t_method)my_numbox_tick_reset);
1741 x->x_clock_wait = clock_new(x, (t_method)my_numbox_tick_wait);
1742 x->x_gui.x_fsf.x_change = 0;
1743 outlet_new(&x->x_gui.x_obj, &s_float);
1744 return (x);
1745}
1746
1747static void my_numbox_free(t_my_numbox *x)
1748{
1749 if(x->x_gui.x_fsf.x_rcv_able)
1750 pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv);
1751 clock_free(x->x_clock_reset);
1752 clock_free(x->x_clock_wait);
1753 gfxstub_deleteforkey(x);
1754}
1755
1756void g_numbox_setup(void)
1757{
1758 my_numbox_class = class_new(gensym("nbx"), (t_newmethod)my_numbox_new,
1759 (t_method)my_numbox_free, sizeof(t_my_numbox), 0, A_GIMME, 0);
1760 class_addcreator((t_newmethod)my_numbox_new, gensym("my_numbox"),
1761 A_GIMME, 0);
1762 class_addbang(my_numbox_class,my_numbox_bang);
1763 class_addfloat(my_numbox_class,my_numbox_float);
1764 class_addlist(my_numbox_class, my_numbox_list);
1765 class_addmethod(my_numbox_class, (t_method)my_numbox_click,
1766 gensym("click"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, 0);
1767 class_addmethod(my_numbox_class, (t_method)my_numbox_motion,
1768 gensym("motion"), A_FLOAT, A_FLOAT, 0);
1769 class_addmethod(my_numbox_class, (t_method)my_numbox_dialog,
1770 gensym("dialog"), A_GIMME, 0);
1771 class_addmethod(my_numbox_class, (t_method)my_numbox_loadbang,
1772 gensym("loadbang"), 0);
1773 class_addmethod(my_numbox_class, (t_method)my_numbox_set,
1774 gensym("set"), A_FLOAT, 0);
1775 class_addmethod(my_numbox_class, (t_method)my_numbox_size,
1776 gensym("size"), A_GIMME, 0);
1777 class_addmethod(my_numbox_class, (t_method)my_numbox_delta,
1778 gensym("delta"), A_GIMME, 0);
1779 class_addmethod(my_numbox_class, (t_method)my_numbox_pos,
1780 gensym("pos"), A_GIMME, 0);
1781 class_addmethod(my_numbox_class, (t_method)my_numbox_range,
1782 gensym("range"), A_GIMME, 0);
1783 class_addmethod(my_numbox_class, (t_method)my_numbox_color,
1784 gensym("color"), A_GIMME, 0);
1785 class_addmethod(my_numbox_class, (t_method)my_numbox_send,
1786 gensym("send"), A_DEFSYM, 0);
1787 class_addmethod(my_numbox_class, (t_method)my_numbox_receive,
1788 gensym("receive"), A_DEFSYM, 0);
1789 class_addmethod(my_numbox_class, (t_method)my_numbox_label,
1790 gensym("label"), A_DEFSYM, 0);
1791 class_addmethod(my_numbox_class, (t_method)my_numbox_label_pos,
1792 gensym("label_pos"), A_GIMME, 0);
1793 class_addmethod(my_numbox_class, (t_method)my_numbox_label_font,
1794 gensym("label_font"), A_GIMME, 0);
1795 class_addmethod(my_numbox_class, (t_method)my_numbox_log,
1796 gensym("log"), 0);
1797 class_addmethod(my_numbox_class, (t_method)my_numbox_lin,
1798 gensym("lin"), 0);
1799 class_addmethod(my_numbox_class, (t_method)my_numbox_init,
1800 gensym("init"), A_FLOAT, 0);
1801 class_addmethod(my_numbox_class, (t_method)my_numbox_log_height,
1802 gensym("log_height"), A_FLOAT, 0);
1803 my_numbox_widgetbehavior.w_getrectfn = my_numbox_getrect;
1804 my_numbox_widgetbehavior.w_displacefn = iemgui_displace;
1805 my_numbox_widgetbehavior.w_selectfn = iemgui_select;
1806 my_numbox_widgetbehavior.w_activatefn = NULL;
1807 my_numbox_widgetbehavior.w_deletefn = iemgui_delete;
1808 my_numbox_widgetbehavior.w_visfn = iemgui_vis;
1809 my_numbox_widgetbehavior.w_clickfn = my_numbox_newclick;
1810 class_setwidget(my_numbox_class, &my_numbox_widgetbehavior);
1811 class_sethelpsymbol(my_numbox_class, gensym("numbox2"));
1812 class_setsavefn(my_numbox_class, my_numbox_save);
1813 class_setpropertiesfn(my_numbox_class, my_numbox_properties);
1814}