Anyone working on a GDI graphics module?
The big advantage using GDI would mean your app does not require OpenGL or DX.
Here's a quick example:
Ideally, it should be implemented like an existing graphics module:
The big advantage using GDI would mean your app does not require OpenGL or DX.
Here's a quick example:
Strict Extern "Win32" Function FindWindowA(class$,Text$) Function GetActiveWindow() Function GetWindowDC(hwnd%) Function ReleaseDC(hWnd%,hDC%) Function CreatePen(PenStyle%,w%,Color%) Function CreateSolidBrush(Color%) Function SelectObject(hdc%,obj%) Function DeleteObject(obj%) Function Ellipse(hdc%,x1%,y1%,x2%,y2%) Function FrameRect(hdc%,Rect:region,Brush%) Function RoundRect(hdc%,l%,t%,r%,b%,width%,height%) End Extern Const PEN_OFF%=5 , PEN_SOLID%=0 , PEN_DASH%=1 , PEN_DOT%=2 Const PEN_DASHDOT%=3 , PEN_DASHDOTDOT%=4 , PEN_INFRAME%=6 Type region Field l%, r%, t%, b% End Type Type GDIGraphics Global hWND% Global DC% Field penobject% , PenR%,PenG%,PenB% , PenWidth%=1 , PenStyle%=$1 Field solidbrushobject% , SolidR%,SolidG%,solidB% Method SetGraphics(gad:TGadget) hWND=QueryGadget(gad,QUERY_HWND) DC=GetWindowDC(hWND) End Method Method Free() ReleaseDC hWND,DC hWND=Null ; DC=Null If solidbrushobject DeleteObject solidbrushobject ; solidbrushobject=Null EndIf If penobject DeleteObject penobject ; penobject=Null EndIf End Method Method _ChangePen() If penobject DeleteObject penobject penobject=CreatePen(PenStyle%,PenWidth%,(PenR | (PenG Shl 8) | (PenB Shl 16))) SelectObject DC,penobject End Method Method SetPenColor(r%,g%,b%) PenR=r ; PenG=g ; PenB=b ; _ChangePen End Method Method SetPenWidth(w%) PenWidth=w ; _ChangePen End Method Method SetPenStyle(s%) PenStyle=s ; _ChangePen End Method Method SetFillColor(r%,g%,b%) SolidR=r ; SolidG=g ; SolidB=g If solidbrushobject DeleteObject solidbrushobject solidbrushobject=CreateSolidBrush(solidR | (solidG Shl 8) | (solidB Shl 16)) SelectObject DC,solidbrushobject End Method Method DrawOval(x%,y%,w%,h%) Ellipse DC,x,y,x+w,y+h End Method Method DrawRect(x%,y%,w%,h% , rw%=0 , rh%=0) RoundRect DC, x,y,x+w,y+h , rw,rh End Method End Type ' ######################################################################################## ' GUI AppTitle$="GDI Test" Global win:TGadget=CreateWindow(AppTitle$,200,50,512,512,Null,WINDOW_TITLEBAR) Global pan:TGadget=CreatePanel(0,0,win.ClientWidth(),win.ClientHeight(),win,PANEL_BORDER) '' DebugLog FindWindowA("BLITZMAX_WINDOW_CLASS",AppTitle$) ' INIT GDI Graphics + output Local gdi:GDIGraphics=New GDIGraphics gdi.SetGraphics win ' ############################################## ' Simple graphics example For Local n%=1 To 10 gdi.SetFillColor Rand(255) , Rand(255) , Rand(255) gdi.SetPenWidth Rand(1,8) gdi.SetPenColor Rand(255) , Rand(255) , Rand(255) gdi.DrawOval Rand(30,150),Rand(40,180),Rand(90),Rand(70) Next gdi.SetPenWidth 7 gdi.SetPenStyle PEN_DASH gdi.SetPenColor $ff,$22,$ff gdi.SetFillColor $77,$77,$77 gdi.DrawRect 300,250,120,120 gdi.Free ; gdi=Null ' ############################################## Repeat ''DebugLog currentevent.ToString() Select WaitEvent() Case EVENT_WINDOWCLOSE Exit End Select Forever End
Ideally, it should be implemented like an existing graphics module:
SetGraphicsDriver GDIGraphicsDriver() ' send output to this gadget SetGraphics mywindowpanelI'm not sure how the redrawing or retaining of the graphics would work though. In the example above, moving a window in front of the test window erases the graphics.