GRADUATION TINTS IN CREATIVE BASIC
 - by BPak

A simple method of putting a Graduation Tint on a Window using Creative Basic commands



To make the Graduation Tint - like you see in the Installation Package Window when installing using the Installshield Program - the Creative Basic RECT function and the RGB color function are all that are needed!
 
 
STEP 1

Define the Window

DEF Main:WINDOW
SETID "WM_EXITSIZEMOVE",0x232

WINDOW Main,150,150,400,350,@CAPTION|@SYSMENU|@SIZE,0,"Graduation Tint",MainWindow
MENU Main,"T,&File,0,0","I,&Quit,0,1"

STEP 2

Start Window and create Tint at start up of program.

run = 1
' initialise the tint on start up
MakeBackground

waituntil run=0
closewindow Main
END

STEP 3

Code the Main Window Message Event Handler

WM_EXITSIZEMOVE
is used to re-paint the window when a window is re-sized by user by calling the SUB MakeBackground.

Window is centered in the @IDCREATE Message

SUB MainWindow
SELECT @CLASS
    CASE @IDCLOSEWINDOW
          run = 0
    CASE @IDMENUPICK
         SELECT@MENUNUM
             CASE
                    run = 0
         ENDSELECT
    ' check for an > exit size move < from Window Message
    CASE @WM_EXITSIZEMOVE 
         ' if finished changing the Window size then repaint Tint
         MakeBackground
    CASE @IDCREATE
         CENTERWINDOW Main
ENDSELECT
RETURN
STEP 4  (a)

Code the Sub MakeBackground

Part (a) of the Sub is where the Graduation Tint is made and applied to the Client Area of the Window.

Actually it is applied to a RECT that covers the Client Area of the Window.

Comments explaining each process are made in GREEN print throughout the code.

Basically the Screen Height is divided into 255 RECTangles (dif = height / 255) which are drawn one above the other - each one having a different color - so as to give the Graduation Effect.
 
 
 
 

 

SUB MakeBackground
     DEF left, top, width, height:INT
     DEF dif:FLOAT
     DEF newtop, newheight, dz, fx, gx, bt:INT

     ' get Client Area to place Tint into
     GETCLIENTSIZE(Main, left, top, width, height)
     ' obtain the amount of change - we have 255 shades in a color
     ' divide the HEIGHT by the color shades (255) to obtain the number of
     ' different RECT we will need to paint
     dif = height / 255
     ' work through all tint colors and RECTs - one by one in the for loop
     FOR dz = 0 to 255
          ' work TOP for each Tint and RECT
          newtop = dz * dif
          ' work HEIGHT for each Tint and RECT
          newheight = (dz + 1) * dif
          ' Work Color for RGB change for each Tint and RECT
          ' Below three different combination variables are made
          ' use as you wish to cause different Graduation combinations
          bt = 255 - dz : fx = 0 + dz : gx = 0 + dz
          ' Set the Rect to the desired Tint - ...
          RECT Main, left, newtop, width, newheight, RGB(0,bt,bt),RGB(0,bt,bt) 
          ' Any of the following lines may be uncommented to be tested
          ' RECT Main, left, newtop, width, newheight, RGB(gx,fx,bt),RGB(gx,fx,bt) 
          ' RECT Main, left, newtop, width, newheight, RGB(fx,0,bt),RGB(fx,0,bt) 
          ' RECT Main, left, newtop, width, newheight, RGB(fx,bt,gx),RGB(fx,bt,gx) 
          ' RECT Main, left, newtop, width, newheight, RGB(bt,0,0),RGB(bt,0,0) 
          ' RECT Main, left, newtop, width, newheight, RGB(0,bt,0),RGB(0,bt,0) 
          ' RECT Main, left, newtop, width, newheight, RGB(bt,bt,0),RGB(bt,bt,0) 
          ' Make other combinations that you wish to try
     NEXT dz
     ' The Graduation TINT is now finished
. . . the rest of this SUB follows below . . .

STEP 4  (b)

Continuing with the Sub, Text is added on top of the  Graduation Tinted RECT.

First two RECT are Drawn to give a Drop Shadow Effect to the Box where the type will be placed.

Next the Text is Printed too the above RECT as Black Print, which will be used to give Shadow to the Type.

Finally the MOVE statement offsets the type to PRINT the text in RED above the Black Text.

 Continued from the SUB above
     ' put rect to hold text on screen -  Black RECT for Shadow
     RECT Main, left+22, top+12, width-40, 33, RGB(0,0,0),RGB(0,0,0) 
     ' Yellow Rect with Red Border - offset on top of Black RECT
     RECT Main, left+20, top+10, width-40, 33, RGB(255,0,0),RGB(255,255,0) 
     ' Set the font to use for text 
     SETFONT Main, "Arial", 18, 900, @SFITALIC
     ' Draw Mode set to Transparent so type uses existing background
     DRAWMODE Main, @TRANSPARENT 
     ' set color for the typeface - black for drop shadow
     FRONTPEN Main, RGB(0,0,0)
     ' Position on screen to print text
     MOVE Main, 26,13
     ' Place the text on screen
     PRINT Main, "Graduation Tint  -  by Bizzy"
     ' set color for the typeface - red for type
     FRONTPEN Main, RGB(255,0,0)
     ' Position on screen to print text - 
     ' offset from above text to produce shadow
     MOVE Main, 25,12
     ' Place the text on screen
     PRINT Main, "Graduation Tint  -  by Bizzy"
RETURN

Use the Mouse to Re-Size the Window and see the Graduation Tint re-painted to the screen.

Graduation Tints can also be added to any area on the window in the same way simply be specifying the RECT area of the Screen to work with. For Example the RECT where the Type was printed could have its own Graduation Tint instead of the Solid Yellow simply by working another Tint to the size of the RECT.