home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / sgi / editors / kali.lha / kali / callbacks.c next >
C/C++ Source or Header  |  1992-10-11  |  7KB  |  310 lines

  1. /* 
  2.  *** callbacks.c - Tamara Munzner, Sept. 1992 
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <strings.h>
  7. #include "symmetry.h"
  8. #include "icons.h"
  9. #include "help.h"
  10.  
  11. #define SAVE 0
  12. #define LOAD 1
  13.  
  14. #include "panel.c"
  15.  
  16. void set_linebutton(int new);
  17. void set_symbutton(int new);
  18. void set_angrat();
  19. FL_OBJECT *linelist(int button);
  20. FL_OBJECT *symlist(int button);
  21. void flx_enable(FL_OBJECT *obj);
  22. void flx_disable(FL_OBJECT *obj);
  23.  
  24.  
  25. extern WINDOW win;
  26. extern int mode, count, sym_index, pick_for;
  27. extern SYMMETRY *sym;
  28. extern LINE *Lines;
  29. extern RECTANGLE win_rect, sym_rect;
  30. extern float zoom;
  31. extern XFORM xforms[5];
  32. extern POINT *sym_pts;
  33. extern void DrawLine();
  34. extern void PickLine();
  35. extern LINE *DropLine();
  36. extern void (*xformfnc) ();
  37. extern void ChangeRatio();
  38. extern void ChangeScale();
  39. extern void ChangeAngle();
  40. extern void ChangeRotation();
  41. extern LINE *ReadPattern();
  42. extern LINE* ThrowAwayLines(LINE *Lines);
  43. extern void SaveProc();
  44. extern void LoadProc();
  45. extern int lit;
  46.  
  47. int iostate;
  48.  
  49. void forms_init()
  50. {
  51.   int i;
  52.   create_the_forms();
  53.  
  54.   fl_set_bitmap(P6MBitmap, icon_width, icon_height, p6m_bits);
  55.   fl_set_bitmap(P6Bitmap, icon_width, icon_height, p6_bits);
  56.   fl_set_bitmap(P31MBitmap, icon_width, icon_height, p31m_bits);
  57.   fl_set_bitmap(P3M1Bitmap, icon_width, icon_height, p3m1_bits);
  58.   fl_set_bitmap(P3Bitmap, icon_width, icon_height, p3_bits);
  59.   fl_set_bitmap(P4MBitmap, icon_width, icon_height, p4m_bits);
  60.   fl_set_bitmap(P4GBitmap, icon_width, icon_height, p4g_bits);
  61.   fl_set_bitmap(P4Bitmap, icon_width, icon_height, p4_bits);
  62.   fl_set_bitmap(PMMBitmap, icon_width, icon_height, pmm_bits);
  63.   fl_set_bitmap(CMMBitmap, icon_width, icon_height, cmm_bits);
  64.   fl_set_bitmap(P2Bitmap, icon_width, icon_height, p2_bits);
  65.   fl_set_bitmap(PMGBitmap, icon_width, icon_height, pmg_bits);
  66.   fl_set_bitmap(PGGBitmap, icon_width, icon_height, pgg_bits);
  67.   fl_set_bitmap(CMBitmap, icon_width, icon_height, cm_bits);
  68.   fl_set_bitmap(PGBitmap, icon_width, icon_height, pg_bits);
  69.   fl_set_bitmap(PMBitmap, icon_width, icon_height, pm_bits);
  70.   fl_set_bitmap(P1Bitmap, icon_width, icon_height, p1_bits);
  71.  
  72.   fl_set_form_position(KaliForm, 8, 8);
  73.   SymmetryProc(NULL, sym_index);
  74.   fl_show_form(KaliForm, FL_PLACE_POSITION, TRUE, "Symmetry Groups");
  75.  
  76.   for (i=0; help[i][0] != '.'; i++) {
  77.     fl_add_browser_line(InfoBrowser, help[i]);
  78.   }
  79.  
  80. }
  81.  
  82.  
  83.  
  84. void SymmetryProc(FL_OBJECT *obj, long val)
  85. {
  86.   sym_index = val;
  87.   sym = &(SYMTAB[sym_index]);
  88.   Lines = ThrowAwayLines(Lines);
  89.   set_symbutton(val);
  90.   DefineSymWindow(&sym_rect,sym,&win_rect,zoom);
  91.   count = SetUpSymmetry(sym,&sym_pts,xforms,&sym_rect);
  92.   DrawCurrent(&sym_rect,Lines,sym,
  93.           sym_pts,xforms,count,DrawLine);
  94.   swapbuffers();
  95.   /* we don't set mode to DRAW since we don't want to rubberband yet,
  96.      but we will be in draw mode as soon as mouse is used.
  97.    */
  98.   set_linebutton(DRAW);
  99.   set_linebutton(DRAW);
  100.   set_angrat();
  101.   mode = 0;
  102. }
  103.  
  104. void DrawProc(FL_OBJECT *obj, long val)
  105. {
  106. /* 18 19 26*/
  107.   DrawCurrent(&sym_rect,Lines,sym,
  108.           sym_pts,xforms,count,DrawLine);
  109.   swapbuffers();
  110.   mode = 0;
  111.   set_linebutton(val);
  112. }
  113.  
  114. void PickProc(FL_OBJECT *obj, long val)
  115. {
  116.   if ((mode == DRAW) && (Lines != NULL))
  117.     {
  118.       Lines = DropLine(Lines);
  119.       DrawCurrent(&sym_rect,Lines,sym,
  120.           sym_pts,xforms,count,DrawLine);
  121.       swapbuffers();
  122.     }
  123.   mode=PICK;
  124.   pick_for = val;   /* MOVE or CUT */
  125.   set_linebutton(val);
  126.   lit = FALSE;
  127. }
  128.  
  129.  
  130. void LineProc(FL_OBJECT *obj, long val)
  131. {
  132.   mode = TRANSFORM; 
  133.   switch (val) {
  134.   case ZOOM: xformfnc = ChangeScale; break;
  135.   case ROTATE: xformfnc = ChangeRotation; break;
  136.   }
  137.   set_linebutton(val);
  138. }
  139.  
  140. void AngleProc(FL_OBJECT *obj, long val)
  141. {
  142.     mode = TRANSFORM; 
  143.     xformfnc = ChangeAngle;
  144.     set_linebutton(val);
  145. }
  146.  
  147. void RatioProc(FL_OBJECT *obj, long val)
  148. {
  149.     mode = TRANSFORM; 
  150.     xformfnc = ChangeRatio;
  151.     set_linebutton(val);
  152. }
  153.  
  154. void StartSaveProc(FL_OBJECT *obj, long val)
  155. {
  156.   iostate = SAVE;
  157.   fl_show_form(IOForm, FL_PLACE_MOUSE, TRUE, "Save");
  158. }
  159.  
  160. void StartLoadProc(FL_OBJECT *obj, long val)
  161. {
  162.   iostate = LOAD;
  163.   fl_show_form(IOForm, FL_PLACE_MOUSE, TRUE, "Load");
  164.   fl_set_button(DrawButton, 1);
  165.   set_linebutton(DRAW);
  166.   set_linebutton(DRAW);
  167.   mode = 0;
  168. }
  169.   
  170. void IODoneProc(FL_OBJECT *obj, long val)
  171. {
  172.   char *filename, *readwrite;
  173.   FILE *pat; 
  174.   void (*func)();
  175.  
  176.   if (iostate == SAVE) {
  177.     func = SaveProc;
  178.     readwrite = "w";
  179.   } else {
  180.     func = LoadProc;
  181.     readwrite = "r";
  182.   }
  183.   filename = strdup(fl_get_input(IOInput));
  184.   pat = fopen(filename,readwrite);
  185.   if (pat == NULL) {
  186.     fl_set_input(IOInput, "Bogus file name!");
  187.     return;
  188.   } else {
  189.     fl_hide_form(IOForm);
  190.   }
  191.   func(pat);
  192.   if (iostate == LOAD) {
  193.     set_symbutton(sym_index);
  194.     set_symbutton(sym_index);
  195.   }
  196.   winset(win);
  197. }
  198.  
  199. void CancelProc(FL_OBJECT *obj, long val)
  200. {
  201.   fl_hide_form(IOForm);
  202.   winset(win);
  203. }
  204.  
  205.  
  206. void QuitProc(FL_OBJECT *obj, long val)
  207. {
  208.   fl_hide_form(KaliForm);
  209.   exit(0);
  210. }
  211.  
  212.  
  213. void InfoProc(FL_OBJECT *obj, long val)
  214. {
  215.   static int winid = 0;
  216.   winid = fl_show_form(InfoForm, FL_PLACE_SIZE, TRUE, "Kali Help");
  217.   winset(winid);
  218.   winpop();
  219. }
  220.   
  221. void CloseThisPanel(FL_OBJECT *obj, long val)
  222. {
  223.   fl_hide_form(obj->form);
  224.   winset(win);
  225. }
  226.  
  227. FL_OBJECT *linelist(int button)
  228. {
  229.   switch (button) {
  230.   case DRAW: return DrawButton; break;
  231.   case CUT: return DeleteButton; break;
  232.   case MOVE: return MoveButton; break;
  233.   case ZOOM: return ZoomButton; break;
  234.   case ROTATE: return RotateButton; break;
  235.   case ANGLE: return AngleButton; break;
  236.   case RATIO: return RatioButton; break;
  237.   }
  238. }
  239.  
  240. FL_OBJECT *symlist(int button)
  241. {
  242.   switch (button) {
  243.   case P1: return P1Bitmap; break;
  244.   case P2: return P2Bitmap; break;  
  245.   case P3: return P3Bitmap; break;  
  246.   case PG: return PGBitmap; break;  
  247.   case PGG: return PGGBitmap; break;  
  248.   case PMG: return PMGBitmap; break;  
  249.   case PM: return PMBitmap; break;  
  250.   case CM: return CMBitmap; break;  
  251.   case PMM: return PMMBitmap; break;  
  252.   case CMM: return CMMBitmap; break;  
  253.   case P31M: return P31MBitmap; break;  
  254.   case P3M1: return P3M1Bitmap; break;  
  255.   case P4: return P4Bitmap; break;  
  256.   case P4G: return P4GBitmap; break;  
  257.   case P4M: return P4MBitmap; break;  
  258.   case P6: return P6Bitmap; break;  
  259.   case P6M: return P6MBitmap; break;  
  260.   }
  261. }
  262.  
  263.  
  264. void set_linebutton(int new)
  265. {
  266.   static int old = DRAW;
  267.   fl_set_button(linelist(old), 0);
  268.   fl_set_button(linelist(new), 1);
  269.   old = new;
  270. }
  271. #define WHITEINDEX 7
  272. #define BLUEINDEX 4
  273. #define BLACKINDEX 0
  274.  
  275.  
  276. void set_symbutton(int new)
  277. {
  278.   static int old = P3;
  279.   fl_set_object_color(symlist(old), BLUEINDEX, WHITEINDEX);
  280.   fl_set_object_color(symlist(new), WHITEINDEX, BLUEINDEX);
  281.   old = new;
  282. }
  283.  
  284.  
  285. void flx_enable(FL_OBJECT *obj) {
  286.   
  287.   obj->active = 1;
  288.   fl_set_object_lcol(obj, BLACKINDEX);
  289.  
  290. }
  291.  
  292. void flx_disable(FL_OBJECT *obj) {
  293.  
  294.   obj->active = 0;
  295.   fl_set_object_lcol(obj, WHITEINDEX);
  296.  
  297. }
  298.  
  299. void set_angrat()
  300. {
  301.   if (sym->dof & ANG)
  302.     flx_enable(AngleButton);
  303.   else 
  304.     flx_disable(AngleButton);
  305.   if (sym->dof & RAT)
  306.     flx_enable(RatioButton);
  307.   else 
  308.     flx_disable(RatioButton);
  309. }
  310.