[Community Project] - Win32 GDI graphics

BlitzMax Forums/BlitzMax Programming/[Community Project] - Win32 GDI graphics

EOF(Posted 2006) [#1]
** 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 ...


EOF(Posted 2006) [#2]
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.


degac(Posted 2006) [#3]
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...


EOF(Posted 2006) [#4]
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.


skn3(Posted 2006) [#5]
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.


degac(Posted 2006) [#6]
this one i've missed! thanks


Robert Cummings(Posted 2006) [#7]
Nice work. What about the SDL community project, is that also useful?


EOF(Posted 2006) [#8]
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.


EOF(Posted 2006) [#9]
Updated with mouse events when over a panel. See 1st post.


degac(Posted 2006) [#10]
Gulp!
Nice one - very good job!


EOF(Posted 2006) [#11]
Updated:

* Loads and draws Bitmaps and icons
* Text handling (still need to find out how to set a font)


Perturbatio(Posted 2006) [#12]
Don't know if this is of any use:





EOF(Posted 2006) [#13]
Thanks Perturbatio. Font-loading works. (Updated above) ..




Perturbatio(Posted 2006) [#14]
This is looking pretty good, one day I'll have the time to download it and test it :)


GW(Posted 2006) [#15]
This doesnt work for someone who hasn't purchased the BMax GUI module, correct?


Gabriel(Posted 2006) [#16]
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.


plash(Posted 2006) [#17]
Why wasn't this continued? It looks fairly promising.

Or was there just nothing more to be finished?


Gabriel(Posted 2006) [#18]
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.


EOF(Posted 2006) [#19]
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?


plash(Posted 2006) [#20]
not as far as i know of, but if possible id like to get my hands on that newer version you made.

Email: Removed


EOF(Posted 2006) [#21]
Tim .. Check your email.


plash(Posted 2006) [#22]
Thank you.


Mystik(Posted 2006) [#23]
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.


plash(Posted 2006) [#24]
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.