1 #include <intuition/intuition.h>
2 #include <cybergraphx/cybergraphics.h>
4 #include <proto/exec.h>
5 #include <proto/graphics.h>
6 #include <proto/intuition.h>
7 #include <proto/cybergraphics.h>
8 #include <proto/alib.h>
14 #include "kittysprite_image.c"
16 static struct Screen
*scr
;
17 static struct Window
*win
;
18 static struct Region
*shape
;
19 static Object
*draggad
;
20 static BOOL remapped
, truecolor
, shape_active
= TRUE
;
21 static UBYTE chunky
[KITTYSPRITE_WIDTH
* KITTYSPRITE_HEIGHT
];
22 static UBYTE remaptable
[KITTYSPRITE_COLORS
];
23 static ULONG cgfx_coltab
[KITTYSPRITE_COLORS
];
25 static void cleanup(char *msg
)
29 printf("Kitty: %s\n", msg
);
36 for(i
= 0; i
< KITTYSPRITE_COLORS
; i
++)
38 ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[i
]);
42 if (scr
) UnlockPubScreen(NULL
, scr
);
43 if (draggad
) DisposeObject(draggad
);
44 if (win
) CloseWindow(win
);
49 static void getvisual(void)
51 if (!(scr
= LockPubScreen(NULL
)))
53 cleanup("Can't lock pub screen!");
56 if (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) > 8)
62 #if KITTYSPRITE_PACKED
63 static BOOL
unpack_byterun1(const UBYTE
*source
, UBYTE
*dest
, LONG unpackedsize
)
70 c
= (BYTE
)(*source
++);
76 if (--unpackedsize
<= 0) return FALSE
;
87 if (--unpackedsize
<= 0) return FALSE
;
96 static void makegfx(void)
100 #if KITTYSPRITE_PACKED
101 unpack_byterun1(kittysprite_data
, chunky
, KITTYSPRITE_WIDTH
* KITTYSPRITE_HEIGHT
);
103 memcpy(chunky
, kittysprite_data
, KITTYSPRITE_WIDTH
* KITTYSPRITE_HEIGHT
);
111 for(y
= 0; y
< KITTYSPRITE_HEIGHT
; y
++)
113 struct Rectangle rect
= {0, y
, 0, y
};
114 BOOL transp
, transpstate
= TRUE
;
116 for(x
= 0; x
< KITTYSPRITE_WIDTH
; x
++)
118 transp
= chunky
[y
* KITTYSPRITE_WIDTH
+ x
] == 0;
124 rect
.MaxX
= rect
.MinX
= x
;
132 OrRectRegion(shape
, &rect
);
142 if (!transpstate
) OrRectRegion(shape
, &rect
);
146 for(i
= 0; i
< KITTYSPRITE_COLORS
; i
++)
150 cgfx_coltab
[i
] = kittysprite_pal
[i
];
154 ULONG r
= (kittysprite_pal
[i
] >> 16) & 0xFF;
155 ULONG g
= (kittysprite_pal
[i
] >> 8) & 0xFF;
156 ULONG b
= (kittysprite_pal
[i
]) & 0xFF;
158 remaptable
[i
] = ObtainBestPen(scr
->ViewPort
.ColorMap
,
162 OBP_Precision
, PRECISION_IMAGE
,
163 OBP_FailIfBad
, FALSE
,
173 for(i
= 0; i
< KITTYSPRITE_WIDTH
* KITTYSPRITE_HEIGHT
; i
++)
175 chunky
[i
] = remaptable
[chunky
[i
]];
181 static void makedraggad(void)
183 draggad
= NewObject(NULL
, GADGETCLASS
, GA_Left
, 0,
187 GA_SysGType
, GTYP_WDRAGGING
,
193 static void makewin(void)
195 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
198 WA_Width
, KITTYSPRITE_WIDTH
,
199 WA_Height
, KITTYSPRITE_HEIGHT
,
202 WA_IDCMP
, IDCMP_VANILLAKEY
,
203 WA_Gadgets
, (IPTR
)draggad
,
204 WA_ShapeRegion
, (IPTR
)shape
,
207 if (!win
) cleanup("Can't open window!");
210 static void paintwin(void)
214 WriteLUTPixelArray(chunky
,
228 WriteChunkyPixels(win
->RPort
,
231 KITTYSPRITE_WIDTH
- 1,
232 KITTYSPRITE_HEIGHT
- 1,
238 static void handleall(void)
240 struct IntuiMessage
*msg
;
245 WaitPort(win
->UserPort
);
246 while((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
250 case IDCMP_VANILLAKEY
:
278 ChangeWindowShape(win
, (shape_active
? NULL
: shape
), NULL
);
279 shape_active
= !shape_active
;
281 } /* switch(msg->Code) */
284 } /* switch(msg->Class) */
286 ReplyMsg((struct Message
*)msg
);
288 } /* while((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
290 } /* while(!quitme) */