I need some help dealing with a graphic.
I thought I was close but I asked Grok for help to debug it. That was 2 days ago, and I think it’s taken me farther and farther from the right answer.
I have a DesktopCanvas on my window called Float_Piece. It starts invisible and located at (172, 398) — which isn’t meaningful except that I needed a place to put it before I use it.
First, I’m using it without any problem in a MouseDrag event.
In a window named winBoard, I’m dragging an object around that’s a DesktopRectangle object. It has a MouseDrag event that works perfectly:
if winBoard.isDragging then
winBoard.Float_Piece.Left = X - 15 + self.Left
winBoard.Float_Piece.Top = Y - 15 + self.Top
end if
But the problem is when I want to show it moving from one location to another in my window.
I’ve created a routine called Animate_Float_Piece.
Animate_Float_Piece(startLeft As Double, startTop As Double, endLeft As Double, endTop As Double, durationMs As Integer)
Dim currentLeft As Double = startLeft
Dim currentTop As Double = startTop
Dim targetLeft As Double = endLeft
Dim targetTop As Double = endTop
Dim animationSteps As Integer = 60
Dim stepLeft As Double = (endLeft - startLeft) / animationSteps
Dim stepTop As Double = (endTop - startTop) / animationSteps
Dim delayMicroseconds As Integer = (durationMs * 10000) \ animationSteps
Float_Piece.Visible = True
For currentStep As Integer = 0 To animationSteps - 1
currentLeft = startLeft + (stepLeft * currentStep)
currentTop = startTop + (stepTop * currentStep)
Float_Piece.Left = currentLeft
Float_Piece.Top = currentTop
Float_Piece.Refresh
Dim startTime As Double = System.Microseconds
While System.Microseconds < startTime + delayMicroseconds
App.DoEvents
Wend
Next
Float_Piece.Left = targetLeft
Float_Piece.Top = targetTop
Float_Piece.Refresh
Yes, I was too lazy to figure out using a timer again. Maybe in the future. But I don’t see the image and I don’t see it floating across the screen. Since I wasn’t sure if the problem is with my canvas or with the movement, I simplified the animation routine so I would just display the canvas in the middle of the window. I changed the code to:
Animate_Float_Piece(startLeft As Double, startTop As Double, endLeft As Double, endTop As Double, durationMs As Integer)
Float_Piece.Left = 400
Float_Piece.Top = 400
Float_Piece.Visible = True
Float_Piece.Refresh
If Float_Piece.Backdrop = Nil Then
MessageBox(“Backdrop is NIL! No image assigned.”)
End If
But I still don’t see the static image on the screen.
Grok told me that I had to add a Paint event to Float_Piece. Not sure why because it appears in the MouseDrag event but I added:
If g = Nil Then Return
// Handle Retina
Var scale As Double = If(Me.ScaleFactor > 0, Me.ScaleFactor, 1.0)
Var w As Double = Backdrop.Width / scale
Var h As Double = Backdrop.Height / scale
g.DrawPicture(Backdrop, 0, 0, w, h)
But the image always appears in position (0,0) of the window and not at position (400,400). I’ve looked at the values of Left and Top in the debugger in the Paint event, and they each = 400.
So I’m stuck and can’t figure out why the canvas is displaying at 0,0.
