Re: Phix: cffi.e
- Posted by andreasWagner 5 days ago
- 263 views
Hallo,
i just had to try it works
I would never have thought of trying it this way. there has been a function in tinlib for over 10 years that has never worked because of this problem (WindowFromPoint).
of course i still have to test if there are any memory leaks.
thanks a lot
Andreas
petelomax said...
Hmm, maybe something like this would work (where color is a single #RRGGBBAA value):
local constant xDrawCircleV = define_c_proc(ray,"+DrawCircleV",{C_FLOAT,C_FLOAT,C_FLOAT,C_DWORD}) c_proc(xDrawCircleV,{x,y,radius,color})
only for windows 32bit but it works
-- file: ray.e -- practically everything is shamelessly copied from Icy Vikings raylib.e atom ray constant Color =C_ULONG public struct Vector2 atom x = 0 atom y = 0 end struct ray = open_dll("raylib.dll") if ray = 0 then puts(1,"Unable to load Raylib!\n") abort(0) end if --public function makeRGB(integer REDi,integer GREENi, integer BLUEi,integer ALPHAi) -- return(REDi+BLUEi*256+(GREENi*256*256)+(ALPHAi*256*256*256)) --end function public function makeRGB(sequence color) return(color[1]+color[2]*256+(color[3]*256*256)+(color[4]*256*256*256)) end function public constant WHITE = {255,255,255,255}, BLACK = {0,0,0,255}, MAGENTA = {255,0,255,255}, RAYWHITE = {245,245,245,255}, RED = {230,41,55,255}, MAROON = {190,33,55,255}, GREEN = {0,228,48,255}, LIME = {0,158,47,255}, DARKGREEN = {0,117,44,255}, SKYBLUE = {102,191,255,255}, BLUE = {0,121,241,255}, YELLOW = {253,249,9,255} constant xInitWindow = define_c_proc(ray,"+InitWindow",{C_INT,C_INT,C_PTR}), xCloseWindow = define_c_proc(ray,"+CloseWindow",{}), xWindowShouldClose = define_c_func(ray,"+WindowShouldClose",{},C_BOOL), xSetTargetFPS = define_c_proc(ray,"+SetTargetFPS",{C_INT}), xBeginDrawing = define_c_proc(ray,"+BeginDrawing",{}), xEndDrawing = define_c_proc(ray,"+EndDrawing",{}), xClearBackground = define_c_proc(ray,"+ClearBackground",{C_ULONG}), xDrawText = define_c_proc(ray,"+DrawText",{C_PTR,C_INT,C_INT,C_INT,Color}), xDrawCircleV = define_c_proc(ray,"+DrawCircleV",{C_FLOAT,C_FLOAT,C_FLOAT,Color}) public procedure InitWindow(atom width,atom height,sequence title) atom ptitle = allocate_string(title) c_proc(xInitWindow,{width,height,ptitle}) free(ptitle) end procedure public procedure CloseWindow() c_proc(xCloseWindow,{}) end procedure public function WindowShouldClose() return c_func(xWindowShouldClose,{}) end function public procedure SetTargetFPS(atom fps) c_proc(xSetTargetFPS,{fps}) end procedure public procedure ClearBackground(object color) c_proc(xClearBackground,{makeRGB(color)}) end procedure public procedure BeginDrawing() c_proc(xBeginDrawing,{}) end procedure public procedure EndDrawing() c_proc(xEndDrawing,{}) end procedure public procedure DrawText(sequence text,atom x,atom y,atom fontSize,sequence color) atom ptext =allocate_string(text) c_proc(xDrawText,{ptext,x,y,fontSize,makeRGB(color)}) free(ptext) end procedure public procedure DrawCircleV(Vector2 center,atom radius,sequence color) c_proc(xDrawCircleV,{center.x,center.y,radius,makeRGB(color)}) end procedure
--file BasicWin.ex include ray.e constant Width = 800 constant Height = 600 InitWindow(Width,Height,"Simple Window") SetTargetFPS(60) Vector2 pos =new() pos.x=Width/2.5 pos.y=Height/2.5 while not WindowShouldClose() do BeginDrawing() ClearBackground(BLUE) DrawCircleV(pos,100,RED) DrawText("Simple Window Program",Width /2.5, Height /2.5 ,20,YELLOW) EndDrawing() end while CloseWindow()