|
Aloha!


If you would care to make a donation ...
Email Me About CoreGraphics Module
I would be remiss if I did not thank Charles Yeomans for his advice and more importantly, his excellent book on how to use declares in REALbasic, iDeclare. iDeclare Web Site
And of course thank you to the REALbasic NUG mailing list where I lurk and learn - thanks nuggers. :-)
|
|
|
These are some REALbasic projects that I have been working on for awhile. Like the OpenGL drawing environment, I have been interested in Apple's latest eye candy, the Quartz and CoreGraphics frameworks. It has been quite a steep learning curve for me to get this to work with REALbasic, as there are many issues that need to be dealt with. Least of not is my idiocy. :-)
All of these versions are what I would refer to as beta. It mostly works for me, but a few things do need to be ironed out. I'd appreciate it if you would try it and tell me what you think.
If you are not familiar with what CoreGraphics (CG) does, it allows you more control of your drawing environment. You can draw lines, rectangles, etc. just like you can now in REALbasic. But, with CG, you can add an alpha feature to your line, a transparency, as one example. I think this alone makes this module worth trying out. In addition I have four different dotted line definitions you can use, pretty nifty! See Apple for more details on Quartz 2D and CG, Apple Site
[Update: July 4, 2008]
I had a user request to add a core graphic image class to this project, so here it is. Users of these classes should upgrade to this latest version as I've made a few changes and bug fixes to this version. As alway, please let me know if something does not work for you.
Download Rb Project File Here
See the demo project for usage of the new Image Class. Peter Zegelin of Fractured Software (see below) has unfortunately (at least for me) moved on with his AlphaDraw project, moving it to a C++, Cocoa front end.
[Update: July 16, 2007]
I've been fortunate enough to be refining and testing my classes with the excellent help of Peter Zegelin. Peter has just released a new Rb made application called AlphaDraw, Fractured Software - AlphaDraw. AlphaDraw uses the CG Classes featured here, how cool is that! It has been a great experience having Peter sort out bugs and request features of the CGClasses. Mahalo (thank you) Peter. And if you're in to MIDI on your Mac, be sure to check out Peter's Rondo application, Fractured Software - Rondo. Tell him MauiTom send you!
The latest version of my CGClasses and the one Peter used for his latest version can be downloaded at the link below. The example project has several windows that demonstrate how to use the CG Classes.
Download Rb Project Files
Developers should use this latest version. The March 23rd release can cause Console files to grow very large. This version fixes those bugs. To summarize the classes at this point:
* Naming space issues have been addressed. All of the classes and support structures that I designed now have the 'TJC_' preface. This eliminates name collisions with the Rb frameworks.
* This project comes with a 'minimum' of module function calls to keep the file sizes as small as possible. This keeps compile calls to a minimum too.
* TJC_CGObject - base object for the classes
* TJC_CGContextClass - a debugging class that you will most likely not use.
* TJC_CGLineClass - draws CG lines.
* TJC_CGPointClass - if you need to draw a 'point' or 'dot' using CG.
* TJC_CGRectangleClass - draws CG rectangles. Fill and Stroke attributes supported.
* TJC_CGPolygonClass - use like Rb class to draw a CG rectangle, except you pass a zero based array. Fill and Stroke attributes supported along with the ability to draw a polygon that is a 'open' path.
* TJC_CGTextClass - draws 'Mac-Roman' encoded text using CG. Shadows, rotation, character spacing and scaling are supported. This class is for basic text display. Quartz does not perform text layout, only text rendering.
* TJC_CGBezierCubicClass - beta - basic cubic defined Bezier CG class.
* TJC_CGBezierQuadraticClass - beta - basic quadratic defined Bezier CG class.
CG Classes
- March 23, 2007. I've decided to take a little different approach to my CoreGraphics usage in Rb, a new design approach. Instead of extending the Graphics class as the previous versions listed below, I am adding CG Classes. This release includes CGLine, CGRectangle, CGText and CGImage. In the Paint() event of a Window or Canvas, you instantiate each object then *set* its properties. For example, this snippet of code creates a text object.
Dim myText As CGText
myText = New CGText(self, 100,50, self.Width, self.Height)
myText.SetText "REALbasic 2K7"
myText.SetFontName "Impact"
myText.SetFontSize self.Height / 10
myText.SetCharacterSpacing 4
myText.SetDrawingMode "TextFillStroke"
myText.SetFillColor &c008000
myText.SetFillAlpha 0.50
myText.SetStrokeColor &c004080
myText.SetStrokeAlpha 1.0
myText.SetRotation 45
myText.SetShadowBlur 0.50
myText.SetShadowColor &c008000
myText.SetShadowOffset 12, -4
myText.Draw()
Cool, huh?! Most of that code you should be able to figure out. You create a new CGObject by telling it which graphics context owns it and where to place it. after setting the parameters you want, you *Draw()* it.
Let me tell you that one big feature that I have not figured out in all of these CoreGraphic projects, is how to get it to *print*. The native routines that allow you to print in Rb do not work - blah. Then again, maybe you have a project that this would not matter. In that case, this is a feature! Hopefully I can fix this.
One other thing is that I am still using 10.3 on a G4. I plan on upgrading soon to an Intel Mac, but what this means is that some of the groovy features that were added in 10.4 in the CG library are mostly not included here. For instance, simple mask support of CG images was added in 10.4. This release does not support masks. I plan on adding the 10.4 support as soon as I am able to test it on my machine.
A sample project is included with this download. The modules and classes are free to use but they are encrypted. You use this at your own risk. Here is a screen shot of the sample project window.
Rotated objects with colored shadows! As usual, I'd really like to hear from you if this may help you with a project. And, as usual, I don't have any documents but do plan on adding them (if there is a demand). Please feel free to Email me with your questions.
Advanced Module Updated
Advanced Usage Version Download
- Aug. 22, 2006. Added CGDrawQuadCurve. This allows you to draw a simple Bezier curve with one control point. Also added CGDrawRoundRect. Next up will be adding support to draw CG images.
Advanced Module Released
- Aug. 11, 2006. I have added a more advanced version module and it is working well for me. Basically, if you just need the basic routines that come preprogrammed in the Basic Usage module , use it, simple, easy. If you want to be able to control a few more parameters in your CG environment, like adding shadows, use this new Advanced Usage module. This module, like the previous one, comes with a demo project that shows how to call the routines. Here is an example,
g.CGSetFillColor rgb(255,0,0)
g.CGSetFillAlpha 0.80
g.CGSetShadowOffset 4, -4
g.CGSetShadowBlur 0.80
g.CGFillOval 50,100,50,50
This shows how you can now set the CG drawing environment to your own needs. That listing fills in an oval shape at 80% transparency and draws a shadow of it. Nifty!
This download now includes an html document file that explains the routines!
Rectangles And Circles Added
*NOTE _ THis version is no longer available ...*
- Aug. 5, 2006. Added these basic drawing capabilities. This is as far as I'm going to go with this initial exploration of the implementation of CG and Rb. I'm going to start a new module that will not follow the calling conventions of the existing Rb API, which is what I've tried to do with this existing project. CG can do so much more so I need to reconsider my design considerations. So, my next version will (I hope!) allow you to "set" certain parameters before you draw, like SetShadow, SetDashPattern, etc. It will mean learning some new API's for a user, but it should be worth the time to get the eye candy for your projects.
Updated Version - No Plugin Problem!
- Aug. 3, 2006. I can now run the TypeLib plugin with no errors. Please let me know if you see any problems like this again. I added the ability to draw rectangles. You can specify a dotted line for these rectangles also, same dotted pattern as in draw line calls. For now there is no control over how the corners are drawn, I will add this along with fill rectangle calls in the next release. Drawing circles will follow that.
Plugin Follow up
- Aug. 1, 2006. It looks like this plugin creates a class called "Rect" that is causing the problem. I've spent a few hours seeing if I can work around this with no luck. For now, this module will not work with this plugin - sorry.
Plugin Problem
- Aug. 1, 2006. It looks like this error message is from a problem with a plugin. I don't use plugin's. Possible culprit is the TypeLib plugin from einhugur.com. I've download the plugin to remove whatever it is that collides with this plugin. Thank you to Japp at isticky.net and Ben Blake for giving me some clues on this.
Error Message Reported
- July 31, 2006. This is an error message some users are reporting. I have no clue how or what would generate this. Asking on the NUG for some help on this.

