PDA

View Full Version : canvas example :)



lydia_sp
15-09-2009, 18:38
hello all.

what the purpose do I have with canvas module ?

my example I do it first time and wonder why I can use it if there are only a few commands for canvas module? Or I am understanding something wrong. it`s display beautiful things but like 2d pixel world ;)


'' lydias canvas tb example

uses "UI"

' -- ID numbers of controls
Begin Const
%cCanvasDB = %WM_USER + 500
%btnClose
%btnManipul

%tAnimationTimer
End Const

dim smilegefix(225) as integer = 16711935,16711935,16711935,16711935,16766464,16766464,16766464,16760064,16760064,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16766464,16766464,16766464,16766464,16766464,16766464,16760064,16760064,16755968,16711935,16711935,16711935,16711935,16711935,16766464,16766464,16772864,16772864,16772864,16766464,16766464,0,16760064,16755968,16753920,16711935,16711935,16711935,16711935,16766464,16772864,0,0,16772864,16772864,16766464,16766464,0,16760064,16755968,16711935,16711935,16711935,16766464,16766464,16772864,0,0,16772864,16772864,16766464,16766464,16760064,0,16755968,16751616,16711935,16711935,16766464,16766464,16772864,16772864,16772864,16772864,16772864,16766464,16766464,16760064,0,16755968,16751616,16711935,16711935,16766464,16766464,16766464,16772864,16772864,16772864,16766464,16766464,16760064,16760064,0,16753920,16751616,16711935,16711935,16760064,16766464,16766464,16766464,16766464,16766464,16766464,16766464,16760064,16760064,0,16753920,16751616,16711935,16711935,16760064,16760064,16760064,0,0,16766464,16760064,16760064,16760064,16755968,0,16751616,16751616,16711935,16711935,16711935,16760064,16760064,0,0,16760064,16760064,16760064,16755968,0,16753920,16751616,16711935,16711935,16711935,16711935,16755968,16755968,16760064,16760064,16760064,16755968,16755968,0,16753920,16751616,16751616,16711935,16711935,16711935,16711935,16711935,16753920,16755968,16755968,16755968,16753920,16753920,16751616,16751616,16751616,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16751616,16751616,16751616,16751616,16751616,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935
dim n, k,z,x,y as integer

' -- Create dialog here
FUNCTION TBMAIN()
LOCAL hDlg AS DWORD

DIALOG New 0, "lydias Canvas example in double buffermode",-1,-1, 296, 186, _
%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, %cCanvasDB, "", -55+cx+65, 32, cx,cy
CONTROL ADD LABEL, hDlg, -1, "Double cigarette buffer"+$CRLF+"(draws all at once, no flicker and braindamage at all)", 5+cx+5, 5, cx, 40

CONTROL ADD BUTTON, hDlg, %btnClose, "Click to close", 10+cx, 44+cy, cx-6, 14, CALL btnCloseProc
CONTROL ADD BUTTON, hDlg, %btnManipul, "don't manipulate me", -120+cx, -50+cy, cx-8, 18, CALL btnManipulate

DIALOG SHOW MODAL hDlg, CALL dlgProc

END FUNCTION

' -- Callback for dialog
CALLBACK FUNCTION dlgProc()

' -- Test for messages
SELECT CASE CBMSG

CASE %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
DIALOG SET TIMER CBHNDL, %tAnimationTimer, 10, %NULL

CASE %WM_TIMER
DIM tx, ty as long

Canvas_Attach(cbhndl, %cCanvasDB, %true)
DrawGraphics()
Canvas_Redraw ' -- Needs this to sync

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

END SELECT

END FUNCTION

' -- Callback for close button
CALLBACK FUNCTION btnCloseProc()

IF CBMSG = %WM_COMMAND THEN
IF CBCTLMSG = %BN_CLICKED THEN
' -- Closes the dialog
DIALOG END CBHNDL
END IF
END IF

END FUNCTION

CALLBACK FUNCTION btnManipulate()
IF CBMSG = %WM_COMMAND THEN
IF CBCTLMSG = %BN_CLICKED THEN
dim a,b,c as integer
a = 100
b = 200
c= a*b-19999
msgbox 0, "earth quake st. andreas ground"
msgbox 0, "result: " + c
END IF
END IF

END FUNCTION

Type PolyPoint
x as single
x1 as single
y as single
y1 as single
count as single
End Type

dim pp as PolyPoint

Type PolyArray
xy(500) as PolyPoint

'pa.count = 4 '---Indicate you need 4 vertex
'pa.xy(1).x = x1 '---X1
'pa.xy(1).y = y1-150 '---Y1
'pa.xy(2).x = x1+150 '---X2
'pa.xy(2).y = y1 '---Y2
'pa.xy(3).x = x1 '---X3
'pa.xy(3).y = y1+150 '---Y3
'pa.xy(4).x = x1-150 '---X4
'pa.xy(4).y = y1 '---Y4

End Type

dim pa As PolyArray

Canvas_setpos (step x+50,y+40)
Canvas_Polygon pa, rgb(0,50,255), RGB(5,128,255),%Canvas_FillStyle_Solid


SUB DrawGraphics()
DIM tx, ty AS LONG


tx = 100+cos(gettickcount/100)*10
ty = 100+sin(gettickcount/100)*10

canvas_COLOR rgb(128, 255, 0), RGB(0, 0, 0)
Canvas_Clear(rgb(0,0,0))
Canvas_Box(tx-50,ty-50,tx,ty, 0, rgb(255, 0, 0), rgb(255,128,0),%Canvas_FillStyle_DiagonalCrossedLines )
canvas_print "Ciao maria "+STR$(rnd(1,256))
canvas_Color( 10,180)
canvas_print " a tutti fatale fame !"+STR$(rnd(1,256))

for x as integer =1 to 40
for y as integer = 1 to 55
z=rnd(1,2)
Canvas_Line ((10,10), (160, 160), rgb(55,255,0))
Canvas_Line ((0,0), (200, 200), rgb(255,0,0))
Canvas_Line ((200,0), (0, 200), rgb(255,0,0))

Canvas_Line ((x+10,y+10), (10+z, smilegefix(225)), rgb(0,50,255))
Canvas_SetPixel x+50,y+50, rgb(120,50,255)
''Canvas_BitmapGetFileInfo

next
next

END SUB

I saw some example and tried this one for myself. "canvas_polygon pa" doesn`t work cause I have to check UDT handling again !

