PDA

View Full Version : Canvas & GdiPlus



peter
24-02-2014, 20:12
Hello,


Gdiplus on Canvas, is that possible?
I have made a small attempt and got a success.


The question is whether this runs with Windows8, Window7 has no problems.
Gdiplus is an ancient Gdi and will not updated anymore. Nevertheless, it has a mighty Graphics on board.


At the moment, I have only some primitives, to play with it.


Examples:


Uses "ui"
#INCLUDE "gdip.inc"


OpenWindow 640, 480
Long x, y, i


SetSmoothMode 2
While IsWindow(hwnd) And GetAsyncKeyState(27)=0
ClsColor &HFF000000

DrawBox 50,50,100,100,1,&HFFFFFF00

FillBox 50, 180,100,100, &HFFFFFF00
FillBox 100,220,100,100, &H6400FF00
FillBox 140,260,100,100, &H64FF0000

DrawLine 0,170,639,170,2, &HFFFF0000
DrawEllipse 200,100,60,60,2,&HFF00FFFF
FillEllipse 280,100,60,60, &HFFD49696

For i=100 To 360
DrawPoint i,400,1,ARGB 200,255,255,255
Canvas_SetPixel i,410,&HFFFFFF
Next
Canvas_Redraw
Sleep 10
Wend
ShutDown
Canvas_Window End hwnd




Uses "ui"
#INCLUDE "gdip.inc"


OpenWindow 640, 480


Long col,sx,sy,anz,speed,xscreen,yscreen,i,sx,sy,co
xscreen=640 : yscreen=480 : speed=8 : anz=2000


Dim xstern(anz) As Long
Dim ystern(anz) As Long
Dim zstern(anz) As Long


For i=1 To anz
xstern(i) = Rnd(-(xscreen/2), (xscreen/2))*255
ystern(i) = Rnd(-(yscreen/2), (yscreen/2))*255
zstern(i) = Rnd( speed,255 )
Next


SetSmoothMode 2
While IsWindow(hwnd) And GetAsyncKeyState(27)=0
ClsColor &HFF000000
For i=1 To anz
zstern(i) = zstern(i) - speed
If zstern(i) <= speed Then zstern(i) = 255
sx = (xstern(i) / zstern(i)) + (xscreen/2)
sy = (ystern(i) / zstern(i)) + (yscreen/2)
co = (300 - zstern(i))
DrawPoint sx, sy, 4, ARGB 255,co,co,co
Next
Canvas_Redraw
Sleep 10
Wend
ShutDown
Canvas_Window End

peter
24-02-2014, 20:33
Uses "ui"
#INCLUDE "gdip.inc"


OpenWindow 640, 480
Randomize


Long x, y
SetSmoothMode 2


While IsWindow(hwnd) And GetAsyncKeyState(27)=0
ClsColor &HFF000000
For y=0 To Height Step 20
For x=0 To Width Step 20
DrawLine x,y,240,69,1,ARGB 255,Rnd(64,255),Rnd(64,255),Rnd(64,255)
Next
Next
Canvas_Redraw
Sleep 10
Wend
ShutDown
Canvas_Window End hwnd

peter
24-02-2014, 20:34
Uses "ui"
#INCLUDE "gdip.inc"


OpenWindow 800, 600
Randomize


Type Star
xStar As Long
yStar As Long
speed As Long
End Type


Dim Stars(450) As Star
Dim xRes As Long =800
Dim yRes As Long =600
Long i


For i=1 To 450
Stars(i).xStar = Rnd(1, xRes -2)
Stars(i).yStar = Rnd(1, yRes -2)
Stars(i).speed = Rnd(2, 8)
Next
SetSmoothMode 2


While IsWindow(hwnd) And GetAsyncKeyState(27)=0
ClsColor &HFF000000
For i = 1 To 450
DrawPoint Stars(i).xStar,Stars(i).yStar,2,ARGB 255,255,255,255
Stars(i).xStar = Stars(i).xStar + Stars(i).speed
If Stars(i).xStar > xRes Then
Stars(i).xStar = 0
Stars(i).yStar = Rnd(1, yRes -2)
Stars(i).speed = Rnd(2, 8)
End If
Next
Canvas_Redraw
Sleep 10
Wend
ShutDown
Canvas_Window End hwnd

Petr Schreiber
24-02-2014, 22:08
Works okay on Windows 8!,

.NET actually seems to wrap the GDI+, at least on Windows, so it will stay usable for long time I guess :)

One tip, instead of:


zstern(i) = zstern(i) - speed
If zstern(i) <= speed Then zstern(i) = 255


you can do:


zstern(i) = CYCLE_Prev(zstern(i), speed, 255, speed)


First parameter = cycled value
Second parameter = minimum value
Third parameter = maximum value
Fourth parameter = decrement


Petr

peter
24-02-2014, 23:06
thanks Petr,

but I will go the old programming way, I am not that open for new instructions.
I love it easy! that's the reason why I am an assembler programmer.