home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / mouse.ex < prev    next >
Text File  |  1994-01-15  |  1KB  |  67 lines

  1.         ----------------
  2.         -- mouse test --
  3.         ----------------
  4. -- This is a very simple program to demonstrate the get_mouse() built-in
  5. -- function. No call is made to mouse_events(), so by default all events are
  6. -- reported by get_mouse(). 
  7.  
  8. include mouse.e
  9. include graphics.e
  10.  
  11. sequence vc
  12. vc = video_config()
  13. if graphics_mode(17 + vc[VC_COLOR]) then -- 640x480 (16 colors)
  14.     puts(1, "Can't get good graphics mode\n")
  15.     abort(1)
  16. end if 
  17. vc = video_config()
  18.  
  19. procedure beep()
  20.     atom t
  21.     sound(500)
  22.     t = time()
  23.     while time() < t+0.07 do
  24.     end while
  25.     sound(0)
  26. end procedure
  27.  
  28. constant origin = {vc[VC_XPIXELS]/2, vc[VC_YPIXELS]/2}
  29.  
  30. procedure try_mouse()
  31.     integer color
  32.     object event
  33.  
  34.     color = 14
  35.     while 1 do
  36.         event = get_mouse()
  37.         if sequence(event) then
  38.         printf(1, "event: %d, x:%d, y:%d       \r", event)
  39.  
  40.         if event[1] = MOVE then
  41.         mouse_pointer(0)
  42.         draw_line(color, {origin, {event[2], event[3]}}) 
  43.         mouse_pointer(1)
  44.  
  45.         elsif event[1] = LEFT_DOWN then
  46.         beep()
  47.             color = color + 1
  48.         if color > 15 then
  49.             color = 0
  50.         end if 
  51.  
  52.         elsif event[1] = LEFT_UP then
  53.         beep()
  54.                 
  55.         elsif event[1] = RIGHT_DOWN or 
  56.           event[1] = MIDDLE_DOWN then
  57.         exit
  58.         end if
  59.     end if
  60.     end while
  61. end procedure
  62.  
  63. try_mouse()
  64.  
  65. if graphics_mode(-1) then
  66. end if
  67.