/* window.c * Main loop manages GEM windows, AES, mouse, menues, and drawing process. */ #include #include #include #include #include #include #include #include "\t\mandlbox.h" /*#define WI_KIND (SIZER|MOVER|FULLER| CLOSER|NAME|VSLIDE)*/ #define WI_KIND (CLOSER|NAME|VSLIDE) #define MIN_WIDTH (2*gl_wbox) #define MIN_HEIGHT (3*gl_hbox) int gl_hchar, gl_wchar, gl_wbox, gl_hbox; /* system sizes */ int ps_handle; /* physical screen (workstation) handle */ int vs_handle; /* virtual screen (workstation) handle */ int wi_handle; /* window handle */ int old_res; /* initial resolution of screen */ int xdesk,ydesk,hdesk,wdesk; /* size of whole desktop */ int xwork,ywork,hwork,wwork; /* size of current working window */ int xold,yold,hold,wold; /* size of screen before FULL cmd */ int msgbuff[8]; /* event message buffer */ int keycode; /* keycode returned by event-keyboard */ int mx,my; /* mouse x and y pos. */ int butdown; /* button state tested for, UP/DOWN */ int ret; /* dummy return variable */ int clut_rotate; /* mode */ /******* shared memory with draw.c: */ double Vx0, Vy0, Vxw, Vyw; /* Size of viewed area, in real numbers */ int Niter; /* max number of iterations */ int box_invisible; /******* shared memory with stitch.c: */ int no_check = 1; int contrl[12], intin[128], ptsin[128], intout[128]; int ptsout[128]; /* storage wasted for idiotic bindings */ char str[128]; GRECT work_clip; int draw_state; char *p_menu; #define c(x) 1000*(2*(x)+1)/16 int desks_clut[16][3], mandel_clut[16][3] = { {c(7),c(7),c(7)}, /* white */ {c(0),c(0),c(0)}, /* black */ {c(7),c(1),c(1)}, /* red */ {c(7),c(4),c(0)}, {c(7),c(6),c(0)}, {c(7),c(7),c(0)}, /* yellow */ {c(6),c(7),c(0)}, {c(0),c(7),c(0)}, /* green */ {c(0),c(7),c(5)}, {c(0),c(7),c(6)}, /* blue */ {c(0),c(6),c(7)}, {c(2),c(3),c(7)}, {c(4),c(0),c(7)}, {c(6),c(0),c(7)}, /* violet */ {c(7),c(0),c(6)}, {c(7),c(0),c(4)} }; struct places { double x, y, dx, dy; int menue_number; int iter_ct; char name[20]; } places[] = {{.651350,-.176159, .000929, .000636, MGOLUM, 1024, "Golum"}, {.166765,-.807549, .018935, .012964, MRIPPLE, 1024, "Ripple"}, {.054566,-.755330, .002208, .001512, MPINWH, 1024, "Pinwheels"}, {.127512,-.781265, .011749, .008044, MSWIRLS, 1024, "Swirls"}, {.656728,-.174796, .004559, .003122, M3ON4, 1024, "3 on 4"}, {.650663,-.176422, .001890, .001249, MTURTLE, 1024, "Turtle"}, {-1.0, -1.85, 2.0, 2.4, MBUDDAH, 256, "Buddah"}}; struct { char active, on_crt; int hidden; int want_active; char new0, new1; int x0,y0, x1,y1; int xyarray[10]; } rbox = {0, 1, FALSE, 0}; char *fs_get(); main() { int event, mouse_buttons, mmoving, fulled; int x0, y0, xw, yw, i, j; int *p_val; /* if ((old_res=Getrez()) != 0) /* won't work with AES */ /* Setscreen(-1, -1, 0); /* make low resolution */ appl_init(); open_vwork(); open_window(); open_rsc(); Niter = 256; /* inz count till black */ inz_dialog(); graf_mouse(ARROW,0x0L); fulled=FALSE; butdown=TRUE; box_invisible = 1; dr_iRastWindow(xwork, ywork, wwork, hwork); dr_iProgCoords(-1.0,-1.85, 2.0,2.4); dr_Vreset(); do { if (draw_state==0 || mmoving) { event = evnt_multi( MU_MESAG| MU_BUTTON| MU_KEYBD | MU_TIMER, 1,1,butdown, 0,0,0,0,0, 0,0,0,0,0, msgbuff,100,0, /* 100 ms timer*/ &mx,&my,&mouse_buttons,&ret,&keycode,&ret); }else { event = evnt_multi(MU_MESAG| MU_BUTTON| MU_KEYBD| MU_M1, 1,1,butdown, 1,0,0,0,0, /* (always true event) */ 0,0,0,0,0, msgbuff,0,0, &mx,&my,&mouse_buttons,&ret,&keycode,&ret); } if (event & MU_MESAG) switch (msgbuff[0]) { case WM_REDRAW: /* set clip and draw_mode */ start_redraw(1, msgbuff[4],msgbuff[5],msgbuff[6], msgbuff[7]); /*!!!*/ break; case WM_NEWTOP: /* unsure of what this does, so boobytrap*/ case WM_TOPPED: wind_set(wi_handle,WF_TOP,0,0,0,0); break; case WM_SIZED: case WM_MOVED: if (msgbuff[6]ob_spec) -> te_ptext; sprintf(edit_string, fmt, val); } get_dialog_field(p_window, w_name, fmt, val) struct object *p_window; char *w_name, *fmt; char *val; /* untyped pointer, actually */ { char *edit_string, alert_string[128], sc_str[128]; edit_string = (struct text_edinfo *) (p_window->ob_spec) -> te_ptext; sc_str[0] = 0; sscanf(edit_string, fmt, val, sc_str); if (sc_str[0]!=0) { if (strlen(edit_string) > 30) edit_string[30] = 0; sprintf(alert_string, "[1][Cannot figure out how | %s | can be put into %s.\ ][Got It?]", edit_string, w_name); form_alert(0, alert_string); } } long *save_screen; int Nsave_screen; disp_dialog(tree_index, start_edit) int tree_index, start_edit; { struct object *p_object; int x0, y0, xw, yw; int exit_obj; if (rsrc_gaddr(R_TREE, tree_index, &p_object)==0) panic ("AES/rsrc_gaddr() error",0L,0L); form_center(p_object, &x0, &y0, &xw, &yw); form_dial(FMD_START, x0, y0, xw, yw); draw_on_screen(); /* don't save mouse */ rast_save(x0, y0, xw, yw, save_screen, Nsave_screen); view_screen(); objc_draw(p_object, 0, 2, x0, y0, xw, yw); exit_obj = form_do(p_object, start_edit); objc_change(p_object, exit_obj, 0, x0,y0,xw,yw, 0,1); draw_on_screen(); /* unsave with mouse gone */ rast_restore(); view_screen(); form_dial(FMD_FINISH, x0, y0, xw, yw); return (exit_obj); } int ind[] = {NUMERIC, AUTHOR, ITERATN, -1}; inz_dialog() /* reserve a buffer to hide the screen under /* dialog boxes listed in ind[]*/ { struct object *p_object; int x0, y0, xw, yw, obj, size; char *pointer; /* find size of biggest dialog box: */ for (Nsave_screen=0, obj=0; ind[obj]>=0;) { if (rsrc_gaddr(R_TREE, ind[obj++], &p_object)==0) panic ("AES/rsrc_gaddr() error",0L,0L); form_center(p_object, &x0, &y0, &xw, &yw); size = rastSize(x0, y0, xw, yw); Nsave_screen = (size>Nsave_screen)? size: Nsave_screen; } pointer = Malloc((long) (Nsave_screen)); if (pointer == 0) panic("inz_dialog: Malloc out of memory\n", 0L, 0L); save_screen = (long *) pointer; } start_redraw(ds, xc, yc, wc, hc) int ds, xc, yc, wc, hc; { int i; if (ds == 1) { draw_state = 1; rbox.want_active = 0; } clip_current(); if (xc >=0) { work_clip.g_x=xc; work_clip.g_y=yc; work_clip.g_w=wc; work_clip.g_h=hc; } } GRECT t1; /*current working rectangle*/ more_redraw() { int i, flag; flag = WF_NEXTXYWH; switch (draw_state) { case 0: draw_on_screen(); /* make boxes visible */ view_screen(); return; case 1: flag = WF_FIRSTXYWH; case 2: wind_get(wi_handle, flag, &t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h); if (t1.g_w==0 || t1.g_h==0) { draw_state = 0; return; } if (draw_state == 2) panic("must currently be top window only\n", 0L, 0L); if (!rc_intersect(&work_clip,&t1)) return; draw_state = 3; clip_current(); dr_sBox(); /*???t1.g_x,t1.g_y,t1.g_w,t1.g_h);*/ default: if (i=dr_compute()) dr_putBuf(i); else draw_state = 2; } } int last_button, last_x, last_y; /* mouse on previous scan*/ mouse_moving(mx, my, mouse_buttons) int mx, my, mouse_buttons; { int moving; mouse_buttons &= 1; if (mouse_buttons && last_button==0) { if (!rbox_redraw(mx,my)) /*down of left button*/ { rbox_set(0, mx, my); rbox_set(1, mx, my); rbox.want_active=1; } } if (last_button) rbox_set(1, mx, my); /*drag of left button*/ moving = (mx!=last_x || my!=last_y); last_x = mx; last_y = my; last_button = mouse_buttons; return (moving); } rbox_redraw(x,y) int x,y; { if ( (x > rbox.xyarray[0]) ^ (x > rbox.xyarray[4]) && (y > rbox.xyarray[1]) ^ (y > rbox.xyarray[5]) ) { dr_zoom(rbox.xyarray[0],rbox.xyarray[1], rbox.xyarray[4],rbox.xyarray[5]); start_redraw(1, xwork,ywork,wwork,hwork); /* rbox.want_active = 0;/**/ return (1); } else return (0); } rbox_set(index, x, y) int index, x, y; { int dx, dy; double f1, f2; if (index==0) { rbox.x0=x; rbox.y0=y; rbox.new0=1; }else { if ((dx=x-rbox.x0) && (dy=y-rbox.y0)) /* keep ratio correct */ { f1 = (double)dy/(double)dx; f2 = (double)hwork/(double)( (1-2*(f1<0))*wwork); if (f1500 && 2 != form_alert(1,"[3][16 Colors Required.|\ Set Preferences to Low|Resolution and Restart.][okay|ignore warning]")) exit(); } char myname[] = "mandlbox.rsc"; open_rsc() { if (rsrc_load(myname)==0) panic("File %s missing!",myname,0L); if (rsrc_gaddr(R_TREE, MENUE, &p_menu)==0) panic ("AES/rsrc_gaddr() error",0L,0L); if (menu_bar(p_menu, TRUE)==0) panic ("AES/menu_bar() error",0L,0L); } panic(str,v,w) char *str, *v, *w; { long i; fprintf(stderr,"\n\n\n***** ERROR: *****\n"); fprintf(stderr,str,v,w); for (i=0; i<200000; i++); exit(); }