PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/ucblogo-6.0/xgraphics.h

#
C Header | 206 lines | 137 code | 50 blank | 19 comment | 3 complexity | d679fc5abb32b6d7d594997d16f51fcc MD5 | raw file
Possible License(s): GPL-2.0
  1. /* X window system graphics header file. */
  2. #include <memory.h>
  3. #include <X11/Xlib.h>
  4. #include <X11/Xutil.h>
  5. extern int have_x;
  6. extern int back_ground;
  7. extern void real_window_init();
  8. void logofill(void);
  9. /* Some X-related defines. */
  10. #define BORDER 1
  11. #define FONT "fixed"
  12. #define NUMCOLORS 512
  13. #define NUMINITCOLORS 16
  14. #define EVENT_MASK (StructureNotifyMask | PointerMotionMask \
  15. | ButtonPressMask | ButtonReleaseMask)
  16. #define DEFAULT_HEIGHT 500
  17. #define DEFAULT_WIDTH 500
  18. #define GR_SIZE 60000
  19. #define checkX { \
  20. if (have_x < 0) real_window_init(); \
  21. if (!have_x) { \
  22. err_logo(BAD_GRAPH_INIT,NIL); \
  23. return; \
  24. } \
  25. }
  26. #define prepare_to_draw {checkX; placate_x();}
  27. #define done_drawing XFlush(dpy)
  28. extern void placate_x();
  29. #define prepare_to_draw_turtle nop()
  30. #define done_drawing_turtle nop()
  31. #define screen_left 0
  32. #define screen_right (screen_width-1)
  33. #define screen_top 0
  34. #define screen_bottom (screen_height-1)
  35. /* #define screen_height (1 + screen_bottom - screen_top) */
  36. /* #define screen_width (1 + screen_right - screen_left) */
  37. #define screen_x_center (screen_left + (screen_width)/2)
  38. #define screen_y_center (screen_top + (screen_height)/2)
  39. #define turtle_left_max ((screen_left) - (screen_x_center))
  40. #define turtle_right_max ((screen_right) - (screen_x_center))
  41. #define turtle_top_max ((screen_y_center) - (screen_top))
  42. #define turtle_bottom_max ((screen_y_center) - (screen_bottom))
  43. #define screen_x_coord ((screen_x_center) + turtle_x)
  44. #define screen_y_coord ((screen_y_center) - turtle_y)
  45. #define turtle_height 18
  46. #define turtle_half_bottom 6.0
  47. #define turtle_side 19.0
  48. #define clear_screen XClearWindow(dpy, win)
  49. #define erase_screen() XClearWindow(dpy, win)
  50. #define line_to(a,b) if(xgr_pen.vis==0)\
  51. XDrawLine(dpy,win,xgr_pen.pm,\
  52. xgr_pen.xpos,xgr_pen.ypos,\
  53. (a),(b));\
  54. xgr_pen.xpos=(a);\
  55. xgr_pen.ypos=(b)
  56. #define move_to(a,b) xgr_pen.xpos=(a);\
  57. xgr_pen.ypos=(b)
  58. #define draw_string(s) XDrawString(dpy,win,xgr_pen.pm,\
  59. xgr_pen.xpos,xgr_pen.ypos,\
  60. (s),strlen((s)));
  61. #define set_pen_vis(v) xgr_pen.vis=(v)
  62. #define set_pen_mode(m) xgr_pen.pm=(m)
  63. #define set_pen_color(c) draw_turtle();\
  64. xgr_pen.color=c%NUMCOLORS;\
  65. XSetForeground(dpy,draw_gc,color[2+xgr_pen.color].pixel);\
  66. XSetForeground(dpy,reverse_gc,color[2+xgr_pen.color].pixel);\
  67. draw_turtle();
  68. #define set_back_ground(c) back_ground=c%NUMCOLORS;\
  69. XSetBackground(dpy,draw_gc,color[2+back_ground].pixel);\
  70. XSetBackground(dpy,reverse_gc,color[2+back_ground].pixel);\
  71. XSetBackground(dpy,erase_gc,color[2+back_ground].pixel);\
  72. XSetForeground(dpy,erase_gc,color[2+back_ground].pixel);\
  73. XSetWindowBackground(dpy,win,color[2+back_ground].pixel);\
  74. redraw_graphics();
  75. #define set_pen_width(w) XSetLineAttributes(dpy, draw_gc, w, LineSolid, \
  76. CapProjecting, JoinMiter);\
  77. XSetLineAttributes(dpy, erase_gc, w, LineSolid, \
  78. CapProjecting, JoinMiter);\
  79. XSetLineAttributes(dpy, reverse_gc, w, LineSolid, \
  80. CapProjecting, JoinMiter);\
  81. xgr_pen.pw = w;
  82. #define set_pen_height(h) XSetLineAttributes(dpy, draw_gc, h, LineSolid, \
  83. CapProjecting, JoinMiter);\
  84. XSetLineAttributes(dpy, erase_gc, h, LineSolid, \
  85. CapProjecting, JoinMiter);\
  86. XSetLineAttributes(dpy, reverse_gc, h, LineSolid, \
  87. CapProjecting, JoinMiter);\
  88. xgr_pen.ph = h;
  89. #define set_pen_x(x) nop()
  90. #define set_pen_y(y) nop()
  91. /* pen_info is a stucture type with fields for the various
  92. pen characteristics including the location, size, color,
  93. mode (e.g. XOR or COPY), pattern, visibility (0 = visible) */
  94. typedef struct {
  95. int color;
  96. int xpos;
  97. int ypos;
  98. int vis;
  99. int pw;
  100. int ph;
  101. GC pm;
  102. } pen_info;
  103. extern pen_info xgr_pen;
  104. #define p_info_x(p) (p.xpos)
  105. #define p_info_y(p) (p.ypos)
  106. /* All these should take an argument, like the two just above.
  107. Then we could support multiple turtles.
  108. */
  109. #define pen_width xgr_pen.pw
  110. #define pen_height xgr_pen.ph
  111. #define pen_color xgr_pen.color
  112. #define pen_mode xgr_pen.pm
  113. #define pen_vis xgr_pen.vis
  114. #define pen_x (xgr_pen.xpos)
  115. #define pen_y (xgr_pen.ypos)
  116. #define get_node_pen_pattern (cons(make_intnode(-1), NIL))
  117. #define pen_reverse pen_mode=reverse_gc
  118. #define pen_erase pen_mode=erase_gc
  119. #define pen_down pen_mode=draw_gc
  120. #define button get_button()
  121. #define mouse_x get_mouse_x()
  122. #define mouse_y get_mouse_y()
  123. /* There seems little point in implementing these unless we put
  124. everything in one window. (Possibly use a slave xterm?)
  125. */
  126. #define full_screen nop()
  127. #define split_screen nop()
  128. #define text_screen nop()
  129. #define plain_xor_pen() pen_reverse
  130. #define label(s) XDrawImageString(dpy,win,xgr_pen.pm,\
  131. xgr_pen.xpos,xgr_pen.ypos,\
  132. (s), strlen(s))
  133. #define tone(p,d) nop()
  134. #define get_pen_pattern(p) nop()
  135. #define set_pen_pattern(p) nop()
  136. #define set_list_pen_pattern(p) nop()
  137. extern void set_palette(int, unsigned int, unsigned int, unsigned int);
  138. extern void get_palette(int, unsigned int*, unsigned int*, unsigned int*);
  139. /* The sparc has fmod. So I use it. */
  140. /* #define fmod(x,y) x */
  141. extern void nop();
  142. /* Global X variables. */
  143. extern int screen_height, screen_width;
  144. extern Display *dpy; /* X server connection */
  145. extern Window win; /* Window ID */
  146. extern GC draw_gc, /* GC to draw with */
  147. erase_gc, /* GC to draw with */
  148. reverse_gc; /* GC to draw with */
  149. extern XColor color[];
  150. extern XColor dummy;
  151. extern int get_mouse_x(), get_mouse_y();
  152. /* Avoid name conflicts. Note: if xgraphics.c uses True and
  153. False, bad things are likely to happen.
  154. */
  155. #undef True
  156. #undef False