[comp.sys.apple] programming questions

hartkopf@tramp.Colorado.EDU (Jeff Hartkopf) (08/25/89)

I have two questions concerning toolbox programming on the GS, using
ORCA/C.  I have previously accomplished what I'm asking about below
when I was using TML Pascal, but I can't figure out how to do it in C.

1)  How do you create a set of 16 colors for 640 mode, like the pre-defined
StdColors[] in TML Pascal?  The Pascal manual says that they defined
StdColors like

StdColors: array[0..15] of Pattern;

and that StdColors[0] (black) contains 16 words of $0000, StdColors[1]
(blue) contains 16 words of $1111, ..., StdColors[15] (white) contains
16 words of $FFFF.  Now, how would I actually declare/initialize an
array like this in ORCA/C, so that I could use the statement

SetPenPat(color[x]);


2)  How do I define an icon (in the format used for DrawIcon()) in C?
In Pascal, I did it like this (there are bound to be errors in the
following code, I just show it as a comparison):

type
	masktype = array[1..height, 1..widthbytes] of byte;

	iconrec =
	record
		IconType:	Integer;
		IconSize:	Integer;
		IconHeight:	Integer;
		IconWidth:	Integer;
		IconImage:	masktype;
		IconMask:	masktype;
	end;

var
	iconmask:	masktype;
	icon:		iconrec;

	with icon do
	begin
		IconType := 	ColorIconType;
		IconSize := 	size;		
		IconHeight := 	height;
		IconWidth :=	width; 
	end;

procedure makeicon;
	StuffHex(@icon.IconMask[1],		'FFFFFFFFFFFFFF');
	StuffHex(@icon.IconMask[2],		'FFFFFFFFFFFFFF');
{ ... }

	StuffHex(@icon.IconImage[1],		'F000FFFC000000');
	StuffHex(@icon.IconImage[2],		'C0003FF0000000');
{ ... }
end;

and then draw the icon with

DrawIcon(&icon, 0, 0, 0);


Thanks very much for any help.


Jeff Hartkopf

Internet:
hartkopf@tramp.Colorado.EDU

dlyons@Apple.COM (David Lyons) (08/26/89)

In article <11032@boulder.Colorado.EDU> hartkopf@tramp.Colorado.EDU (Jeff Hartkopf) writes:

[In ORCA/C, how do I....]

>[...]  Now, how would I actually declare/initialize an
>array like this in ORCA/C, so that I could use the statement
>
>SetPenPat(color[x]);

Well, here's one way:

int color[16][16] = {
  { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
  { 0x1111, 0x1111, 0x1111, 0x1111, 0x1111, 0x1111, 0x1111, 0x1111,
    ... },
   ...
 };

Icky, eh?

You could do something like this instead:

void SetDithColor(int x)
{
  int patt[16], i;
  x *= 0x1111;
  for(i=0; i<16; i++)
      patt[i] = x;
  SetPenPat(patt);
}

(Not tested, but looks okay.)


>2)  How do I define an icon (in the format used for DrawIcon()) in C?

You can do a fairly straightforward translation of your Pascal code into
C; of you can use an icon editor to generate the code.  (I know my DIcEd
will "Save As Source" for "APW C"; other icon editors may, too.)  DIcEd
generates something like this for you (in a text file):

static char Icon1[] = {
  0x00, 0x00, 0x80, ... /* lots o' bytes */
}

which you can just cut and paste it into your code.  The dialog box says
APW C, but it's just a generic "static char" declaration, so it'll work
just as well with ORCA/C.

 --Dave Lyons, Apple Computer, Inc.          |   DAL Systems
   AppleLink--Apple Edition: DAVE.LYONS      |   P.O. Box 875
   AppleLink--Personal Edition: Dave Lyons   |   Cupertino, CA 95015-0875
   GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
   Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons

   My opinions are my own, not Apple's.