home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part05 / w_mousefun.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-27  |  7.0 KB  |  262 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1991 by Paul King
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "figx.h"
  15. #include "resources.h"
  16. #include "w_util.h"
  17. #include "w_drawprim.h"
  18. #include "w_mousefun.h"
  19. #include "w_setup.h"
  20.  
  21. #define MOUSE_BUT_WID        (int) (MOUSEFUN_WD * 0.045)
  22. #define MOUSE_BUT_HGT        (int) (MOUSEFUN_HT * 0.5)
  23. #define MOUSE_LEFT_SPACE    (int) ((MOUSEFUN_WD - 4 * MOUSE_BUT_WID) / 2)
  24. #define MOUSE_LEFT_CTR        (int) (MOUSE_LEFT_SPACE/2)
  25. #define MOUSE_MID_CTR        (int) (MOUSEFUN_WD / 2)
  26. #define MOUSE_RIGHT_CTR        (int) (MOUSEFUN_WD - MOUSE_LEFT_CTR)
  27. #define MOUSEFUN_MAX               20
  28.  
  29. DeclareStaticArgs(14);
  30. static char    mousefun_l[MOUSEFUN_MAX];
  31. static char    mousefun_m[MOUSEFUN_MAX];
  32. static char    mousefun_r[MOUSEFUN_MAX];
  33.  
  34. /* labels for the left and right buttons have 15 chars max */
  35. static char    lr_blank[] = "               ";
  36.  
  37. /* give the middle button label a bit more space - 18 chars max */
  38. static char    mid_blank[] = "                  ";
  39. static Pixmap    mousefun_pm;
  40.  
  41. void
  42. init_mousefun(tool)
  43.     TOOL        tool;
  44. {
  45.     FirstArg(XtNwidth, MOUSEFUN_WD);
  46.     /* start with nominal height and adjust later */
  47.     NextArg(XtNheight, MSGFORM_HT);
  48.     NextArg(XtNfromHoriz, cmd_panel);
  49.     NextArg(XtNhorizDistance, -INTERNAL_BW);
  50.     NextArg(XtNfromVert, NULL);
  51.     NextArg(XtNvertDistance, 0);
  52.     NextArg(XtNleft, XtChainLeft);
  53.     NextArg(XtNright, XtChainLeft);
  54.     NextArg(XtNtop, XtChainTop);
  55.     NextArg(XtNbottom, XtChainTop);
  56.     NextArg(XtNborderWidth, INTERNAL_BW);
  57.     NextArg(XtNbackgroundPixmap, NULL);
  58.     NextArg(XtNmappedWhenManaged, False);
  59.     NextArg(XtNlabel, "");
  60.  
  61.     mousefun = XtCreateManagedWidget("mouse_panel", labelWidgetClass,
  62.                      tool, Args, ArgCount);
  63. }
  64.  
  65. static void
  66. reset_mousefun()
  67. {
  68.     /* get the foreground and background from the mousefun widget */
  69.     /* and create a gc with those values */
  70.     mouse_button_gc = XCreateGC(tool_d, XtWindow(mousefun), (unsigned long) 0, NULL);
  71.     FirstArg(XtNforeground, &mouse_but_fg);
  72.     NextArg(XtNbackground, &mouse_but_bg);
  73.     GetValues(mousefun);
  74.     XSetBackground(tool_d, mouse_button_gc, mouse_but_bg);
  75.     XSetForeground(tool_d, mouse_button_gc, mouse_but_fg);
  76.     XSetFont(tool_d, mouse_button_gc, button_font->fid);
  77.  
  78.     /* also create gc with fore=background for blanking areas */
  79.     mouse_blank_gc = XCreateGC(tool_d, XtWindow(mousefun), (unsigned long) 0, NULL);
  80.     XSetBackground(tool_d, mouse_blank_gc, mouse_but_bg);
  81.     XSetForeground(tool_d, mouse_blank_gc, mouse_but_bg);
  82.  
  83.     mousefun_pm = XCreatePixmap(tool_d, XtWindow(mousefun),
  84.             MOUSEFUN_WD, MOUSEFUN_HT, DefaultDepthOfScreen(tool_s));
  85.  
  86.     XFillRectangle(tool_d, mousefun_pm, mouse_blank_gc, 0, 0,
  87.            MOUSEFUN_WD, MOUSEFUN_HT);
  88.  
  89.     XDrawRectangle(tool_d, mousefun_pm, mouse_button_gc, MOUSE_LEFT_SPACE,
  90.            (int) (MOUSEFUN_HT * 0.45), MOUSE_BUT_WID, MOUSE_BUT_HGT);
  91.     XDrawRectangle(tool_d, mousefun_pm, mouse_button_gc,
  92.            (int) (MOUSE_LEFT_SPACE + 1.5 * MOUSE_BUT_WID),
  93.            (int) (MOUSEFUN_HT * 0.45), MOUSE_BUT_WID, MOUSE_BUT_HGT);
  94.     XDrawRectangle(tool_d, mousefun_pm, mouse_button_gc,
  95.            (int) (MOUSE_LEFT_SPACE + 3 * MOUSE_BUT_WID),
  96.            (int) (MOUSEFUN_HT * 0.45), MOUSE_BUT_WID, MOUSE_BUT_HGT);
  97.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  98.     SetValues(mousefun);
  99.     mouse_title();
  100.     FirstArg(XtNmappedWhenManaged, True);
  101.     SetValues(mousefun);
  102. }
  103.  
  104. static char *title = "Mouse Buttons";
  105.  
  106. mouse_title()
  107. {
  108.     /* put a title in the window */
  109.     XDrawImageString(tool_d, mousefun_pm, mouse_button_gc,
  110.              4, button_font->ascent+4, title, strlen(title));
  111.     FirstArg(XtNbackgroundPixmap, 0);
  112.     SetValues(mousefun);
  113.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  114.     SetValues(mousefun);
  115. }
  116.  
  117. void
  118. setup_mousefun()
  119. {
  120.     XDefineCursor(tool_d, XtWindow(mousefun), arrow_cursor);
  121.     /* now that the message panel has the real height it needs (because of
  122.        the font size we can resize the mouse panel */
  123.     MOUSEFUN_HT = MSGFORM_HT + CMDPANEL_HT - INTERNAL_BW;
  124.     XtUnmanageChild(mousefun);
  125.     FirstArg(XtNheight, MOUSEFUN_HT);
  126.     SetValues(mousefun);
  127.     XtManageChild(mousefun);
  128.     reset_mousefun();
  129.     set_mousefun("", "", "");
  130. }
  131.  
  132. void
  133. resize_mousefun()
  134. {
  135.     XFreePixmap(tool_d, mousefun_pm);
  136.     reset_mousefun();
  137. }
  138.  
  139. void
  140. set_mousefun(left, middle, right)
  141.     char       *left, *middle, *right;
  142. {
  143.     strcpy(mousefun_l, left);
  144.     strcpy(mousefun_m, middle);
  145.     strcpy(mousefun_r, right);
  146. }
  147.  
  148. void
  149. draw_mousefun_mode()
  150. {
  151.     clear_mousefun();
  152.     draw_mousefun("Change Mode", "", "");
  153. }
  154.  
  155. void
  156. draw_mousefun_ind()
  157. {
  158.     clear_mousefun();
  159.     draw_mousefun("Menu", "Dec/Prev", "Inc/Next");
  160. }
  161.  
  162. void
  163. draw_mousefun_unitbox()
  164. {
  165.     clear_mousefun();
  166.     draw_mousefun("Pan to Origin", "", "Set Units/Scale");
  167. }
  168.  
  169. void
  170. draw_mousefun_topruler()
  171. {
  172.     clear_mousefun();
  173.     draw_mousefun("Pan Left", "Drag", "Pan Right");
  174. }
  175.  
  176. void
  177. draw_mousefun_sideruler()
  178. {
  179.     clear_mousefun();
  180.     draw_mousefun("Pan Up", "Drag", "Pan Down");
  181. }
  182.  
  183. void
  184. draw_mousefun_canvas()
  185. {
  186.     clear_mousefun();
  187.     draw_mousefun(mousefun_l, mousefun_m, mousefun_r);
  188. }
  189.  
  190. static void
  191. draw_mousefun_msg(s, xctr, ypos)
  192.     char       *s;
  193.     int            xctr, ypos;
  194. {
  195.     int            width;
  196.  
  197.     width = XTextWidth(button_font, s, strlen(s));
  198.     XDrawImageString(tool_d, mousefun_pm, mouse_button_gc,
  199.              xctr - (int) (width / 2), ypos, s, strlen(s));
  200. }
  201.  
  202. void
  203. draw_mousefun(left, middle, right)
  204.     char       *left, *middle, *right;
  205. {
  206.     draw_mousefun_msg(left, MOUSE_LEFT_CTR, 30);
  207.     draw_mousefun_msg(middle, MOUSE_MID_CTR, 11);
  208.     draw_mousefun_msg(right, MOUSE_RIGHT_CTR, 30);
  209.     FirstArg(XtNbackgroundPixmap, 0);
  210.     SetValues(mousefun);
  211.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  212.     SetValues(mousefun);
  213. }
  214.  
  215. void
  216. notused_middle()
  217. {
  218.     draw_mousefun_msg("Not Used", MOUSE_MID_CTR, 11);
  219.     FirstArg(XtNbackgroundPixmap, 0);
  220.     SetValues(mousefun);
  221.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  222.     SetValues(mousefun);
  223. }
  224.  
  225. void
  226. clear_middle()
  227. {
  228.     draw_mousefun_msg(mid_blank, MOUSE_MID_CTR, 11);
  229.     FirstArg(XtNbackgroundPixmap, 0);
  230.     SetValues(mousefun);
  231.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  232.     SetValues(mousefun);
  233. }
  234.  
  235. void
  236. notused_right()
  237. {
  238.     draw_mousefun_msg("Not Used", MOUSE_RIGHT_CTR, 30);
  239.     FirstArg(XtNbackgroundPixmap, 0);
  240.     SetValues(mousefun);
  241.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  242.     SetValues(mousefun);
  243. }
  244.  
  245. void
  246. clear_right()
  247. {
  248.     draw_mousefun_msg(mid_blank, MOUSE_RIGHT_CTR, 30);
  249.     FirstArg(XtNbackgroundPixmap, 0);
  250.     SetValues(mousefun);
  251.     FirstArg(XtNbackgroundPixmap, mousefun_pm);
  252.     SetValues(mousefun);
  253. }
  254.  
  255. void
  256. clear_mousefun()
  257. {
  258.     draw_mousefun(lr_blank, mid_blank, lr_blank);
  259.     /* redraw the title in case the blanks overwrite it */
  260.     mouse_title();
  261. }
  262.