bye, lydia

lydia_sp
16-09-2009, 17:19
hi :)

as "canvas_polygon" doesn`t work with help file example (UDT kind) I have tried to find a correct way for my canvas example. I did it !

complete and correct version:


'' lydias canvas tb example

uses "UI"

' -- ID numbers of controls
Begin Const
%cCanvasDB = %WM_USER + 500
%btnClose
%btnManipul

%tAnimationTimer
End Const

dim smilegefix(225) as integer = 16711935,16711935,16711935,16711935,16766464,16766464,16766464,16760064,16760064,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16766464,16766464,16766464,16766464,16766464,16766464,16760064,16760064,16755968,16711935,16711935,16711935,16711935,16711935,16766464,16766464,16772864,16772864,16772864,16766464,16766464,0,16760064,16755968,16753920,16711935,16711935,16711935,16711935,16766464,16772864,0,0,16772864,16772864,16766464,16766464,0,16760064,16755968,16711935,16711935,16711935,16766464,16766464,16772864,0,0,16772864,16772864,16766464,16766464,16760064,0,16755968,16751616,16711935,16711935,16766464,16766464,16772864,16772864,16772864,16772864,16772864,16766464,16766464,16760064,0,16755968,16751616,16711935,16711935,16766464,16766464,16766464,16772864,16772864,16772864,16766464,16766464,16760064,16760064,0,16753920,16751616,16711935,16711935,16760064,16766464,16766464,16766464,16766464,16766464,16766464,16766464,16760064,16760064,0,16753920,16751616,16711935,16711935,16760064,16760064,16760064,0,0,16766464,16760064,16760064,16760064,16755968,0,16751616,16751616,16711935,16711935,16711935,16760064,16760064,0,0,16760064,16760064,16760064,16755968,0,16753920,16751616,16711935,16711935,16711935,16711935,16755968,16755968,16760064,16760064,16760064,16755968,16755968,0,16753920,16751616,16751616,16711935,16711935,16711935,16711935,16711935,16753920,16755968,16755968,16755968,16753920,16753920,16751616,16751616,16751616,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16751616,16751616,16751616,16751616,16751616,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935,16711935
dim n, k,z as integer 'x,y

' -- Create dialog here
FUNCTION TBMAIN()
LOCAL hDlg AS DWORD

DIALOG New 0, "lydias Canvas example in double buffermode",-1,-1, 296, 186, _
%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, %cCanvasDB, "", -55+cx+65, 32, cx,cy
CONTROL ADD LABEL, hDlg, -1, "Double cigarette buffer"+$CRLF+"(draws all at once, no flicker and braindamage at all)", 5+cx+5, 5, cx, 40

CONTROL ADD BUTTON, hDlg, %btnClose, "Click to close", 10+cx, 44+cy, cx-6, 14, CALL btnCloseProc
CONTROL ADD BUTTON, hDlg, %btnManipul, "don't manipulate me", -120+cx, -50+cy, cx-8, 18, CALL btnManipulate

DIALOG SHOW MODAL hDlg, CALL dlgProc

END FUNCTION

' -- Callback for dialog
CALLBACK FUNCTION dlgProc()

' -- Test for messages
SELECT CASE CBMSG

CASE %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
DIALOG SET TIMER CBHNDL, %tAnimationTimer, 10, %NULL

CASE %WM_TIMER
DIM tx, ty as long

Canvas_Attach(cbhndl, %cCanvasDB, %true)
DrawGraphics()
Canvas_Redraw ' -- Needs this to sync

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

END SELECT

END FUNCTION

' -- Callback for close button
CALLBACK FUNCTION btnCloseProc()

IF CBMSG = %WM_COMMAND THEN
IF CBCTLMSG = %BN_CLICKED THEN
' -- Closes the dialog
DIALOG END CBHNDL
END IF
END IF

END FUNCTION

CALLBACK FUNCTION btnManipulate()
IF CBMSG = %WM_COMMAND THEN
IF CBCTLMSG = %BN_CLICKED THEN
dim a,b,c as integer
a = 100
b = 200
c= a*b-19999
msgbox 0, "earth quake st. andreas ground"
msgbox 0, "result: " + c
END IF
END IF

END FUNCTION

'' udt part ---------------------------

Type PolyPoint
x as single
x1 as single
y as single
y1 as single
xy as single
End Type

Type PolyArray
xy(500) as long
count as long
x1(100) as long
y1(100) as long
End Type

dim pa as PolyArray
dim x1 as PolyArray
dim y1 as PolyArray
dim x as PolyArray
dim y as PolyArray

pa.count = 4 '---Indicate you need 4 vertex
pa.xy(1) = x1 '---X1
pa.xy(1) = y1-150 '---Y1
pa.xy(2) = x1+150 '---X2
pa.xy(2) = y1 '---Y2
pa.xy(3) = x1 '---X3
pa.xy(3) = y1+150 '---Y3
pa.xy(4) = x1-150 '---X4
pa.xy(4) = y1 '---Y4

msgbox 0, "udt results hard stuff: " + pa.count
'' pa.xy(1).x = x1 '--- doesnt work !!!

Canvas_setpos (step x+50,y+40)
Canvas_Polygon pa, rgb(0,50,255), RGB(5,128,255),%Canvas_FillStyle_Solid

'' udt part fin ---------------------------

SUB DrawGraphics()
DIM tx, ty AS LONG


tx = 100+cos(gettickcount/100)*10
ty = 100+sin(gettickcount/100)*10

canvas_COLOR rgb(128, 255, 0), RGB(0, 0, 0)
Canvas_Clear(rgb(0,0,0))
Canvas_Box(tx-50,ty-50,tx,ty, 0, rgb(255, 0, 0), rgb(255,128,0),%Canvas_FillStyle_DiagonalCrossedLines )
canvas_print "Ciao maria "+STR$(rnd(1,256))
canvas_Color( 10,180)
canvas_print " a tutti fatale fame !"+STR$(rnd(1,256))
dim x,y as integer

for x = 1 to 40
for y = 1 to 55
z=rnd(1,2)
Canvas_Line ((10,10), (160, 160), rgb(55,255,0))
Canvas_Line ((0,0), (200, 200), rgb(255,0,0))
Canvas_Line ((200,0), (0, 200), rgb(255,0,0))

Canvas_Line ((x+10,y+10), (10+z, smilegefix(225)), rgb(0,50,255))
Canvas_SetPixel x+50,y+50, rgb(120,50,255)
''Canvas_BitmapGetFileInfo

next
next

END SUB

udt kind like



'Canvas_polygon pa.xy(1).x = x1

'--- doesnt work !" really as help file about canvas_polygon says. - Anybody can say why ?

Look at my script, I have done another way. I am not sure if the canvas_polygon pa was built as I don`t see it at canvas scene ;) but the code is correct, I think so.

http://community.thinbasic.com/index.php?topic=2914.msg22143;topicseen#new

saludos, lydia