PaintPanel - native gadget painting windows + osx

BlitzMax Forums/MaxGUI Module/PaintPanel - native gadget painting windows + osx

skn3(Posted 2012) [#1]
Ok I have just finished wrapping up my paintpanel module for windows and mac.

https://bitbucket.org/skn3/paintpanel

The repo includes the module, example and is pre compiled for windows and mac. Painting is easy, just hook into EVENT_GADGETPAINT and start using the paint methods belonging to the Skn3PaintPanel.

All the methods are documented but it should be pretty self-explanatory.

If you find any bugs then please post here or commit to the repo. If anyone wants to port this to linux then again please do so!

Screenshot showing mac and windows example running:


Enjoy!

Last edited 2012

Last edited 2012


skn3(Posted 2012) [#2]
Created my first gadget using this lib. There is no much point in me sharing it as it uses lots of base gadget stuff I have but at least the demo can be played with :)

It is a color button that reacts to mouse events and only uses a single panel that is painted.

http://www.skn3.com/junk/modules/paintpanel/colorbutton.zip




jsp(Posted 2012) [#3]
Thanks for sharing, will check it out.


skn3(Posted 2012) [#4]
Updated now and added PaintTextDimensions() which will return dimensions for the given text. The existing method PaintText() will now also return the dimensions after drawing. This can be useful for drawing text elements one after the other.


JoshK(Posted 2012) [#5]
Very nice.


macklebee(Posted 2012) [#6]
where can i get the modules for skn3.callback and sk3.funcs to try this?


GaryV(Posted 2012) [#7]
where can i get the modules for skn3.callback and sk3.funcs to try this?


The link is in the first post.


skn3(Posted 2012) [#8]
My bad I have committed with those bits commented out and the maxgui bits uncommented. You shouldn't need them now. If anyone knows a way to conditionally commit portions of code to git then let me know.

Last edited 2012


macklebee(Posted 2012) [#9]
thanks skn3... will have a go at it now...


Captain Wicker (crazy hillbilly)(Posted 2012) [#10]
Hi skn3.
I have a small problem.
Building example1_maxgui
Compiling:example1_maxgui.bmx
Linking:example1_maxgui
Undefined symbols for architecture i386:
  "_Skn3PaintPanelPaintTextDimensions", referenced from:
      __skn3_paintpanel_Skn3PaintPanel_PaintTextDimensions in paintpanel.release.macos.x86.a(paintpanel.bmx.release.macos.x86.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Build Error: Failed to link /Applications/BlitzMax/mod/skn3.mod/paintpanel.mod/example1_maxgui.app/Contents/MacOS/example1_maxgui
Process complete



skn3(Posted 2012) [#11]
Hey there, have you rebuilt the modules?


Captain Wicker (crazy hillbilly)(Posted 2012) [#12]
Yes. I have rebuilt all modules and rebuilt documentation, but it will not work.
OSX Mountain Lion 10.8.2
Intel Core i7 @2.8GHz
AMD Radeon 6770M 512MB
8GB RAM (DDR3) @1333MHz



skn3(Posted 2012) [#13]
Ok will take a look tomorrow when I get to work. Thanks for poi ting it out :)


skn3(Posted 2012) [#14]
Really sorry about not getting to this, I am incredibly busy at the moment but I will get around to it.


rs22(Posted 2012) [#15]
Thank you for this! Very useful!


JoshK(Posted 2013) [#16]
I get the same problem, so I commented out all mentions of that function.

This code saved my ass. We were having some redraw errors using OpenGL to render a custom tree view. I replaced the OpenGL calls with this code, and it's perfectly stable and reliable.


skn3(Posted 2013) [#17]
Apologies for the long delay! There was simply a missing glue function call in the objc code.

The repo has been updated. Just make sure you move over to the bit bucket repo. https://bitbucket.org/skn3/paintpanel It is linked at the top of the page.

I didn't bother testing on mac as it was switched off, but it was a really simple fix so should be fine. Let me know if it fails and I'll stop being lazy.. haha.


shinkiro1(Posted 2013) [#18]
Hey, maybe I am just not getting this, but what is the difference between this and a canvas?
Has it got something to do with performance or flickering?


skn3(Posted 2013) [#19]
Creating a canvas is actually creating a DirectX or OpenGL instance. This is quite memory intensive, especially if you are using a canvas per custom gadget. There are also issues with certain hardware when you try and draw the same image on multiple canvas. The final issues is the inability to draw antialiased text on a canvas.

Paint panel uses the os native drawing commands so performance should be increased and you will have a lower hardware requirement for your app.


shinkiro1(Posted 2013) [#20]
That totally makes sense :)


Derron(Posted 2013) [#21]
Difference is also:
canvas: Win,Mac,Linux + normal BlitzMax instruction set
skn3's element: Win,Mac (at the moment) + custom instruction set


bye
Ron.


Brucey(Posted 2013) [#22]
Yeah, what you want is a panel-based Max2D, rather than a completely new set of commands.

Then you simply tell Max2D, "This is your current graphics driver", and you can use the same commands (as you do with OpenGL/DX) to paint onto it.


Derron(Posted 2013) [#23]
@Brucey - yes.

But in that case this would mean, that there is a kind of "graphicsdriver" which handles the native draw commands of each platform and therefor is able to translate "maxcode" to "native".


At the moment you are not able to use the maxgui canvas with additional windows: the windows are not redrawn until forced (move out of the desktop and in...) and events like gadget_repaint or "RedrawGadget"-commands are not working here with FLTK/linux.

So that native gadget window is nice - but "useless" for me as it only supports windows/mac.
Means: if you need custom looking widgets, or graphical representations (diagrams, curves,...) you are better looking for wxmax (but this will take you into the combat with symlinking 32bit libs on 64bit etc.).

bye
Ron


skn3(Posted 2013) [#24]
Yeah, what you want is a panel-based Max2D, rather than a completely new set of commands.


That would be a nice feature, is that one of your secret projects?

Somone got near making a GDI driver a while back http://www.blitzbasic.com/Community/posts.php?topic=56055 but it didn't appear to get finished.

There is one big negative though, if you wrote a Max2dOSDriver you would then not be able to have a max2d gl/dx canvas alongside native gadget drawing.

The purpose of my module was not to replace the canvas but instead to add extra functionality, hence the extra command set. If I had more time I would have started adding in Linux support and some of the more advanced drawing operations. But alas I don't have spare time.

If anyone wanted to add linux glue for the commands then Id be happy to add them to the repo.


JoshK(Posted 2015) [#25]
Any Linux support for this? I could really use it.


JoshK(Posted 2015) [#26]
paintpanel.h needs a change to compile. Add @public at the top of this class:
#import <maxgui.mod/cocoamaxgui.mod/cocoa.macos.m>
#import <maxgui.mod/maxgui.mod/maxgui.h>
#import <pub.mod/macos.mod/macos.h>

@interface Skn3PaintPanelViewContent:PanelViewContent{
@public
	BOOL painting;
	PanelView *panel;
	NSBezierPath *path;
	NSColor *backgroundColor;
	NSColor *color1;
	NSColor *color2;
	NSGradient *gradient;
	NSFont *font;
}
-(id)initWithFrame:(NSRect)rect;
-(void)dealloc;
-(NSColor*)colorFromIntsRed:(int)red green:(int)green blue:(int)blue;
-(void)drawRect:(NSRect)rect;
-(void)setPaintBackground:(int)r g:(int)g b:(int)b;
-(void)setPaintColor:(int)r1 g1:(int)g1 b1:(int)b1 r2:(int)r2 g2:(int)g2 b2:(int)b2;
-(void)setPaintFont:(NSFont*)newFont style:(int)Style;
-(void)paintLine:(int)x1 y1:(int)y1 x2:(int)x2 y2:(int)y2 width:(int)width;
-(void)paintGradient:(int)x y:(int)y width:(int)width height:(int)height vertical:(int)vertical;
-(void)paintRect:(int)x y:(int)y width:(int)width height:(int)height;
-(void)paintOval:(int)x y:(int)y width:(int)width height:(int)height;
-(BBArray *)paintText:(NSString*)text x:(int)x y:(int)y width:(int)width height:(int)height wrap:(int)wrap hAlign:(int)hAlign vAlign:(int)vAlign;
-(BBArray *)paintTextDimensions:(NSString*)text x:(int)x y:(int)y width:(int)width height:(int)height wrap:(int)wrap hAlign:(int)hAlign vAlign:(int)vAlign;
-(void)paintBitmap:(NSImage*)image x:(int)x y:(int)y;
-(void)paintSubBitmap:(NSImage*)image x:(int)x y:(int)y width:(int)width height:(int)height sourceX:(int)sourceX sourceY:(int)sourceY sourceWidth:(int)sourceWidth sourceHeight:(int)sourceHeight;
@end