Creating a Drawing Area
A drawing area is a window in which an application can display plots or images. The drawing area has both horizontal and vertical scroll bars. The scroll bars can be used to pan across a drawing that is too large to fit in the window. A drawing area is created with the WwDrawing function.
When a drawing area widget is created, WwDrawing automatically associates the drawing area with a PV-WAVE window index (see the WINDOW command in the PV‑WAVE Reference for more information). Then, the drawing area callback is executed and the graphics are displayed. The callback is also executed on systems that do not provide backing store for when the drawing window is obscured and then redisplayed.
Example 1: Basic Drawing Area
In this example, a drawing area window is created. The parent widget is called
layout, the window index of the PV-WAVE window used is 1. Note that the size of the drawing area is 256 x 256, while the total size of the drawing is 512 x 512 (the image is larger than the actual drawing area). Scroll bars are provided for moving the image inside the drawing area. The result is shown in
Figure 5-19: Drawing Area.
To run this example, enter the callback procedure in a file and compile it with the .RUN command. Then enter the widget commands at the WAVE> prompt.
Callback Procedure
PRO DrawCB, wid, data
COMMON draw, img
PRINT, 'Draw'
TV, img
END
Widget Commands
top=WwInit('ww_ex10', 'Examples', layout)
COMMON draw, img
LOADCT, 5, /Silent
img=BYTARR(512,512)
Openr,1, !Data_Dir + 'head.img'
READU,1,img
CLOSE, 1
draw=WwDrawing(layout, 1, 'DrawCB', [256,256], [512,512])
status=WwSetValue(top, /Display)
WwLoop
Example 2: User Resizes the Drawing Area
This example demonstrates how the drawing area can be dynamically resized when the user resizes the main window.
To run this example, enter the code into a procedure file, and execute it with the .RUN command.
PRO DrawCB, wid, index
COMMON Trdraw, draw, area, widx
print, 'Draw', !D.x_vsize, !D.y_vsize, index, widx
x = indgen(100)
plot, x
END
PRO Testresize
COMMON Trdraw, draw, area, widx
; Initialize toolkit, create form layout
top = WwInit('testresize','Test', layout, $
Background='Green', /Form)
Create drawing area
widx = -1
draw = WwDrawing(layout, widx, 'DrawCB', $
[256, 256], [512, 512], /Noscroll, $
Area = area, /Right, /Left, /Top, /Bottom)
status = WwSetValue(top, /Display)
WtLoop
END
Example 3: Resizing the Drawing Area Programmatically
This example demonstrates how to resize the drawing area programmatically using WwSetValue.
To run this example, enter the code into a procedure file, and execute it with the .RUN command.
PRO ButtonCB, wid, which
COMMON Test, draw, top, size
CASE which OF
1: BEGIN
size = 600
status = WwSetValue(draw, [600, 600])
END
2: BEGIN
erase, 0
tvscl, dist(size)
END
ENDCASE
END
; Draw the image.
PRO DrawingCB, wid, which
COMMON Test, draw, top, size
tvscl, dist(size)
END
PRO Testdraw
COMMON Test, draw, top, size
size = 400
top = WwInit('testdraw', 'Testdraw', layout, $
/Vertical, Title = 'Test Drawing', Position = position)
b = ['Resize','Redraw']
; Create Pushbutton.
pushb = WwButtonBox(layout, b, 'ButtonCB', $
/Vertical, Border = 0, Spacing = 10, Position = [10, 400])
; Create Drawing.
drawing_surf = WwDrawing(layout, 1, 'DrawingCB', $
[400, 400], [400, 400], Area = draw, Position = [0, 0])
status = WwSetValue(top, /Display)
; Waiting for callbacks.
WwLoop
END