PDA

View Full Version : Back to the root



peter
13-02-2014, 01:54
Hi,

I am starting from the beginning without dll and gpf's.



Uses "ui","math"
#INCLUDE "api.inc"

DWord hdc, hwnd
hwnd = Canvas_Window("ThinBasic",10,10,640,480)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()
Canvas_Font "times",14, %CANVAS_FONTSTYLE_NORMAL

Long w = 640/2
Long h = 480/2
Dim a,v As Single
Long cfont = LoadIcon "icon/cfont.ani"

While IsWindow(hwnd) And Keydown(%VK_ESCAPE)=0
Canvas_Clear Rgb(240,255,255)
For a=0 To 360 Step 10
Canvas_Circle w+Sin(DegToRad(a))*110, h+Cos(DegToRad(a))*110, 10, Rgb(0,0,255)
Canvas_Circle w+Cos(DegToRad(a))*100, h+Sin(DegToRad(a))*100, 10, Rgb(0,0,255)
Next

Canvas_Circle w+Sin(DegToRad(v))*110, h+Cos(DegToRad(v))*110, 10, Rgb(255,0,0), -1
Canvas_Circle w+Cos(DegToRad(v))*100, h+Sin(DegToRad(v))*100, 10, Rgb(128,0,0), -1

v +=10
If v >360 Then v=0
IconText hdc,cfont,176,16,"WHAT FUNNY",32,64

Canvas_Redraw
Sleep 10
Wend
Canvas_Window End


Sub DrawText(x,y As Long, txt As String, col As Long)
Canvas_Color(col,-2)
Canvas_SetPos(x,y)
Canvas_Print(txt)
End Sub

Function KeyDown(cKey As Long) As Integer
Return GetAsyncKeyState cKey
End Function

peter
13-02-2014, 23:27
Hi,

Added: load and save to the api library.
Is for binaries.

Here is a small "load" demo.


Uses "ui"
#INCLUDE "api.inc"


DWord hdc, hwnd
hwnd = Canvas_Window("ThinBasic",10,10,640,480)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()
Canvas_Font "verdana",24, %CANVAS_FONTSTYLE_NORMAL


Dim map(1200) As Byte
Dim x,y,z,ico As Long


ico = LoadIcon "map/strip.ani"
LoadBytes "map/map1-1.txt",map(1),1200


While IsWindow(hwnd) And Keydown(%VK_ESCAPE)=0
For y=0 To 29
For x=0 To 39
z=(y*40+x)+1
If map(z) = 33 Then DrawIcon hdc,ico,x*32,y*32,32,32,0
If map(z) = 34 Then DrawIcon hdc,ico,x*32,y*32,32,32,1
If map(z) = 39 Then DrawIcon hdc,ico,x*32,y*32,32,32,2
Next
Next
DrawText 250,360,"WHAT!",Rgb(200,255,0)
Canvas_Redraw
Sleep 10
Wend
Canvas_Window End

ErosOlmi
14-02-2014, 16:11
Thanks a lot Peter.
Works perfectly.

Some of the defined functions are already present in thinBasic UI module as native functions with "WIN_" prefix.
For example:

Declare Function DeleteObject Lib "gdi32.dll" Alias "DeleteObject" (ByVal hObject As Long) As Long
Declare Function DeleteDC Lib "gdi32.dll" Alias "DeleteDc" (ByVal hdc As Long) As Long

are present in UI module as:

Win_DeleteObject
Win_DeleteDC

and you can use them directly.
If you like I can add some or all the functions you need as native in UI.
In help file under thinBasic Modules > UI (User Interface) > Windows API > you can find the list of API functions I've already developed.

Ciao
Eros

peter
14-02-2014, 19:21
Thank you Eros.


Yes, I know your WIN_ many declaration in it.
Your offer sounds good.


Most of api declaration what I use, need a type declaration / structure.
Is this a problem in the UI core?


I think that I need a lot of declarations with time, I never have standstill.
I can do a list, if you want.

Updated api.inc

here is a small particle test. wave 16 is my favourite.


Uses "ui"
#INCLUDE "api.inc"


DWord hwnd = Canvas_Window("api_app",xMid(800),yMid(600),800,600)
Canvas_Attach(hwnd,0,%TRUE)
DWord hdc = Canvas_GetDC()
Canvas_Font "verdana",14,0


Dim a, t, xp, yp, zp, xs, ys, z, c As Single
Long p
c=2


