home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / wdr_scrl.pro < prev    next >
Encoding:
Text File  |  1997-07-08  |  5.2 KB  |  179 lines

  1. ; $Id: wdr_scrl.pro,v 1.3 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ; This is the code for a DRAW widget with scroll bars.  It 
  7. ; displays a portion of an image of a "DIST" in the drawing
  8. ; window.  It also allows the user to erase the
  9. ; draw widget and to redraw the image.  If the mouse button
  10. ; is pressed while the cursor is moved over the displayed
  11. ; image, the X and Y positions of the cursor are printed in
  12. ; the IDL window.
  13.  
  14. ; For an example of a draw widget without scroll bars, 
  15. ; see the procedure WDRAW.PRO.
  16.  
  17.  
  18. PRO wdr_scrl_event, event
  19. ; This is the event handler for a draw widget with scroll bars.
  20.  
  21. ; The COMMON block is used because the event handler usually needs
  22. ; the window number and size of the draw widget.
  23.  
  24. COMMON wdr_scrlblock, win_num, orig_image, x_im_sz, y_im_sz
  25.  
  26. ; When a widget is manipulated, put its User Value into the variable 'eventval':
  27.  
  28. WIDGET_CONTROL, event.id, GET_UVALUE = eventval
  29.  
  30. ; Perform actions based on the user value of the event:
  31.  
  32. CASE eventval OF
  33.    'DRAW_WIN_EVENT': BEGIN
  34.             ; The help statement is useful for
  35.             ; debugging the event handler.  Try uncommenting
  36.             ; it to see the full structure returned by a 
  37.             ; draw window event.  Note the 'PRESS' and
  38.             ; 'RELEASE' fields.
  39.             ; HELP, /STRUCT, event
  40.  
  41.             ; Only deal with the 'press' event,
  42.             ; disregard the 'release' event
  43.             IF event.press EQ 1 THEN BEGIN
  44.                 ; Print the device coordinates of the cursor
  45.                 PRINT, 'X = ', event.x
  46.                 PRINT, 'Y = ', event.y
  47.             ENDIF
  48.              END
  49.  
  50.    'ERASE': BEGIN
  51.         swin = !D.WINDOW        ; Save previous window
  52.         ; Set the window number - important if multiple windows
  53.         WSET, win_num
  54.                 ERASE                   ; Erase the image
  55.         WSET, swin              ; Restore previous window
  56.              END
  57.  
  58.  
  59.    'REDRAW': BEGIN
  60.         swin = !D.WINDOW        ; Save previous window
  61.         ; Set the window number - important if multiple windows
  62.         WSET, win_num
  63.                 ; Redraw the image
  64.                 TVSCL, REBIN(orig_image, x_im_sz, y_im_sz)
  65.         WSET, swin              ; Restore previous window
  66.              END
  67.  
  68.    'DONE': BEGIN
  69.                 WIDGET_CONTROL, event.top, /DESTROY
  70.            END
  71. ENDCASE
  72.  
  73. END
  74.  
  75.  
  76.  
  77. PRO wdr_scrl, XSIZE=x_size, YSIZE=y_size, $
  78.     X_SCROLL_SIZE=x_scroll, Y_SCROLL_SIZE=y_scroll, $
  79.     GROUP=GROUP
  80.  
  81.  
  82. ; This is the procedure that creates a draw widget which scrolls.
  83.  
  84. ; The COMMON block is used because the event handler usually needs
  85. ; the window number and size of the draw widget.
  86. ; Names of common variables must be distinct from keyword variables.
  87.  
  88. COMMON wdr_scrlblock, win_num, orig_image, x_im_sz, y_im_sz
  89.  
  90. ; The size of the draw area is one of the more important parameters
  91. ; for a draw widget.  This example uses keywords to define the size
  92. ; of the draw area.  An alternative would be to use a fixed size draw area. 
  93.  
  94. if (NOT keyword_set(x_size)) THEN x_size = 600
  95. if (NOT keyword_set(y_size)) THEN y_size = 600
  96.  
  97. ; The size of actual area which will be displayed is determined by
  98. ; these keywords.
  99.  
  100. if (NOT keyword_set(x_scroll)) THEN x_scroll = 200
  101. if (NOT keyword_set(y_scroll)) THEN y_scroll = 300
  102.  
  103. swin = !D.WINDOW    ; Remember the current window so it can be restored
  104.  
  105. ; A top -level base widget with the title "Scrolling Draw Widget Example"
  106. ; will be created.  The size is left unspecified until the draw widget
  107. ; is created:
  108.  
  109. base = WIDGET_BASE(TITLE = 'Scrolling Draw Widget Example', $
  110.            /COLUMN)
  111.  
  112. ; Setting the managed attribute indicates our intention to put this application
  113. ; under the control of XMANAGER, and prevents our draw widgets from
  114. ; becoming candidates for becoming the default window on WSET, -1. XMANAGER
  115. ; sets this, but doing it here prevents our own WSETs at startup from
  116. ; having that problem.
  117. WIDGET_CONTROL, /MANAGED, base
  118.  
  119. ; Make the 'DONE' button:
  120.  
  121. button1 = WIDGET_BUTTON(base, $
  122.         UVALUE = 'DONE', $
  123.         VALUE = 'DONE')
  124.  
  125. ; Make the DRAW widget:
  126.  
  127. draw = WIDGET_DRAW(base, $
  128.     /BUTTON_EVENTS, $        ;Generate events when button is pressed.
  129.     /FRAME, $
  130.     RETAIN = 2, $            ;Make sure IDL provides backing store.
  131.     UVALUE = 'DRAW_WIN_EVENT', $    ;The User Value of the draw widget.
  132.     X_SCROLL_SIZE = x_scroll, $    ;The x size of the displayed area.
  133.     Y_SCROLL_SIZE = y_scroll, $    ;The y size of the displayed area.
  134.     XSIZE = x_size, $
  135.     YSIZE = y_size)
  136.  
  137. ; Make the 'ERASE' button:
  138.  
  139. button2 = WIDGET_BUTTON(base, $
  140.         UVALUE = 'ERASE', $
  141.         VALUE = 'ERASE')
  142.  
  143. ; Make the 'REDRAW' button:
  144.  
  145. button3 = WIDGET_BUTTON(base, $
  146.         UVALUE = 'REDRAW', $
  147.         VALUE = 'REDRAW')
  148.  
  149.  
  150. ; Realize the widgets:
  151. WIDGET_CONTROL, base, /REALIZE
  152.  
  153. ; The VALUE of a draw widget is its "window number".
  154. ; Get the window number from the draw widget.
  155. ; This number can only be obtained after the widget has been realized.
  156.  
  157. WIDGET_CONTROL, draw, GET_VALUE=win_num
  158.  
  159. ; Use to display an image in the draw widget.  Set the window for
  160. ; the TVSCL command to use since there may be other draw windows.
  161. WSET, win_num
  162.  
  163. orig_image = COS(DIST(50))            ;Make an image to display.
  164. TVSCL, REBIN(orig_image, x_size, y_size)    ;Display the image.
  165.  
  166. WSET, swin            ; Restore the original window
  167.  
  168. ; Set the common values for the image size:
  169. x_im_sz = x_size
  170. y_im_sz = y_size
  171.  
  172. ; Hand off control of the widget to the XMANAGER:
  173. XMANAGER, "wdr_scrl", base, GROUP_LEADER=GROUP, /NO_BLOCK
  174.  
  175.  
  176. END
  177.  
  178.  
  179.