Guessing Game

by Erick Tejkowski

Did you know that your computer can read minds? This week we’ll witness its extraordinary mind-reading powers by creating a simple REALbasic project. See if you can figure out how it works before looking at the code!

04-25-03_img1.jpg

Downloads

Because the code for this demo is drop-dead simple, there isn’t really any reason to cover the process of putting an interface together. Check one of the previous tutorials if you are a complete REALbasic newbie. The fact is, this project doesn’t have any tricky code at all. The trick lies in the mathematical content of the application, not the code itself.

Download the Guessing Game project.

Originally published by ResExcellence Reprinted with permission

Current Notes 45

Software

REALbasic 2008 Release 4.1 – Another quick patch release for REALbasic. It fixed a handful of issues, described in the release notes

Community

REALbasic Fan page on Facebook – If you use Facebook, be sure to add yourself as a fan of REALbasic!

Image Spinner

by Erick Tejkowski

One of the most frequently asked questions among REALbasic lists is “How do I rotate an image?” This project will show you how to quickly and easily rotate an image in realtime. The REALbasic Group2D class simplifies matters significantly for us. By dragging a few items to your interface and adding a bit of code, you’ll be spinning in no time.

Build the Interface

Launch REALbasic and add a Canvas, a PushButton, and a Slider control to the Window1 interface. Set the maximum value of the slider to 6283. Since one complete rotation around a circle is approximately 6.283 radians, we’ll use the larger value of 6283 to insure fine resolution upon rotation. Next, click on the slider to select it and uncheck its Enabled property in the Properties window. Then, add an image file to your project. I snagged a photo of Michael Coyle, ResEx’ own top dog. His image accompanies the source code download at the end of this tutorial. The final interface looks like this:

4-11-03_img1.jpg

Add the Code

Double-click PushButton1 and add the following code to its Action event.

  Dim px as PixmapShape
  Dim p as Picture
 
  px=New PixmapShape(coyle)
  p=New Picture(coyle.width,coyle.height,32)
  d=New Group2D
  d.append(px)
  Canvas1.Backdrop=p
  Canvas1.backdrop.Objects=d
  canvas1.Refresh
  slider1.enabled = True

Next, add this code to the Paint event of Canvas1.

  g.clearRect 0,0,me.width,me.height
  g.drawobject d,47,60

With the Window1 code editor opened, create a new property of that window, by choosing Edit-New Property. Name the property like this:

d as Group2D
4-11-03_img2.jpg

Conclusion

Choose Debug-Run to see your work. By drawing an image using a Group2D object, you can a number of important image operations. The speed isn’t as fast as an RGBSurface, but for many tasks its perfectly suitable.

Download the ImageSpinner project.

Originally published by ResExcellence Reprinted with permission

PNG Utilities Replacements

In a prior post, I noted that PNG Utilities has been deprecated. It still works fine in REALbasic 2008 Release 4, but if you’re looking to replace it with something that is supported you have two (non-free) option: Monkeybread Plugins or Einhugur GraphicsFormats plugin

Switching to either of this is quite easy, but I thought it would be worth capturing how to do it in a post here.

This is a sample code for loading a toolbar icon using PNG Utilities:

Me.SaveToolButton.Icon = PNGu.GetPictureWithMask(save32)

This code is in the Open event of the toolbar.

MonkeyBread PNG Plugin

The entire MonkeyBread plugin suite costs about $320 and is worth every penny. If that’s too rich for you, then for about $30 you can just purchase the PNG plugin part which is what is used to replace PNG Utilities.

The code using the MonkeyBread PNG plugin looks like this:

Me.SaveToolButton.Icon = PNGStringToPictureMBS(save32, 0)

As you can see it is extremely similar. In addition, the MonkeyBread PNG plugin is about the same size (1.3MB) as the PNG Utilities plugin.

Einhugur GraphicsFormats

The Einhugur plugin suite contains several new controls for REALbasic in addition to the GraphicsFormats plugin which works with PNG and JPEG images. The entire suite costs $200 and it is also worth every penny.

The code using this plugin:

Dim PNGImp As New PngImporter
Me.SaveToolButton.Icon = PNGImp.OpenFromString(save32)

The GraphicsFormats plugin is bigger than PNG Utilities (5.7MB) so your executable will grow a bit.

Summary

As you can see, if you already have these two plugin suites, switching to them is quite easy. If you don’t already have them, then you probably ought to pick them up in general because they add so much power to REALbasic.

However, in the short term, I see no problem sticking with PNG Utilities.

Current Notes 44

Software

Build Mate – A tool to help you automate your REALbasic build

Formatted Text Control – Add powerful word processor capabilities to your apps

GraffitiSuite – Many updates to this impressive collection of controls

Information

Barcode in REALbasic – Windows-only

SHA-1 Class – An implementation of SHA-1 encryption

Partial String Splitting – Based on some Python functions

Run Pauses Might be Your Friend – How to use this feature of REALbasic to put files alongside the executable

Community

How we use REALbasic – Aaron describes how REAL Software uses REALbasic

Managing SQLite Databases – Bob writes about tools he uses to work with SQLite

REALbasic Developer Magazine Print-on-demand – I ordered the last two digital issues from here; they look fabulous!

Coding Standards – Philip shares his best practices