[Community Project] - Win32 GDI graphics
BlitzMax Forums/BlitzMax Programming/[Community Project] - Win32 GDI graphics
| ||
** Download - GDI Graphics _________________________________________________ As a possible community project what do you guys think with regards to creating a Win32 GDI graphics driver? Here are my thoughts on the pros and cons: + No need to rely on OpenGL or DX + Uses internal API graphics (smaller executables) + Ideal for simple window graphics (boxes, lines, filled ares) + Suitable for applications such as paint programs + Maxiumum compatibility - Not as fast (or fully-featured?) as OpenGL or DX - Windows only Anyhow, here's something I've been playing with .. Ideally, I would like to see something which mimics all of the Max2D commands but relys solely on API calls to avoid the need for OpenGL, DX. Example: SetGraphicsDriver GDIGraphicsDriver() SetGraphics mypanel ' send graphics output to panel gadget SetPenColor 100,200,200 SetPenWidth 4 SetFillColor 50,60,70 DrawRect 10,20,40,50 At the moment, I have a GDI type with the following methods: gdi1:GDI=GDI.CreateGDIPanel(x,y,w,h,group:TGadget) methods: .Free - free the GDI panel and resources Rendering -------------------------- .SetRenderMethod .SetBuffer .Cls .Flip Color Handling -------------------------- .SetPenColor .SetPenWidth .SetPenStyle .SetFillColor .SetFillPattern 2D Drawing -------------------------- .Plot .Point() .DrawLine .DrawOval .DrawRect .InvertArea .ScrollArea .FloodFill Text Handling -------------------------- .DrawText .SetFont .SetTextFormat Bitmap/Icon handling -------------------------- .LoadBitmap .FreeBitmap .DrawBitmap .DrawScaledBitmap .LoadIcon .DrawIcon .FreeIcon Also, the following events are returned to the Max event system when the mouse is over a GDI gadget: Event Source Data EventX() EventY() EVENT_MOUSEMOVE | gdi panel | n/a | mouseXpos | mouseYpos EVENT_MOUSEUP | gdi panel | button(1/2/3) | mouseXpos | mouseYpos EVENT_MOUSEDOWN | gdi panel | button(1/2/3) | mouseXpos | mouseYpos Handy Links: API Guide Microsoft MSDN Win32 API reference - 5.43MB I'll try and update the source code with any mods/additions you come up with ... |
| ||
TODO: [1] - Fix cursor stuck at 'busy' state whilst over GDI panel [2] - Change the way images are created [3] - Grabbing/pasting areas of the gdi [4] - Lot's of other drawing methods added (XOR, AND, COPY, DIFF - via CombineRgn API) [5] - Gradient fills (GradientFill API) [6] - Turn the whole system into a proper graphics driver which can be used via SetGraphicsDriver and SetGraphics. |
| ||
I found that *should* be something like this:Extern "Win32" 'Public Const WM_SETREDRAW = &HB Function SendMessage(HWND%,WM_SETREDRAW:Int,par1:Int,par2:Long) ... Method Refresh() SendMessage(hWND,WM_SETREDRAW,0,0)'<--- ???? End Method ... Case EVENT_WINDOWMOVE gdi.refresh of course it don't work...I obtain an error message on SendMessage()..."Compile Error: Too Many Function Parameter" I suspect that somewhere (where?) in the bmax mods there is a SendMessage Functions... |
| ||
Thanks degac. I had a play with SendMessageA and the WM_SETREDRAW flag but I can't get it to work as desired. Locking the redrawing of the window after drawing the graphics means the panels border and contained graphics are not drawn after another window passed over the top. For the time being I'm calling gdi.DrawGraphics DrawTest which executes the DrawTest() function when an event occurs such as EVENT_APPRESUME , EVENT_WINDOWACTIVATE, EVENT_WINDOWMOVE It's by no means perfect though. The InvertArea screws up for starters. Plus, once the window is inactive there is no notification to re-draw the graphics. |
| ||
Perhaps you could have a look at this http://www.blitzbasic.com/Community/posts.php?topic=53212 Just something I was playing around with a while ago. |
| ||
this one i've missed! thanks |
| ||
Nice work. What about the SDL community project, is that also useful? |
| ||
Updated with WM_PAINT method. Thanks Skn3[ac]! I'm not sure if its right but there are no flames coming out of the PC's tower as of yet. Although the graphics are now permanently displayed a bug still needs attention: 2) The cursor remains in a 'busy' state until I move OFF the panel gadget. Not sure whats going on there. Currently, graphics commands are sent to a bitmap buffer device context which is then BitBlt'd into the gadgets device context via the Flip and WM_PAINT calls. Rob, I've not really looked at SDL but I really want to keep this as independent as possible and therefore not rely on external API's or libs. |
| ||
Updated with mouse events when over a panel. See 1st post. |
| ||
Gulp! Nice one - very good job! |
| ||
Updated: * Loads and draws Bitmaps and icons * Text handling (still need to find out how to set a font) |
| ||
Don't know if this is of any use: |
| ||
Thanks Perturbatio. Font-loading works. (Updated above) .. |
| ||
This is looking pretty good, one day I'll have the time to download it and test it :) |
| ||
This doesnt work for someone who hasn't purchased the BMax GUI module, correct? |
| ||
Sorry to bump this. Is there any way to load and draw an image with an alpha channel? Even if just 1 bit alpha, that would be fine. I've tried loading and drawing both bitmaps and icons ( because I read that they were easier to get working with alpha channels ) but I can't get it working in either case. |
| ||
Why wasn't this continued? It looks fairly promising. Or was there just nothing more to be finished? |
| ||
Looking at the thread, I'd say there wasn't a lot of interest and what Jim has already put together is really very good. You can do an awful lot with it as it is. I've read up on alpha in bitmaps and it looks as though there are two ways to do it, one of which is rarely supported and the other way is really rather complicated and unwieldy. So I think I'm just gonna draw square images and be done with it. |
| ||
I did do a fair bit of work on this project mainly for my self. I Re-wrote the command set to a more friendly BlitzMax-style approach. Currently I have these commands/functions: Since I am working abroad at the moment I cannot upload the GDI stuff to my UK site. Any good free sites worth registering with? |
| ||
not as far as i know of, but if possible id like to get my hands on that newer version you made. Email: Removed |
| ||
Tim .. Check your email. |
| ||
Thank you. |
| ||
Jim very kindly sent me a copy of the new version and said I could post a link in case anyone else wants to take a look. http://www.xmystik.co.uk/gdi-new.zip Thanks Jim :) Steve. |
| ||
To use GDI drawing (like FloodFill) you can only draw on a GDIPanel, correct? It would be cool to be able to floodfill images onto other images to create a sort of texture effect for 2d games, menus, etc. |