Release July 31, 2006
- Initial Beta release - need people to test it and break it. It draws lines! There are a lot of other calls in the module that are not ready yet, so please just stay to the lines for now. The download comes with a demo, check out the calls in the demo. To use the module in your own project, import it. You make the CG calls using the graphics parameter in a Paint() Event.
Known Issues
- Large rounded end caps are not accounted for and will sometimes cause the lines to be drawn outside of the graphics area.
- The lines drawn do not show up if you try and print the window. I sure could use some help here as to why.
- I'm pretty sure you need to make sure the window you are drawing to is set to "Composite".
Some Details
- This is OS X software. It is written in Rb2006 release 3. It is for free, as is, use it at your own risk.
- The routines should work on any OS X version. I plan on adding the calls that are specific to 10.4 (Tiger), but since I still 10.3 (Panther), this will have to wait until I upgrade.
- The module, while free, is encrypted. If you would like to see something added, PLEASE shoot me off an email with your comment or request. There is a call you can make from the module that will email me pain free, simply call,
ThomasCoreGraphics.Email
- This module EXTENDS the REALbasic graphics class. To me, this is a more reasonable and friendly way to add this funtionality versus adding a lot of new classes to learn. I am really trying to keep the calls in this module similar to REALbasic. For example, here is a call to draw a line in Rb and in this module.
g.DrawLine 0, 0, 100, 100
g.DrawLine_CG 0, 0, 100, 100
The CoreGraphics (CG) designation indicates a call to this module. This would draw a line just like in Rb with no alpha or transparency. If you want to add an alpha fill of the line to say 50%, you would make the call like this.
g.DrawLine_CG 0, 0, 100, 100, 0.50
- I know it's lame, but I only have minimal documentation at the moment. I'm trying, but it's a royal pain and I prefer to spend my time coding (bet you never heard that before!). Again, please feel free to email me and I'll try to help you.
|