Tuesday, May 13, 2014

Playing with Additional Window Features

This tutorial is the first practice session for the topic of CPWindows, which is discussed in the overview found here: CPWindow, the start of all View Hierarchies.

Project Files

For this project, use the files you created from the Multiple Windows tutorial.  Copy them to a new directory.

Playing with Windows

I am a big proponent of play.  By making small changes to code and experimenting, we learn what is available to us in the Frameworks created by others.  In this tutorial, I will show you some of the CPWindow methods that are in the documentation, and I will encourage you to just play with them.

Alpha Values and Transparancy

CPWindows have a function called setAlphaValue.  Try setting this value to ranges between 0 and 1 on any of our windows.  I have added the following lines of code to the original AppController.j file:
    [theWindow setAlphaValue:0.5];
    [theWindow2 setAlphaValue:0.2];
This resulted in the following effect:


 Background Color [Not working as expected]

CPWindows have a function called setBackgroundColor:.  I have added the following lines of code to the original AppController.j file:
    [theWindow setBackgroundColor:[CPColor blueColor]];
    [theWindow2 setBackgroundColor:[CPColor redColor]];
This produced unexpected results.  One would expect this to change the color of the window's background.  Instead, no effect is seen:

Setting Minimum and Maximum Sizes

CPWindows have setMinSize: and setMaxSize: functions.  They take CPSize objects as the argument.  I added the following lines of code to my AppController.j file:
    [theWindow setMinSize:CPSizeMake(100,100)];
    [theWindow2 setMinSize:CPSizeMake(150,150)];
As a result, I am unable to resize my windows to dimensions smaller than these indicated sizes as shown here.  We can also control the resizing of the window with a maximum size limit using the setMaxSize: method.

Removing the Window's Shadow - Making a Flat Window

CPWindows allows one to choose whether the shadow exists or not with setHasShadow:(Bool).  Remember, Cappuccino does not use true and false like most languages; this language uses YES and NO.  I added the following line of code to my AppController.j file:
    [theWindow setHasShadow:NO];
This produced the following:

Autoresizing

Cappuccino Project does a really good job explaining the resizing masks, so I will defer to their article for information about auto-resizing:  Cappuccino Project's Tutorial on Autoresizing

Other Functions

There are many other methods which we may address in the future.  By all means, read through the CPWindow.j file and play with the methods that you find there.  Playing is the only way to truly learn how to work with these objects.




No comments:

Post a Comment