home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 2
/
FFMCD02.bin
/
new
/
gfx
/
edit
/
tsmorph
/
subroutines.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-21
|
59KB
|
2,335 lines
// TSMorph - Amiga Morphing program
// Copyright (C) © 1993 Topicsave Limited
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// mpaddock@cix.compulink.co.uk
// $Author: M_J_Paddock $
// $Date: 1993/09/04 17:43:32 $
// $Revision: 1.15 $
// include precompiled headers if required
#ifndef TSMORPH_H
#include "TSMorph.h"
#endif
extern char TempFilename[256]=""; // file name buffer set up and used in various places
UBYTE r[256],g[256],b[256]; // Saved rgb colors
/* display short help message
* at top of window
* helpnum : number of help node
*/
void
ihelp(ULONG helpnum) {
// only display if not zero, and there is a short message and the window is open
if (helpnum) {
if (*(ShortHelp[helpnum])) {
if (TSMorphWnd) {
GT_SetGadgetAttrs(TSMorphGadgets[GDX_Help],TSMorphWnd,NULL,
GTTX_Text,ShortHelp[helpnum], TAG_END );
}
}
}
}
/* Display help using amigaguide (if available)
* based on a number. Also displays short help message
*/
void
help(ULONG helpnum) {
// display amigaguide if available
if (handle) {
SetAmigaGuideContext(handle,helpnum,NULL);
SendAmigaGuideContext(handle,NULL);
}
// display short message
ihelp(helpnum);
}
/* Colour the picture based on it colormap
* Saving the palette for later use
* The palette is only set when the window is active and a menu is not displayed
*/
void
ColorWindow(struct Picture *pic) {
UWORD i; // Loop counter
UWORD color; // Colour
if (palette) {
if (pic) {
if (pic->ilbm->colortable) {
// Store and set up to 256 colours
for (i=0; i<min((1 << pic->Win->WScreen->BitMap.Depth),256); i++) {
color = GetRGB4(pic->Win->WScreen->ViewPort.ColorMap,i);
r[i]=(color&0x0f00)>>8;
g[i]=(color&0x00f0)>>4;
b[i]=(color&0x000f);
}
LoadRGB4(&(pic->Win->WScreen->ViewPort),pic->ilbm->colortable,
MIN(pic->ilbm->ncolors,pic->Win->WScreen->ViewPort.ColorMap->Count));
}
}
}
}
/* Reset the palette to the original
* stored in ColorWindow()
* Called when window becomes inactive or menu is to be displayed
*
* Note: This routine and the one above are not really allowed by CBM
* But if no other program is changing the palette whilst its
* window is inactive then everything should (amy) be OK.
*/
void
UnColorWindow(struct Picture *pic) {
UWORD i; // Loop counter
if (palette) {
if (pic) {
if (pic->ilbm->colortable) {
for (i=0; i<min((1 << pic->Win->WScreen->BitMap.Depth),256); i++) {
SetRGB4(&(pic->Win->WScreen->ViewPort),i,r[i],g[i],b[i]);
}
}
}
}
}
/* Standard CloseWindowSafely
* removing messages on shared ports
*/
void
CloseWindowSafely(struct Window *win) {
Forbid();
StripIntuiMessages(win->UserPort,win);
win->UserPort = NULL;
ModifyIDCMP(win,0);
Permit();
CloseWindow(win);
}
/* Standard StripIntuiMessages */
void
StripIntuiMessages(struct MsgPort *mp,struct Window *win) {
struct IntuiMessage *msg, *succ;
msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
while(succ = (struct IntuiMessage *)msg->ExecMessage.mn_Node.ln_Succ) {
if(msg->IDCMPWindow == win) {
Remove((struct Node *)msg);
ReplyMsg((struct Message *)msg);
}
msg = succ;
}
}
/* Display an error message
* ErrorMessage : The main text
* Gadget : Text for one gadget
* extra : more of the text
* helpnum : Number of a help node
*
* Uses reqtools.library if available
*/
void
Error(char *ErrorMessage,char *Gadget,char *extra,ULONG helpnum) {
struct EasyStruct EasyStruct = {
sizeof(struct EasyStruct),
0,
NULL,
NULL,
NULL
};
UBYTE *title = "TSMorph Error";
struct Window *req;
UBYTE gad[32] = "Help|";
UBYTE gad1[32] = "_Help|_";
ULONG ret = CALL_HANDLER;
struct AmigaGuideMsg *agm;
ULONG signals;
struct rtHandlerInfo *rth;
// Disable the windows and display the requester
DisableWindows(helpnum);
if (ReqToolsBase) {
// Set up gadgets depending on if amigaguide is available
if (!handle) {
strcpy(gad1,"_");
}
strcat(gad1,Gadget);
// This loops until OK is pressed, displaying help if Help is pressed (if present)
while (ret) {
ret = CALL_HANDLER;
if (rtEZRequestTags(ErrorMessage,gad1,NULL,&extra,
RT_ReqHandler, &rth,
RT_Window, TSMorphWnd,
RT_Underscore, '_',
RTEZ_ReqTitle, title,
TAG_END) == CALL_HANDLER) {
while (ret == CALL_HANDLER) {
if (!rth->DoNotWait) {
signals = Wait(rth->WaitMask | ASig);
}
ret = rtReqHandlerA(rth,signals,NULL);
if (ret == 1) {
help(helpnum);
}
if (signals & ASig) {
while (agm = GetAmigaGuideMsg(handle)) {
ReplyAmigaGuideMsg(agm);
}
}
}
}
else {
ret = 0;
}
}
}
else {
EasyStruct.es_TextFormat = ErrorMessage;
EasyStruct.es_Title = title;
// Set up gadgets depending on if amigaguide is available
if (handle) {
strcat(gad,Gadget);
}
else {
strcpy(gad,Gadget);
}
EasyStruct.es_GadgetFormat = gad;
req = BuildEasyRequest(TSMorphWnd,&EasyStruct,NULL,extra);
// This loops until OK is pressed, displaying help if Help is pressed (if present)
while (ret) {
signals = Wait((1L << req->UserPort->mp_SigBit) | ASig);
if (signals & (1L << req->UserPort->mp_SigBit)) {
ret = SysReqHandler(req,NULL,FALSE);
if (ret == 1) {
help(helpnum);
}
}
if (signals & ASig) {
while (agm = GetAmigaGuideMsg(handle)) {
ReplyAmigaGuideMsg(agm);
}
}
}
FreeSysRequest(req);
}
EnableWindows();
}
/* As Error but
* pic : a picture to uncolor if required
*/
void
XError(struct Picture *pic,char *ErrorMessage,char *Gadget,char *extra,ULONG helpnum) {
UnColorWindow(pic);
Error(ErrorMessage,Gadget,extra,helpnum);
ColorWindow(pic);
}
/* Draw all points
* in both windows
*/
void
DrawAllPoints(void) {
struct MyPoint *MyPoint;
// For each point
for (MyPoint = (struct MyPoint *)PointList.lh_Head;
MyPoint->MyNode.mln_Succ;
MyPoint = (struct MyPoint *)MyPoint->MyNode.mln_Succ) {
// Draw point in image 1
DrawPixels(&Pic1,MyPoint->x,MyPoint->y,NULL);
/* For each linked point draw a line
* to the other if the other is a "later" point
*/
if (MyPoint->p1 > MyPoint) {
MyDraw(Pic1.Win->RPort,MyPoint->p1->x<<Zoom,MyPoint->p1->y<<Zoom,MyPoint->x<<Zoom,MyPoint->y<<Zoom);
}
if (MyPoint->p2 > MyPoint) {
MyDraw(Pic1.Win->RPort,MyPoint->p2->x<<Zoom,MyPoint->p2->y<<Zoom,MyPoint->x<<Zoom,MyPoint->y<<Zoom);
}
if (MyPoint->p3 > MyPoint) {
MyDraw(Pic1.Win->RPort,MyPoint->p3->x<<Zoom,MyPoint->p3->y<<Zoom,MyPoint->x<<Zoom,MyPoint->y<<Zoom);
}
if (MyPoint->p4 > MyPoint) {
MyDraw(Pic1.Win->RPort,MyPoint->p4->x<<Zoom,MyPoint->p4->y<<Zoom,MyPoint->x<<Zoom,MyPoint->y<<Zoom);
}
// Same stuff for image 2
DrawPixels(&Pic2,MyPoint->x1,MyPoint->y1,NULL);
if (MyPoint->p1 > MyPoint) {
MyDraw(Pic2.Win->RPort,MyPoint->p1->x1<<Zoom,MyPoint->p1->y1<<Zoom,MyPoint->x1<<Zoom,MyPoint->y1<<Zoom);
}
if (MyPoint->p2 > MyPoint) {
MyDraw(Pic2.Win->RPort,MyPoint->p2->x1<<Zoom,MyPoint->p2->y1<<Zoom,MyPoint->x1<<Zoom,MyPoint->y1<<Zoom);
}
if (MyPoint->p3 > MyPoint) {
MyDraw(Pic2.Win->RPort,MyPoint->p3->x1<<Zoom,MyPoint->p3->y1<<Zoom,MyPoint->x1<<Zoom,MyPoint->y1<<Zoom);
}
if (MyPoint->p4 > MyPoint) {
MyDraw(Pic2.Win->RPort,MyPoint->p4->x1<<Zoom,MyPoint->p4->y1<<Zoom,MyPoint->x1<<Zoom,MyPoint->y1<<Zoom);
}
}
}
/* Handle Raw Key in Information
* Window - from GadToolsBox
*/
int
TSMorphRawKey(void) {
UWORD X,Y; // Mouse position
ULONG HNum; // Help node
X = TSMorphWnd->MouseX;
Y = TS