376 lines
13 KiB
C
376 lines
13 KiB
C
/* File UI.c */
|
|
/* These functions allocate and free Intuition objects.*/
|
|
|
|
/****************************************************************
|
|
Topograph - A function browser
|
|
Copyright (C) 1996 Marc Culler
|
|
|
|
culler@math.uic.edu
|
|
|
|
Department of Mathematics (M/C 249)
|
|
University of Illinois at Chicago
|
|
851 S. Morgan St.
|
|
Chicago, IL 60607-7045
|
|
|
|
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
|
|
(at your option) 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.
|
|
******************************************************************/
|
|
|
|
#include "Topograph.h"
|
|
#include "graph.h"
|
|
|
|
/* Defined in this module */
|
|
int openUI(ULONG *CPSignal, ULONG *graphSignal);
|
|
void closeUI(void);
|
|
int bailOut(char *userMessage);
|
|
void stackScreens(void);
|
|
void hideScreens(void);
|
|
void CPToFront(void);
|
|
void noPointer(void);
|
|
void ticksOff(void);
|
|
void ticksOn(void);
|
|
|
|
/* Defined in gadgets.c */
|
|
extern struct Gadget *buildCPGadgets(void);
|
|
extern struct Gadget *buildxyzGadgets(void);
|
|
extern void removeAbortGadget(void);
|
|
|
|
/* Defined in menus.c */
|
|
struct Menu *createCPMenu(void);
|
|
|
|
/* Defined in parseIO.c */
|
|
extern void closeIOConsole(void);
|
|
|
|
/* Global data for the User Interface. */
|
|
|
|
struct Screen *CPScreen = NULL;
|
|
struct Screen *graphScreen = NULL;
|
|
struct Screen *xyzScreen = NULL;
|
|
struct Window *CPWindow = NULL;
|
|
struct Window *graphWindow = NULL;
|
|
struct Window *xyzWindow = NULL;
|
|
struct Menu *CPMenu = NULL;
|
|
struct FileRequester *CPFileRequester = NULL;
|
|
struct DrawInfo *CPDrawInfo = NULL;
|
|
APTR *CPVisualInfo = NULL;
|
|
struct TextAttr topaz = {"topaz.font",8,0,FPF_ROMFONT};
|
|
struct TextFont *CPFont = NULL;
|
|
APTR *xyzVisualInfo = NULL;
|
|
struct Gadget *CPGadgetList;
|
|
struct Gadget *xyzGadgetList;
|
|
struct Gadget *CPGadgets[NUMGADGETS];
|
|
int graphLeft;
|
|
int graphTop;
|
|
int graphWidth;
|
|
int graphHeight;
|
|
struct graph *graphData = NULL;
|
|
struct BitMap *graphBitMap = NULL;
|
|
char titleString[256] = {'\0'};
|
|
char inputWindowString[128];
|
|
char messageWindowString[128];
|
|
|
|
UWORD __chip emptyPointer[] = {0,0,0,0,0,0};
|
|
|
|
USHORT fillPattern[] = {0x5555,0xAAAA};
|
|
|
|
UWORD CPColors[] = {0x888, 0x000, 0xfff, 0x37b};
|
|
|
|
UWORD spectrum[] = {
|
|
/* 0*/0x888, /*gray (background)*/
|
|
/* 1*/0x000, /*black (Under Color)*/
|
|
|
|
/* 2*/0xf03, /* 3*/0xf00, /* 4*/0xf20, /* 5*/0xf40, /*reds */
|
|
/* 6*/0xf60, /* 7*/0xf80, /* 8*/0xfa0, /* 9*/0xca0, /*oranges*/
|
|
/*10*/0x9a0, /*11*/0x6b0, /*12*/0x3c0, /*13*/0x0d0, /*yellows*/
|
|
/*14*/0x0e3, /*15*/0x0d6, /*greens */
|
|
|
|
/*16*/0xfff, /*white (Over Color)*/
|
|
/*17*/0xa41, /*brown (pointer) */
|
|
|
|
/*18*/0x0c9, /*19*/0x0bc, /*greens */
|
|
/*20*/0x0af, /*21*/0x08f, /*22*/0x06f, /*23*/0x04f, /*blues */
|
|
/*21*/0x02f, /*22*/0x00f, /*23*/0x40f, /*24*/0x80f, /*indigos*/
|
|
/*25*/0xc0f, /*26*/0xf0f, /*27*/0xf0a, /*28*/0xf05, /*violets*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Defined in Topograph.c */
|
|
extern struct CPMessage CPmsg;
|
|
|
|
/* Open all of the Intuition objects used by the UI. */
|
|
|
|
int openUI(ULONG *CPSignal, ULONG *graphSignal){
|
|
ULONG pens[] = {~0};
|
|
struct Rectangle hiresRect, loresRect;
|
|
int n;
|
|
|
|
QueryOverscan(HIRESLACE_KEY, &hiresRect, OSCAN_TEXT);
|
|
QueryOverscan(LORES_KEY, &loresRect, OSCAN_TEXT);
|
|
graphWidth = 320;
|
|
graphTop = 42;
|
|
graphLeft = (loresRect.MaxX - 320)/2;
|
|
graphHeight = loresRect.MaxY - loresRect.MinY - graphTop - 10;
|
|
|
|
CPFont = OpenDiskFont(&topaz);
|
|
if (CPFont == NULL) return bailOut("Could not open CP font.");
|
|
|
|
CPScreen = OpenScreenTags(NULL,
|
|
SA_Depth, 2,
|
|
SA_DisplayID, HIRESLACE_KEY,
|
|
SA_Pens, &pens,
|
|
SA_Font, &topaz,
|
|
SA_Behind, TRUE,
|
|
SA_Title, "Topograph Screen",
|
|
SA_Type, CUSTOMSCREEN,
|
|
SA_PubName, "Topograph",
|
|
SA_Overscan, OSCAN_TEXT,
|
|
SA_Width, STDSCREENWIDTH,
|
|
SA_Height, hiresRect.MaxY - 20,
|
|
TAG_DONE);
|
|
if (CPScreen == NULL) return bailOut("Could not open Topograph screen.");
|
|
|
|
LoadRGB4(&(CPScreen->ViewPort), CPColors, 4);
|
|
|
|
CPDrawInfo = GetScreenDrawInfo(CPScreen);
|
|
|
|
CPVisualInfo = GetVisualInfo(CPScreen, TAG_END);
|
|
if (CPVisualInfo == NULL) return bailOut("Could not get CP visual info.");
|
|
|
|
if (buildCPGadgets() == NULL) return bailOut("Could not build CP gadgets.");
|
|
|
|
CPWindow = OpenWindowTags(NULL,
|
|
WA_Left, 0,
|
|
WA_Top, 0,
|
|
WA_Width, CPScreen->Width,
|
|
WA_Height, 78,
|
|
WA_AutoAdjust, TRUE,
|
|
WA_CustomScreen, CPScreen,
|
|
WA_IDCMP, IDCMP_CLOSEWINDOW |
|
|
IDCMP_MENUPICK |
|
|
IDCMP_GADGETDOWN |
|
|
IDCMP_RAWKEY |
|
|
CYCLEIDCMP |
|
|
STRINGIDCMP |
|
|
TEXTIDCMP |
|
|
BUTTONIDCMP |
|
|
IDCMP_INTUITICKS,
|
|
WA_Title, "Topograph",
|
|
WA_CloseGadget, TRUE,
|
|
WA_Gadgets, CPGadgetList,
|
|
WA_SmartRefresh, TRUE,
|
|
WA_Activate, FALSE,
|
|
TAG_DONE);
|
|
if (CPWindow == NULL) return bailOut("Could not open CP window.");
|
|
|
|
GT_RefreshWindow(CPWindow, NULL);
|
|
|
|
/* Remove the abort print gadget until we need it. */
|
|
removeAbortGadget();
|
|
|
|
graphBitMap = AllocMem(sizeof(struct BitMap), MEMF_PUBLIC | MEMF_CLEAR);
|
|
if (graphBitMap == NULL) return bailOut("Could not allocate graph bitmap.");
|
|
|
|
InitBitMap(graphBitMap, 6, graphWidth, graphHeight);
|
|
|
|
for (n = 0; n < 6; n++){
|
|
graphBitMap->Planes[n] = AllocRaster(graphWidth, graphHeight);
|
|
if (graphBitMap->Planes[n] == NULL) return bailOut("Could not allocate bitplane.");
|
|
}
|
|
|
|
graphScreen = OpenScreenTags(NULL,
|
|
SA_Depth, 6,
|
|
SA_DisplayID, EXTRAHALFBRITE_KEY,
|
|
SA_Pens, &pens,
|
|
SA_Font, &topaz,
|
|
SA_Behind, TRUE,
|
|
SA_Quiet, TRUE,
|
|
SA_Type, CUSTOMSCREEN,
|
|
SA_BitMap, graphBitMap,
|
|
SA_Left, graphLeft,
|
|
SA_Top, graphTop,
|
|
SA_Width, graphWidth,
|
|
SA_Height, graphHeight,
|
|
TAG_DONE);
|
|
if (graphScreen == NULL) return bailOut("Could not open graph screen.");
|
|
|
|
LoadRGB4(&(graphScreen->ViewPort), spectrum, 32);
|
|
SetDrMd(&(graphScreen->RastPort), COMPLEMENT);
|
|
SetAPen(&(graphScreen->RastPort), 1);
|
|
SetAfPt(&(graphScreen->RastPort), fillPattern, 1)
|
|
|
|
graphWindow = OpenWindowTags(NULL,
|
|
WA_Left, 0,
|
|
WA_Top, 0,
|
|
WA_Width, graphWidth,
|
|
WA_Height, graphHeight,
|
|
WA_Borderless, TRUE,
|
|
WA_ReportMouse, TRUE,
|
|
WA_RMBTrap, TRUE,
|
|
WA_IDCMP, IDCMP_MOUSEMOVE |
|
|
IDCMP_MOUSEBUTTONS |
|
|
IDCMP_RAWKEY ,
|
|
WA_CustomScreen, graphScreen,
|
|
WA_SmartRefresh, TRUE,
|
|
WA_Activate, FALSE,
|
|
TAG_DONE);
|
|
if (graphWindow == NULL) return bailOut("Could not open graph window.");
|
|
|
|
SetRast(&(graphScreen->RastPort),UNDERCOLOR); /*Paint the screen black.*/
|
|
|
|
xyzScreen = OpenScreenTags(NULL,
|
|
SA_Depth, 2,
|
|
SA_DisplayID, HIRESLACE_KEY,
|
|
SA_Pens, &pens,
|
|
SA_Font, &topaz,
|
|
SA_Behind, TRUE,
|
|
SA_Title, "xyz",
|
|
SA_Type, CUSTOMSCREEN,
|
|
SA_Overscan, OSCAN_TEXT,
|
|
SA_Top, hiresRect.MaxY - 16,
|
|
SA_Width, STDSCREENWIDTH,
|
|
SA_Height, 16,
|
|
TAG_DONE);
|
|
if (xyzScreen == NULL) return bailOut("Could not open xyz screen.");
|
|
|
|
LoadRGB4(&(xyzScreen->ViewPort), CPColors, 4);
|
|
|
|
xyzVisualInfo = GetVisualInfo(xyzScreen, TAG_END);
|
|
if (xyzVisualInfo == NULL) return bailOut("Could not get xyz visual info.");
|
|
|
|
if (buildxyzGadgets() == NULL) return bailOut("Could not build xyz gadgets.");
|
|
|
|
xyzWindow = OpenWindowTags(NULL,
|
|
WA_Left, 0,
|
|
WA_Top, 0,
|
|
WA_Width, xyzScreen->Width,
|
|
WA_Height, xyzScreen->Height,
|
|
WA_CustomScreen, xyzScreen,
|
|
WA_AutoAdjust, TRUE,
|
|
WA_SmartRefresh, TRUE,
|
|
WA_Activate, FALSE,
|
|
WA_Gadgets, xyzGadgetList,
|
|
TAG_DONE);
|
|
if (xyzWindow == NULL) return bailOut("Could not open xyz window.");
|
|
|
|
CPMenu = createCPMenu();
|
|
if (CPMenu == NULL) return bailOut("Could not create menus.");
|
|
|
|
LayoutMenus(CPMenu, CPVisualInfo, TAG_END);
|
|
|
|
SetMenuStrip(CPWindow, CPMenu);
|
|
|
|
CPFileRequester = AllocAslRequestTags(ASL_FileRequest,
|
|
ASLFR_Window, CPWindow,
|
|
ASLFR_InitialTopEdge, 100,
|
|
ASLFR_InitialLeftEdge, (hiresRect.MaxX - 400)/2,
|
|
ASLFR_InitialWidth, 400,
|
|
ASLFR_PrivateIDCMP, TRUE,
|
|
ASLFR_SleepWindow, TRUE,
|
|
ASLFR_RejectIcons, TRUE,
|
|
TAG_DONE);
|
|
|
|
if (CPFileRequester == NULL) return bailOut("Could not allocate file requester.");
|
|
|
|
PubScreenStatus(CPScreen,NULL);
|
|
sprintf(inputWindowString,
|
|
"CON:%d/100/600/200/Enter your function:/SCREEN Topograph",
|
|
(hiresRect.MaxX - 600)/2);
|
|
|
|
sprintf(messageWindowString,
|
|
"CON:%d/200/400/100/Topograph message/SCREEN Topograph",
|
|
(hiresRect.MaxX - 400)/2);
|
|
|
|
*CPSignal = 1L << CPWindow->UserPort->mp_SigBit;
|
|
*graphSignal = 1L << graphWindow->UserPort->mp_SigBit;
|
|
|
|
return RETURN_OK;
|
|
}
|
|
|
|
/* Called if an object fails to open. */
|
|
int bailOut(char *userMessage){
|
|
|
|
struct EasyStruct ES = {
|
|
sizeof(struct EasyStruct),
|
|
0,
|
|
"Topograph",
|
|
"%s",
|
|
"Oh"};
|
|
|
|
if (userMessage != NULL)EasyRequest(NULL,&ES,0,userMessage);
|
|
closeUI();
|
|
return RETURN_WARN;
|
|
}
|
|
|
|
|
|
/*Free everything. */
|
|
|
|
void closeUI(){
|
|
int n;
|
|
/* This might be a window on our public screen. Gotta close it. */
|
|
closeIOConsole();
|
|
if (CPFileRequester ) FreeAslRequest(CPFileRequester);
|
|
if (CPWindow ) ClearMenuStrip(CPWindow);
|
|
if (CPMenu ) FreeMenus(CPMenu);
|
|
if (CPVisualInfo ) FreeVisualInfo(CPVisualInfo);
|
|
if (xyzVisualInfo ) FreeVisualInfo(xyzVisualInfo);
|
|
if (xyzWindow ) CloseWindow(xyzWindow);
|
|
FreeGadgets(xyzGadgetList);
|
|
if (xyzScreen ) CloseScreen(xyzScreen);
|
|
if (graphWindow ) CloseWindow(graphWindow);
|
|
if (graphScreen ) CloseScreen(graphScreen);
|
|
for (n=0; n<6; n++)
|
|
if (graphBitMap != NULL && graphBitMap->Planes[n] != NULL)
|
|
FreeRaster(graphBitMap->Planes[n],graphWidth, graphHeight);
|
|
if (graphBitMap ) FreeMem(graphBitMap, sizeof(struct BitMap));
|
|
if (CPWindow ) {
|
|
RemoveGadget(CPWindow,CPGadgets[ABORTPRINT]);
|
|
FreeGadgets(CPGadgets[ABORTPRINT]);
|
|
CloseWindow(CPWindow);
|
|
}
|
|
FreeGadgets(CPGadgetList);
|
|
if (CPScreen ) CloseScreen(CPScreen);
|
|
if (CPFont ) CloseFont(CPFont);
|
|
}
|
|
|
|
void stackScreens(void){
|
|
ScreenToFront(CPScreen);
|
|
ScreenToFront(graphScreen);
|
|
ScreenToFront(xyzScreen);
|
|
ActivateWindow(CPWindow);
|
|
}
|
|
|
|
void hideScreens(void){
|
|
ScreenToBack(xyzScreen);
|
|
ScreenToBack(graphScreen);
|
|
ScreenToBack(CPScreen);
|
|
}
|
|
|
|
void CPToFront(void){
|
|
ScreenToFront(CPScreen);
|
|
}
|
|
|
|
void noPointer(void){
|
|
SetPointer( graphWindow, emptyPointer, 1, 16, 0, 0);
|
|
}
|
|
void ticksOff(void){
|
|
ModifyIDCMP(CPWindow,CPWindow->IDCMPFlags & ~IDCMP_INTUITICKS);
|
|
ActivateWindow(CPWindow);
|
|
}
|
|
|
|
void ticksOn(void){
|
|
ModifyIDCMP(CPWindow,CPWindow->IDCMPFlags | IDCMP_INTUITICKS);
|
|
}
|