Attached code draws an object using the Vector Drawing library. I have the movement and rotation worked out, I just can't for the life of me work out how to zoom the object and have it rendered in the same x/y position.
(Zoom is via NUMPAD+/-, Movement via arrow keys, Rotate via CTRL-LEFT/CTRL-RIGHT).
The code is part of creating a more complex object, just wanted to get the basics going first.
Any help much appreciated! (I just know it's something simple

Code: Select all
EnableExplicit
;-> Globals
Global.l hWndInv
; ; Global.l srcNumber, srcWidth, srcHeight, srcDepth
Global.l hwnd, xPos, yPos, Factor, event, KeyPressed, width, height, oldxPos, oldyPos, oldwidth, oldheight
Global.d oldAngle, rotation, Zoom
Global.l width, height, screenWidth, screenHeight
;}
;-> Constants
#ProgName = "Spiral"
#MaskColor = 0
#AlphaLevel = 5
#initialImageSize = 800
#EE = 2.718281828
#maxLoops = 5000
#direction = 0
#deg2rad = 0.0175
#minSize = 10
#maxSize = 8180
#maxZoom = 120 ; for some reason, numbers above this GPF
#ZoomFactor1 = 0.01
#ZoomFactor2 = 0.1
#ZoomFactor3 = 1
#RotateFactor1 = 1
#RotateFactor2 = 10
#RotateFactor3 = 45
#SizeFactor1 = 10
#SizeFactor2 = 20
#SizeFactor3 = 30
#PosFactor1 = #SizeFactor1 / 2
#PosFactor2 = #SizeFactor2 / 2
#PosFactor3 = #SizeFactor3 / 2
;}
;-> Enumerations
Enumeration
#ZoomIn
#ZoomIn2
#ZoomIn3
#ZoomOut
#ZoomOut2
#ZoomOut3
#MoveLeft
#MoveLeft2
#MoveRight
#MoveRight2
#MoveUp
#MoveUp2
#MoveDown
#MoveDown2
#RotateC
#RotateC2
#RotateC3
#RotateCC
#RotateCC2
#RotateCC3
#ESCape
#Reset
EndEnumeration
;}
#DotSpacing = 5
#ZoomFactor = 0.5
Procedure DrawStar()
#MiddleX = 552
#MiddleY = 360
#MinX = -1000
#MinY = -1000
#MaxX = 2000
#MaxY = 2000
Protected.l i
If StartVectorDrawing(WindowVectorOutput(0))
VectorSourceColor(RGBA(0, 0, 0, 255))
FillVectorOutput()
TranslateCoordinates(xPos, yPos)
; ; TranslateCoordinates(xPos * Zoom, yPos * Zoom)
RotateCoordinates(#MiddleX * Zoom, #MiddleY * Zoom, rotation)
ScaleCoordinates(Zoom, Zoom)
VectorSourceColor(RGBA(255, 0, 0, 255))
; Draw spokes
VectorSourceColor(RGBA(0, 255, 0, 255))
MovePathCursor(#MiddleX, #MinY, #PB_Path_Default)
AddPathLine(#MiddleX, #MaxY)
MovePathCursor(#MinX, #MiddleY)
AddPathLine(#MaxX, #MiddleY)
MovePathCursor(#MiddleX, #MiddleY)
AddPathLine(200, 200, #PB_Path_Relative)
MovePathCursor(#MiddleX, #MiddleY)
AddPathLine(-200, -200, #PB_Path_Relative)
MovePathCursor(#MiddleX, #MiddleY)
AddPathLine(200, -200, #PB_Path_Relative)
MovePathCursor(#MiddleX, #MiddleY)
AddPathLine(-200, 200, #PB_Path_Relative)
DashPath(1, 5)
StopVectorDrawing()
EndIf
EndProcedure ;DrawStar()
Procedure UpdateImage()
Protected hdc
SetWindowTitle(0, #ProgName + " Zoom:" + StrF(Zoom, 4) + " Width:" + StrF(width, 4))
DrawStar()
EndProcedure ;UpdateImage()
Procedure ResetStar()
rotation = 0
Zoom = 1
width = 800
height = width
UpdateImage()
EndProcedure
Procedure Initialise()
xPos = 0
yPos = 0
rotation = 0
Zoom = 1
width = 800
height = width
ExamineDesktops()
hWndInv = OpenWindow(0, 0, 0, DesktopWidth(0) / 2, DesktopHeight(0) / 2, #ProgName, _
#PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | _
#PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget, 0)
SetWindowColor(0, #MaskColor)
SetWindowLong_(hWndInv, #GWL_EXSTYLE, GetWindowLong_(hWndInv, #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(hWndInv, #MaskColor, 1, #LWA_COLORKEY)
StickyWindow(0, 1)
AddKeyboardShortcut(0, #PB_Shortcut_Add, #ZoomIn)
AddKeyboardShortcut(0, #PB_Shortcut_Add + #PB_Shortcut_Shift, #ZoomIn2)
AddKeyboardShortcut(0, #PB_Shortcut_Add + #PB_Shortcut_Alt, #ZoomIn3)
AddKeyboardShortcut(0, #PB_Shortcut_Subtract, #ZoomOut)
AddKeyboardShortcut(0, #PB_Shortcut_Subtract + #PB_Shortcut_Shift, #ZoomOut2)
AddKeyboardShortcut(0, #PB_Shortcut_Subtract + #PB_Shortcut_Alt, #ZoomOut3)
AddKeyboardShortcut(0, #PB_Shortcut_Left, #MoveLeft)
AddKeyboardShortcut(0, #PB_Shortcut_Left + #PB_Shortcut_Shift, #MoveLeft2)
AddKeyboardShortcut(0, #PB_Shortcut_Right, #MoveRight)
AddKeyboardShortcut(0, #PB_Shortcut_Right + #PB_Shortcut_Shift, #MoveRight2)
AddKeyboardShortcut(0, #PB_Shortcut_Up, #MoveUp)
AddKeyboardShortcut(0, #PB_Shortcut_Up + #PB_Shortcut_Shift, #MoveUp2)
AddKeyboardShortcut(0, #PB_Shortcut_Down, #MoveDown)
AddKeyboardShortcut(0, #PB_Shortcut_Down + #PB_Shortcut_Shift, #MoveDown2)
AddKeyboardShortcut(0, #PB_Shortcut_Right + #PB_Shortcut_Control, #RotateC)
AddKeyboardShortcut(0, #PB_Shortcut_Right + #PB_Shortcut_Control + #PB_Shortcut_Shift, #RotateC2)
AddKeyboardShortcut(0, #PB_Shortcut_Right + #PB_Shortcut_Alt, #RotateC3)
AddKeyboardShortcut(0, #PB_Shortcut_Left + #PB_Shortcut_Control, #RotateCC)
AddKeyboardShortcut(0, #PB_Shortcut_Left + #PB_Shortcut_Control + #PB_Shortcut_Shift, #RotateCC2)
AddKeyboardShortcut(0, #PB_Shortcut_Left + #PB_Shortcut_Alt, #RotateCC3)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #ESCape)
AddKeyboardShortcut(0, #PB_Shortcut_R + #PB_Shortcut_Control, #Reset)
DrawStar()
EndProcedure ;Initialise()
;-> MAIN
Initialise()
UpdateImage()
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Repaint
screenWidth = WindowWidth(0)
UpdateImage()
Case #PB_Event_Menu
KeyPressed = EventMenu()
; Debug KeyPressed
Select KeyPressed
;-Move
Case #MoveLeft
xPos - 1
; Debug "xPos: " + Str(xPos)
UpdateImage()
Case #MoveLeft2
xPos - 10
UpdateImage()
Case #MoveRight
xPos + 1
; Debug "xPos: " + Str(xPos)
UpdateImage()
Case #MoveRight2
xPos + 10
UpdateImage()
Case #MoveUp
yPos - 1
UpdateImage()
Case #MoveUp2
yPos - 10
UpdateImage()
Case #MoveDown
yPos + 1
UpdateImage()
Case #MoveDown2
yPos + 10
UpdateImage()
;-Zoom Spiral In
Case #ZoomIn
Debug "Case #ZoomIn"
Debug "Zoom = " + StrF(Zoom)
Debug "width = " + StrF(width)
Debug "screenWidth = " + StrF(screenWidth)
; ; ; ; ; If Zoom <= #maxZoom And width < screenWidth
If Zoom <= #maxZoom
Debug "If Zoom <= #maxZoom And width < screenWidth"
Zoom + #ZoomFactor1
width + #SizeFactor1 : height + #SizeFactor1
xPos - #PosFactor1 : yPos - #PosFactor1
UpdateImage()
Else
Debug "NOT If Zoom <= #maxZoom And width < screenWidth"
EndIf
Case #ZoomIn2
Debug "Case #ZoomIn2"
If Zoom <= #maxZoom
; If width < #maxSize
Zoom + #ZoomFactor2
width + #SizeFactor2 : height + #SizeFactor2
xPos - #PosFactor2 : yPos - #PosFactor2
UpdateImage()
EndIf
Case #ZoomIn3
Debug "Case #ZoomIn3"
If Zoom <= #maxZoom
Zoom + #ZoomFactor3
width + #SizeFactor3 : height + #SizeFactor3
xPos - #PosFactor3 : yPos - #PosFactor3
UpdateImage()
EndIf
;-Zoom Out
Case #ZoomOut
Debug "Case #ZoomOut"
If width > #minSize
If Zoom > #ZoomFactor1
Zoom - #ZoomFactor1
If Zoom <= 0
Zoom = #ZoomFactor1
EndIf
width - #SizeFactor1 : height - #SizeFactor1
xPos + #PosFactor1 : yPos + #PosFactor1
UpdateImage()
EndIf
EndIf
Case #ZoomOut2
Debug "Case #ZoomOut2"
If width > #minSize
If Zoom > #ZoomFactor2
Zoom - #ZoomFactor2
If Zoom <= 0
Zoom = #ZoomFactor2
EndIf
width - #SizeFactor2 : height - #SizeFactor2
xPos + #PosFactor2 : yPos + #PosFactor2
UpdateImage()
EndIf
EndIf
Case #ZoomOut3
Debug "Case #ZoomOut3"
If width > #minSize
If Zoom > #ZoomFactor3
Zoom - #ZoomFactor3
If Zoom <= 0
Zoom = #ZoomFactor3
EndIf
width - #SizeFactor3 : height - #SizeFactor3
xPos + #PosFactor3 : yPos + #PosFactor3
UpdateImage()
EndIf
EndIf
;- Rotate Clockwise
Case #RotateC
rotation - #RotateFactor1
; Debug "Angle: " + StrF(ANGLE)
UpdateImage()
Case #RotateC2
rotation - #RotateFactor2
; Debug "Angle: " + StrF(ANGLE)
UpdateImage()
Case #RotateC3
rotation - #RotateFactor3
; Debug "Angle: " + StrF(ANGLE)
UpdateImage()
;-Rotate 1 CounterClockwise
Case #RotateCC
rotation + #RotateFactor1
; Debug "Angle: " + StrF(ANGLE)
UpdateImage()
Case #RotateCC2
rotation + #RotateFactor2
; Debug "Angle: " + StrF(ANGLE)
UpdateImage()
Case #RotateCC3
rotation + #RotateFactor3
; Debug "Angle: " + StrF(ANGLE)
UpdateImage()
Case #Reset
ResetStar()
EndSelect ;KeyPressed
EndSelect ;Event
Until KeyPressed = #ESCape Or event = #PB_Event_CloseWindow
End
;}