news
About Elegant Chaos
info
About me and my friends
people
Software from Elegant Chaos
software
Other stuff...
stuff

Pollocks

An XCMD for painting colour lines, shapes and pictures directly on to the card window.

Pollocks XCMD. Version 3.2d3, by Sam Deane. Copyright ©1994 ULTRALAB. Compiled 15:53:43, 06/12/94. Debugging code included.


[last exit to hypercard] [externals index] [download Pollocks]

Description

Back in the old days (when I were a lad), there was no way of displaying colour pictures in Hypercard, so I got out my copy of Turbo Pascal (those were the days eh?) and decided that it was time I had a go at this XCMD lark.

What resulted was an XCMD called DrawPICTs, which allowed you to paint PICT resources directly on to the card window. It worked, but looking back at the code I'm not sure how or why, since it was complete gibberish which broke every rule in Inside Mac!

Now that Hypercard 2's picture command exists, along with a whole load of clever stuff like Colourize Hypercard, HyperTint, and Ken Doyle's QTPict XCMD, there are rather more options available.

Nevertheless, DrawPICTs (now called Pollocks) has hung around, been improved now and then, and proven to be useful enough to get included in a number of our products.

In addition to displaying PICT resources, it now allows you to do basic PICT animations, to paint coloured shapes all over the place, and to fudge around with the clip region of hypercard's window.

Clipping

The main problem with painting pictures directly on to the card window like this, is that Hypercard doesn't know that they are there, and so it will obliterate them whenever it refreshes the screen. As this happens quite often, pictures have a habit of disappearing, or even worse getting partially wiped out.

A partial solution to this problem is to tell hypercard not to draw into the areas of the window that contain pictures. This can be done by modifying the window's clipping region.

The clipping region determines the area of the window into which hypercard can draw. Normally the clipping region covers the whole card. With the add, subtract and reset commands it is possible to modify the clipping region of the current card window, so that rectangular areas of the window are removed from it.

The remove command removes rectangles from the clip region, effectively masking out areas of the window. The add command puts areas back in.

The reset command can be used at any time to reset the clip region to its normal value, covering the whole of the window.

Æ NB: Removing an area from the clip region only prevents Hypercard from drawing into that area, it does not prevent the area from being obscured by another window (for example a palette window). When an obscuring window is removed, a white space will be left in it's wake. Hypercard will not be able to redraw your picture (since it doesn't know about it), and it won't even be able redraw the card graphics that it does know about (since you have prevented it from drawing into that area of it's window!).

To avoid this problem, it is best to clip out any pictures just before doing something that is likely to obliterate them (going from card to card for example) and to restore the clip region as soon as possible afterwards.


Commands

draw

The draw command is the simplest way of drawing a picture resource (PICT) on to the card.

The syntax is:

  Pollocks draw,<name>,<left>,<top>

The <name> parameter should contain the name or id of a PICT resource somewhere in the current inheritance path.

The <left> and <top> parameters should contain the coordinates of the top left corner of the PICT. The picture will be displayed at this location in the window of the current stack. It will be clipped by the current clip-region of the card window.

Example script for draw

on mouseDown
  Pollocks draw,"test",140,0
  
  ClearWhenClicked
end mouseDown

list

The list command can be used to display up to 16 pictures in one go.

It has the following syntax:

  Pollocks list,<picture> { ,<picture> {,...etc }}

where <picture> is a single item in the form "<name>,<left>,<top>".

The <name> parameter should contain the name or id of a PICT resource somewhere in the current inheritance path.

The <left> and <top> parameters should contain the coordinates of the top left corner of the PICT. The picture will be displayed at this location in the window of the current stack. It will be clipped by the current clip-region of the card window.

Example script for list

on mouseDown
  Pollocks list,"test,140,0,test,140,100"
  ClearWhenClicked
end mouseDown

sequence

The sequence command allows for basic animation, by displaying a numbered sequence of PICTs in quick succession.

