Revision [14192]
This is an old revision of KeyPgViewgraphics made by CountingPine on 2009-07-06 09:54:03.
VIEW (GRAPHICS)
Sets new physical coordinate mapping and clipping region
Syntax:
View [SCREEN] ( x1, y1 )-( x2, y2 )[, [ color ] [, border ]]]
Parameters:
SCREEN
When specified, any x,y coordinate will be relative to the top-left corner of the screen, and not to the left-top corner of the viewport.
( x1, y1 )-( x2, y2 )
Coordinates of the top-left and bottom-right corners of the new viewport in screen pixels.
color
Color with which to clear the new viewport; if omitted, the viewport will not be cleared.
border
Color of the border box surrounding the new viewport. If omitted, no border box will be drawn.
Description:
Use this statement to set a new clipping region, also known as viewport. The new viewport will override the previous one, if any; if the SCREEN argument is omitted, all future coordinates specifications will be relative to the top-left corner of the new viewport, instead of relative to the top-left corner of the screen. Any graphical primitive will be affected by the new viewport, and drawing outside specified region will produce no effect. If color is specified, in the same format as the one supported by KeyPgColor Color, the new viewport is cleared with it; if border is specified, also in KeyPgColor Color format, a box using border as color will be drawn surrounding given region. If all arguments are omitted, the viewport is reset to the screen mode size.
Examples:
Screen 12
Dim ip As Integer Ptr
Dim As Integer i, j, k
'simple sprite
For i=0 To 63: For j=0 To 63:PSet (i,j), (i\4) Xor (j\4):Next j,i
ip=ImageCreate(64,64)
Get (0,0)-(63,63),ip
Cls
'viewport
Line (215,135)-(425,345),1,bf
View (220,140)-(420,340)
k=0
'move sprite
Do
i=100*Sin(k*.02)+50: j=100* Sin(k*.027)+50
ScreenSync
ScreenLock
Cls 1: Put (i,j),ip ,PSet
ScreenUnlock
k=k+1
Loop Until Len(Inkey)
ImageDestroy(ip)
Dim ip As Integer Ptr
Dim As Integer i, j, k
'simple sprite
For i=0 To 63: For j=0 To 63:PSet (i,j), (i\4) Xor (j\4):Next j,i
ip=ImageCreate(64,64)
Get (0,0)-(63,63),ip
Cls
'viewport
Line (215,135)-(425,345),1,bf
View (220,140)-(420,340)
k=0
'move sprite
Do
i=100*Sin(k*.02)+50: j=100* Sin(k*.027)+50
ScreenSync
ScreenLock
Cls 1: Put (i,j),ip ,PSet
ScreenUnlock
k=k+1
Loop Until Len(Inkey)
ImageDestroy(ip)
Differences from QB:
- QBASIC preserves the WINDOW coordinate mapping after subsequent calls to VIEW.
- FreeBASIC's current behavior is to preserve the WINDOW coordinates after calls to VIEW, or when working on images, meaning that the coordinate mapping may undergo scaling/translations if the viewport changes. (If a WINDOW hasn't been set, there is no coordinate mapping, and so it doesn't change after calls to VIEW.) The behavior may change in future, but consistent behavior can be be assured over inconstent viewport coordinates by re-calling WINDOW whenever you change the VIEW.
See also:
Back to Screen Functions