Sub xCircle(x, y, w As Single)
For a=0 To 36 Step 2
DrawPoint(x+Sin(a)*w,y+Cos(a)*w,2,&hFFFFFF)
Next
End Sub


While IsWindow hwnd And KeyDown(%VK_ESCAPE)=0
Canvas_Clear (0)

For t=1 To 12 Step .1
xp = 120 * Cos(t*c)
yp = 120 * Sin(t*c)
zp = p*Sin(t*16) + 200
xs = (200 + xp * 320 \ 160)
ys = (200 - yp * 320 \ 160)
xCircle(200+xs, 100+ys, zp-20*c)
Next


DrawText 330,0,"Wave " & c, &HFFFFFF
Canvas_Redraw

p +=1
If p >=150 Then
p = -p
c +=1
If c=17 Then c=2
End If
Wend

peter
15-02-2014, 23:55
Hello,

Springtime test.


Uses "ui"
#INCLUDE "api.inc"


DWord hdc, hwnd
hwnd = Canvas_Window("api_app",xMid(650),yMid(480),640,480)
Canvas_Attach(hwnd,0,%TRUE)
hdc = Canvas_GetDC()
Canvas_Font "verdana",24, %CANVAS_FONTSTYLE_NORMAL


Type pp
x As Long
y As Long
z As Long
End Type


Dim fly(80) As pp
Dim ico1, ico2, ico3, np, a, vz As Long
Single sv, hz
np =80


ico1 = Loadicon "icon/bild2.ico"
ico2 = LoadIcon "icon/bstrip.ani"
ico3 = Loadicon "icon/beehead.ani"


For a=1 To np
fly(a).x = Rnd(0,639)
fly(a).y = Rnd(0,479)
fly(a).z = Rnd(0,5)
Next


While IsWindow(hwnd) And Keydown(%VK_ESCAPE)=0
DrawIcon hdc,ico1,0,0,640,480,0
DrawIcon hdc,ico3,256,176,128,128,vz
For a=1 To np
fly(a).x = fly(a).x -1
If fly(a).x < -64 Then
fly(a).x = 640
fly(a).y = Rnd(0,420)
End If
DrawIcon hdc,ico2,fly(a).x,fly(a).y, 64,64, fly(a).z
Next
Canvas_Redraw

sv +.5
If sv >=1 Then
sv = 0
For a=1 To np
fly(a).z +=1
If fly(a).z=12 Then fly(a).z=0
Next
End If

hz +=.1
If hz >=1 Then
hz = 0
vz +=1
If vz=4 Then vz=0
End If
SetFps (100)
Wend
Canvas_Window End

peter
16-02-2014, 16:18
Hello,


api update.


loads and plays simple wav files.
I have added collision (distance algorithm). good for simple games.


test collision:


Uses "ui"
#INCLUDE "api.inc"


DWord hwnd = Canvas_Window("api_app",xMid(640),yMid(480),640,480)
Canvas_Attach(hwnd,0,%TRUE)
DWord hdc = Canvas_GetDC()
Canvas_Font "verdana",24, %CANVAS_FONTSTYLE_NORMAL


Long bx1, by1, bx2, by2, cx, cy, wv, ic, az, bz
Single vz
bx1=0:by1=100:bx2=620:by2=100:bz=4


wv = Loadwav "wave/glass.wav"
ic = LoadIcon "icon/alien.ani"


While IsWindow(hwnd) And Keydown(%VK_ESCAPE)=0
Canvas_Clear Rgb(240,255,255)
DrawIcon hdc,ic,bx1,by1,64,64,az
DrawIcon hdc,ic,bx2,by2,64,64,bz

If Collide(bx1,by1,bx2,by2)=60 Then
cx = bx1
cy = by1
bx1 =0
bx2 =620
by1 +=20
by2 +=20
PlayWav wv
If by1 >=420 Then
by1 = 0
by2 = 0
End If
End If


bx1 +=1
bx2 -=1

vz +=.1
If vz >=1 Then
vz = 0
az +=1
If az=8 Then az=0
bz = bz+1
If bz=8 Then bz=0
End If
Canvas_Redraw
SetFps (80)
Wend
Canvas_Window End

ErosOlmi
18-02-2014, 13:45
Dear Peter,

just to let you know I'm checking your sources and adding as much as possible native Win_* functions.
I will let you know when ready to publish a new thinBasic version.

Ciao
Eros