The syntax of the command is:

  Pollocks sequence,<name>,<left>,<top>,<frames>

This is the same syntax as the draw command, but with one extra parameter. The <frames> parameter should be a number saying how many frames there are in the PICT sequence.

The command will display the pictures "<name>1", "<name>2" ... "<name><frames>" in turn, producing a basic animation. Note that the speed of this animation is totally dependant on the hardware, which is not a good thing. For more sophisticated animation, it would be best to get into Quicktime.

into

The into command draws a picture into a rectangle, scaling the picture if necessary.

It has the following syntax:

  Pollocks into,<name>,<rectangle>

The <name> parameter should contain the name or id of a PICT resource somewhere in the current inheritance path.

The <rectangle> parameter specifies the exact rectangle into which the picture should be drawn. The picture will be scaled as necessary to accomplish this.

Example script for into

on mouseDown
  Pollocks into,"test",the rect of bg fld "text"
  
  ClearWhenClicked
end mouseDown

add

The add command puts rectangular areas back in to the card's clipping region.

The syntax of this commands is:

  Pollocks add,<rectangle>

where <rectangle> is the rectangle to add/remove from the clip region.

subtract

The subtract command removes rectangles from the clip region, effectively masking out areas of the window.

The syntax of this commands is:

  Pollocks subtract,<rectangle>

where <rectangle> is the rectangle to add/remove from the clip region.

reset

The reset command can be used at any time to reset the clip region to its normal value, covering the whole of the window.

The syntax of this commands is:

  Pollocks reset

foreground

The foreground command can be used to change the actual colour that hypercard uses to display "black" pixels. This is a bit of a kludge, as the colour can only be set to one of eight values.

The syntax is:

  Pollocks foreground,<colour>

where <colour> is one of: black,white,red,green,blue, cyan,magenta,or yellow.

Example script for foreground

on mouseDown
  put "black,white,red,green,blue,cyan,magenta,yellow" into cols
  
  get Poppet(items,cols,0,the topLeft of the target,comma)
  if it ­ 0 then
    Pollocks foreground,item 3 of it
  end if
end mouseDown

rect

The rect command is used to paint or colour wash rectangular sections of the card. Like the picture drawing commands, the results of this permanent only until the next time Hypercard updates it's window.

The syntax for this command is not fixed yet, but is currently:

  Pollocks rect,<rectangle>,<colour>,<size>,<mode>

The <colour> parameter is a three item RGB colour in the format "<red>,<green>,<blue>".

The <size> parameter is a number determines the thickness of the lines used to draw the rectangle. If "fill" is specified, instead of a number, the rectangle is filled.

The <mode> parameter is a number which specifies the Quickdraw pen mode to use when painting the rectangle. If "hilite" is passed, the special hilite mode will be used, which will result in a rectangle painted in the current hilite colour.

Example script for rect

on mouseDown
  -- outline the section field
  Pollocks rect,the rect of bg fld "section","20000,20000,20000",5,srccopy
  
  -- hilite the text field rectangle
  Pollocks rect,the rect of bg fld "text","10000,0,0",fill,hilite
  
  
  ClearWhenClicked
end mouseDown

update

The update command is used to force Hypercard to re-draw a section of the card window. This can be useful if you know that a section of the window is likely to be invalid, as a result of previous messing around with the clip region of the window.

The syntax for the command is:

  Pollocks update,<rectangle>

depth

The depth command returns the bit-depth of the deepest screen in the result.

Example script for depth

on mouseDown
  Pollocks depth
  answer "Max depth is: " & the result
end mouseDown

devices

The devices command returns a list giving the details of all the screens connected to the computer.

The syntax is:

  Pollocks devices

A list is returned in the result, with one line for each screen.

The first item of each line is the depth of the screen. Items 2 to 5 give the localtion of the screen, in global coordinates.

Example script for devices

on mouseDown
  Pollocks devices
  answer "Number of screens: " & the number of lines in the result
