PDA

View Full Version : moving canvas box



largo_winch
25-11-2011, 13:00
I wanted to move a canvas box like an animation. for this example I wish to move box from left to right side, quite simple. but that's not working very smooth. I use a "refresh" button to move the box. My idea was to add some buttons to stop the animation or move it again for next time. but for this time I want to see how this box can move slowly from whole left side to right side. I think the loop (for..next) isn't perfect.

moving canvas box example:


' Empty GUI script created on 11-25-2011 10:42:26 by (ThinAIR)

Uses "UI"

' -- ID numbers of controls
Begin ControlID
%myCanvas
%refresh
%bClose
End ControlID

Type BGRA
B As Byte
G As Byte
R As Byte
A As Byte
End Type

' -- Create dialog here
Function TBMain()
Local hDlg As DWord

Dialog New 0, "Moving canvas Box",-1,-1, 200, 140, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg

' -- Place controls here
Dim cx, cy As Long
Dialog Pixels hDlg, 200, 200 To Units cx, cy
Control Add Canvas, hDlg, %myCanvas, "", 5, 5, cx, cy

Control Add Button, hDlg, %refresh, "refresh", 10+cx, 5, 50, 14, Call refreshProc
Control Add Button, hDlg, %bClose, "Close", 10+cx, cy+5-14, 50, 14, Call bCloseProc

Dialog Show Modal hDlg, Call dlgProc

End Function

' -- Callback for dialog
CallBack Function dlgProc()

' -- Test for messages
Select Case CBMSG
Case %WM_INITDIALOG
Canvas_Attach(CBHNDL, %myCanvas, %FALSE)
DrawGraphics()
Canvas_Redraw

Case %WM_CLOSE
' -- Put code to be executed before dialog end here

End Select

End Function

' -- Callback for close button
CallBack Function bCloseProc()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If

End Function

CallBack Function refreshProc()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then

Canvas_Attach(CBHNDL, %myCanvas, %TRUE)
DrawGraphics()
Canvas_Redraw
End If
End If

End Function

'-------------------->
Sub DrawGraphics()
'-------------------->
Local z, v, r, g, b As Long
Local x, y As Double
Local hDlg, mygraf As Long
Local oldx, oldy As Double
Local d, myExit As Long
Local ypush As Double

'---------------- yellow background ok -------------------------------------->
r = 228
g = 255
b = 0
v = Rgb(r, g, b)
z = (r + g + b)\3

If z < 128 Then z = 255 Else z = 0
z = Rgb(100, 220, 40)
Canvas_Clear v
Canvas_Color z, v

'---------------- moving box in foreground from left to right side ? ------>

d = 1 : x = 10 : y = 10 : oldx = x : oldy = y

Canvas_Box(x,y, x+10,y+10, 0,%RED,%GREEN)

'----> loop starting point
For x = -5 To 25 Step 0.1 ' ?
For ypush = 2 To 25 Step 1.0 '?
'Canvas_Width(ypush)
'Canvas_Box(oldx,oldy, oldx+ypush,oldy+ypush,0,%GREEN,%GREEN)
Canvas_Box(oldx,oldy, oldx+10,oldy+10,0,%GREEN,%GREEN)
oldx = x : oldy = y
Canvas_Box(x,y, x+10,y+10,0,%RED,%GREEN)
Canvas_Redraw
Next
Next
End Sub



bye, largo

Michael Clease
25-11-2011, 13:25
I'm not at a computer at the moment but I would suggest you look at timers and static variables

largo_winch
25-11-2011, 16:17
hi michael, yes, could be helpful, I will check more this afternoon/evening, but I see a light for solving the example


Case %WM_TIMER
If CBCTL = %tAnimationTimer Then
DrawGraphics()
Canvas_Redraw
End If


bye, largo

largo_winch
25-11-2011, 20:34
delete this post.

largo_winch
19-12-2011, 18:34
delete this post.