end mouseDown

background

The background command can be used to change the actual colour that hypercard uses to display "white" pixels. This is a bit of a kludge, as the colour can only be set to one of eight values.

The syntax is:

  Pollocks background,<colour>

where <colour> is one of: black,white,red,green,blue, cyan,magenta,or yellow.

Example script for background

on mouseDown
  put "black,white,red,green,blue,cyan,magenta,yellow" into cols
  
  get Poppet(items,cols,0,the topLeft of the target,comma)
  if it ­ 0 then
    Pollocks background,item 3 of it
  end if
end mouseDown

line

The line command is used to paint or colour wash lines onto the card. Like the picture drawing commands, the results of this permanent only until the next time Hypercard updates it's window.

The syntax for this command is not fixed yet, but is currently:

  Pollocks "line",<start>,<path>,<colour>,<size>,<mode>

The <start> parameter gives the start point of the line. The <path> parameter gives the path of the line as a series of coordinates in the form x1,y1,x2,y2,x3,y3, etc..

The <colour> parameter is a three item RGB colour in the format "<red>,<green>,<blue>".

The <size> parameter is a number determines the thickness of the line.

The <mode> parameter is a number which specifies the Quickdraw pen mode to use when painting the line. If "hilite" is passed, the special hilite mode will be used, which will result in a line painted in the current hilite colour.

Example script for line

on mouseDown
  put the topLeft of bg field "text" into tl
  put the botRight of bg field "text" into br
  
  repeat with n = 1 to 50
    Pollocks line,tl,br,"30000,5000,5000",1,srccopy
    subtract 5 from item 2 of br
  end repeat
  
  repeat with n = 1 to 50
    Pollocks line,tl,br,"5000,30000,5000",1,srccopy
    add 4 to item 2 of tl
  end repeat
  
  repeat with n = 1 to 50
    Pollocks line,tl,br,"5000,5000,30000",1,srccopy
    subtract 4 from item 1 of br
  end repeat
  
  ClearWhenClicked
end mouseDown

globalRect

Example script for globalRect

on mouseDown
  -- outline the section field
  Pollocks globalRect,the rect of bg fld "section","20000,20000,20000",5,srccopy
  
  -- hilite the text field rectangle
  Pollocks globalRect,the rect of bg fld "text","10000,0,0",fill,hilite
  
  
  ClearWhenClicked
end mouseDown

globalLine

The line command is used to paint or colour wash lines onto the card. Like the picture drawing commands, the results of this permanent only until the next time Hypercard updates it's window.

The syntax for this command is not fixed yet, but is currently:

  Pollocks "line",<start>,<end>,<colour>,<size>,<mode>

The <start> and <end> parameters give the start and end points of the line.

The <colour> parameter is a three item RGB colour in the format "<red>,<green>,<blue>".

The <size> parameter is a number determines the thickness of the line.

The <mode> parameter is a number which specifies the Quickdraw pen mode to use when painting the line. If "hilite" is passed, the special hilite mode will be used, which will result in a line painted in the current hilite colour.

Example script for globalLine

on mouseDown
  put the topLeft of bg field "text" into tl
  put the botRight of bg field "text" into br
  
  repeat with n = 1 to 50
    Pollocks globalLine,tl,br,"30000,5000,5000",1,srccopy
    subtract 5 from item 2 of br
  end repeat
  
  repeat with n = 1 to 50
    Pollocks globalLine,tl,br,"5000,30000,5000",1,srccopy
    add 4 to item 2 of tl
  end repeat
  
  repeat with n = 1 to 50
    Pollocks globalLine,tl,br,"5000,5000,30000",1,srccopy
    subtract 4 from item 1 of br
  end repeat
  
  ClearWhenClicked
end mouseDown

draw file

list file

sequence file

into file


[last exit to hypercard] [externals index] [download Pollocks]

This page was created automatically, on 25/03/1999 from version 3.0d4 of Last Exit To Hypercard.