home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
269.lha
/
MelaniePaint_v.60
/
sources
/
windows.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-16
|
12KB
|
411 lines
/*============================================================================*/
/* Windows.c: By Kevin T. Seghetti */
/*============================================================================*/
#include "equates.h"
#include <functions.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <graphics/gfx.h>
extern struct Gadget *CreateTextGadgets(),*CreateInvisibleGadgets(),*CreatePropGadget(),*CreateIntGadget(),*CreateTextGadget();
extern struct Remember *MenuRemember,*ToolRemember,*PaletteRemember,*HistRemember,*CoordRemember;
extern struct Window *MPaintWindow,*ToolWindow,*PaletteWindow,*HistWindow,*CoordWindow;
extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase *GfxBase;
extern struct Screen *MPaintScreen;
extern long ForeColor,BackColor,OutlineColor,DrawMode;
extern int MaxColor;
extern struct Menu *MPaintMenu;
extern SHORT PaintWidth,PaintHeight;
extern FLAG Grid,ValidFileName,ChoosingBackColor,PatternOn;
extern struct IntuiText *CreateIntuiText();
struct IntuiText *CoordIntuiText;
char Crd[20];
/*============================================================================*/
struct NewWindow NewPaintWindow =
{
0,0,320,200, /* leftedge, topedge, width, height */
0,1, /* DetailPen, BlockPen */
CLOSEWINDOW|MOUSEBUTTONS|MENUPICK|MOUSEMOVE, /* IDCMP flags */
SMART_REFRESH|BACKDROP|BORDERLESS|ACTIVATE|REPORTMOUSE, /* Flags */
NULL, /* Gadget List */
NULL, /* checkmark pointer */
NULL, /* window title */
NULL, /* screen pointer */
NULL, /* bitmap pointer */
20,20, /* minwidth, minheight */
320,200, /* maxwidth, maxheight */
CUSTOMSCREEN
};
/*============================================================================*/
struct NewWindow NewToolWindow =
{
200,60,100,137, /* leftedge, topedge, width, height */
0,1, /* DetailPen, BlockPen */
CLOSEWINDOW|MENUPICK|GADGETUP|MOUSEMOVE, /* IDCMP flags */
WINDOWDRAG|SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|REPORTMOUSE, /* Flags */
NULL, /* Gadget List */
NULL, /* checkmark pointer */
(UBYTE *)"Tools", /* window title */
NULL, /* screen pointer */
NULL, /* bitmap pointer */
100,124, /* minwidth, minheight */
100,124, /* maxwidth, maxheight */
CUSTOMSCREEN
};
/*============================================================================*/
struct NewWindow NewPaletteWindow =
{
100,60,100,104, /* leftedge, topedge, width, height */
0,1, /* DetailPen, BlockPen */
CLOSEWINDOW|MENUPICK|GADGETDOWN|GADGETUP|MOUSEMOVE, /* IDCMP flags */
WINDOWDRAG|SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|REPORTMOUSE, /* Flags */
NULL, /* Gadget List */
NULL, /* checkmark pointer */
(UBYTE *)"Palette", /* window title */
NULL, /* screen pointer */
NULL, /* bitmap pointer */
100,104, /* minwidth, minheight */
100,104, /* maxwidth, maxheight */
CUSTOMSCREEN
};
/*============================================================================*/
struct NewWindow NewHistWindow =
{
50,20,230,124, /* leftedge, topedge, width, height */
0,1, /* DetailPen, BlockPen */
CLOSEWINDOW|MENUPICK|GADGETDOWN|GADGETUP|MOUSEMOVE, /* IDCMP flags */
WINDOWDRAG|SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|REPORTMOUSE, /* Flags */
NULL, /* Gadget List */
NULL, /* checkmark pointer */
(UBYTE *)"Histogram", /* window title */
NULL, /* screen pointer */
NULL, /* bitmap pointer */
200,104, /* minwidth, minheight */
200,104, /* maxwidth, maxheight */
CUSTOMSCREEN
};
/*============================================================================*/
struct NewWindow NewCoordWindow =
{
10,40,85,50, /* leftedge, topedge, width, height */
0,1, /* DetailPen, BlockPen */
CLOSEWINDOW|MENUPICK|GADGETUP|MOUSEMOVE, /* IDCMP flags */
WINDOWDRAG|SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|REPORTMOUSE, /* Flags */
NULL, /* Gadget List */
NULL, /* checkmark pointer */
(UBYTE *)"Coords", /* window title */
NULL, /* screen pointer */
NULL, /* bitmap pointer */
85,50, /* minwidth, minheight */
85,50, /* maxwidth, maxheight */
CUSTOMSCREEN
};
/*============================================================================*/
void
InitWindow()
{
struct Window *TempWindow;
NewPaintWindow.Screen = MPaintScreen;
NewPaintWindow.Width = PaintWidth;
NewPaintWindow.Height = PaintHeight;
TempWindow = OpenWindow(&NewPaintWindow);
if(!TempWindow)
cleanup("Cannot open paint window",5);
SetMenuStrip(TempWindow,MPaintMenu);
MPaintWindow = TempWindow;
ValidFileName = FALSE;
}
/*============================================================================*/
char *ToolBoxText[] =
{
"Undo",
"Dot",
"CLine",
"Line",
"UBox",
"FBox",
NULL
};
char *ToolBoxText2[] =
{
"Circl",
"Ellip",
"Fill",
"Flood",
"Clear",
"Pick",
NULL
};
char *PaletteText[] =
{
"R+",
"G+",
"B+",
NULL
};
char *PaletteText2[] =
{
"R-",
"G-",
"B-",
NULL
};
char *PaletteText3[] =
{
"Copy",
"Xchg",
NULL
};
/*============================================================================*/
void
OpenToolWindow()
{ int i;
struct Window *TempWindow;
struct Gadget *TempGadget;
ToolRemember = NULL;
NewToolWindow.Screen = MPaintScreen;
NewToolWindow.FirstGadget = CreateTextGadgets(ToolBoxText,5,12,&ToolRemember,TOOL_GADG_UNDO);
TempGadget = CreateTextGadgets(ToolBoxText2,50,12,&ToolRemember,TOOL_GADG_CIRCLE);
AddGadgetsToList(NewToolWindow.FirstGadget,TempGadget);
TempGadget = CreateTextGadget("B",85,95,&ToolRemember,TOOL_GADG_BACK);
AddGadgetsToList(NewToolWindow.FirstGadget,TempGadget);
TempGadget->Activation |= TOGGLESELECT;
if(ChoosingBackColor)
TempGadget->Flags |= SELECTED;
TempGadget = CreateTextGadget("P",85,110,&ToolRemember,TOOL_GADG_PATTERN);
AddGadgetsToList(NewToolWindow.FirstGadget,TempGadget);
TempGadget->Activation |= TOGGLESELECT;
if(PatternOn)
TempGadget->Flags |= SELECTED;
if(MaxColor == 2)
{ TempGadget = CreateInvisibleGadgets(2,5,TOOL_COLOR_HEIGHT+9,7,6,&ToolRemember,(USHORT)0);
AddGadgetsToList(NewToolWindow.FirstGadget,TempGadget);
}
else for(i=0;i<(MaxColor/4);++i)
{ TempGadget = CreateInvisibleGadgets(4,5+(10*i),TOOL_COLOR_HEIGHT+9,7,6,&ToolRemember,(USHORT)4*i);
AddGadgetsToList(NewToolWindow.FirstGadget,TempGadget);
}
TempWindow = OpenWindow(&NewToolWindow);
if(!TempWindow)
CloseToolWindow();
if(MaxColor == 2)
DrawColoredRow(TempWindow->RPort,2,5L,(long)TOOL_COLOR_HEIGHT+9,6L,0L);
else for(i=0;i<(MaxColor/4);++i)
DrawColoredRow(TempWindow->RPort,4,5L+(10*i),(long)TOOL_COLOR_HEIGHT+9,6L,(long)i*4);
ToolWindow = TempWindow;
SetForeColor((long)ForeColor);
SetBackColor((long)BackColor);
SetMenuStrip(ToolWindow,MPaintMenu);
}
/*============================================================================*/
CloseToolWindow()
{
/* NewToolWindow.LeftEdge = ToolWindow->LeftEdge;
NewToolWindow.TopEdge = ToolWindow->TopEdge;
*/
if(ToolWindow)
{
ClearMenuStrip(ToolWindow);
CloseWindow(ToolWindow);
}
ToolWindow = NULL;
if(ToolRemember)
FreeRemember(&ToolRemember,(long)TRUE);
}
/*============================================================================*/
void
OpenPaletteWindow()
{
int i;
struct Window *TempWindow;
struct Gadget *TempGadget;
PaletteRemember = NULL;
NewPaletteWindow.Screen = MPaintScreen;
NewPaletteWindow.FirstGadget = CreateTextGadgets(PaletteText,52,12,&PaletteRemember,PALETTE_GADG_RED_PLUS2);
TempGadget = CreateTextGadgets(PaletteText2,75,12,&PaletteRemember,PALETTE_GADG_RED_MINUS2);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
TempGadget = CreateTextGadgets(PaletteText3,52,48,&PaletteRemember,PALETTE_GADG_COPY);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
TempGadget = CreatePropGadget(10,12,10,45,&PaletteRemember,PALETTE_GADG_PROP_RED);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
TempGadget = CreatePropGadget(20,12,10,45,&PaletteRemember,PALETTE_GADG_PROP_GREEN);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
TempGadget = CreatePropGadget(30,12,10,45,&PaletteRemember,PALETTE_GADG_PROP_BLUE);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
if(MaxColor == 2)
{ TempGadget = CreateInvisibleGadgets(2,5,71,7,6,&PaletteRemember,(USHORT)0);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
}
else for(i=0;i<(MaxColor/4);++i)
{ TempGadget = CreateInvisibleGadgets(4,5+(10*i),71,7,6,&PaletteRemember,(USHORT)4*i);
AddGadgetsToList(NewPaletteWindow.FirstGadget,TempGadget);
}
TempWindow = OpenWindow(&NewPaletteWindow);
if(!TempWindow)
ClosePaletteWindow();
if(MaxColor == 2)
DrawColoredRow(TempWindow->RPort,2,5L,71L,6L,0L);
for(i=0;i<(MaxColor/4);++i)
DrawColoredRow(TempWindow->RPort,4,5L+(10*i),71L,6L,(long)i*4);
PaletteWindow = TempWindow;
SetForeColor((long)ForeColor);
SetMenuStrip(PaletteWindow,MPaintMenu);
}
/*============================================================================*/
ClosePaletteWindow()
{
/* NewPaletteWindow.LeftEdge = PaletteWindow->LeftEdge;
NewPaletteWindow.TopEdge = PaletteWindow->TopEdge;
*/
if(PaletteWindow)
{
ClearMenuStrip(PaletteWindow);
CloseWindow(PaletteWindow);
}
PaletteWindow = NULL;
if(PaletteRemember)
FreeRemember(&PaletteRemember,(long)TRUE);
}
/*============================================================================*/
OpenHistWindow()
{
int i;
struct Window *TempWindow;
struct Gadget *TempGadget;
HistRemember = NULL;
NewHistWindow.Screen = MPaintScreen;
TempWindow = OpenWindow(&NewHistWindow);
if(!TempWindow)
CloseHistWindow();
HistWindow = TempWindow;
SetMenuStrip(HistWindow,MPaintMenu);
DoHist();
PrintHist();
}
/*============================================================================*/
CloseHistWindow()
{
/* NewHistWindow.LeftEdge = HistWindow->LeftEdge;
NewHistWindow.TopEdge = HistWindow->TopEdge;
*/
if(HistWindow)
{
ClearMenuStrip(HistWindow);
CloseWindow(HistWindow);
}
HistWindow = NULL;
if(HistRemember)
FreeRemember(&HistRemember,(long)TRUE);
}
/*============================================================================*/
OpenCoordWindow()
{
int i;
struct Window *TempWindow;
struct Gadget *TempGadget;
CoordRemember = NULL;
NewCoordWindow.Screen = MPaintScreen;
TempGadget = CreateTextGadget("Grid",20,24,&CoordRemember,COORD_GADG_GRID);
TempGadget->Activation = RELVERIFY|TOGGLESELECT;
if(Grid)
TempGadget->Flags |= SELECTED;
NewCoordWindow.FirstGadget = TempGadget;
TempGadget = CreateIntGadget("10",5,37,&CoordRemember,COORD_GADG_GRIDX);
AddGadgetsToList(NewCoordWindow.FirstGadget,TempGadget);
TempGadget = CreateIntGadget("10",45,37,&CoordRemember,COORD_GADG_GRIDY);
AddGadgetsToList(NewCoordWindow.FirstGadget,TempGadget);
CoordIntuiText = CreateIntuiText(Crd,&CoordRemember);
CoordIntuiText->DrawMode = JAM2;
TempWindow = OpenWindow(&NewCoordWindow);
if(!TempWindow)
CloseCoordWindow();
CoordWindow = TempWindow;
SetAPen(TempWindow->RPort,1L);
Move(TempWindow->RPort,0L,20L);
Draw(TempWindow->RPort,81L,20L);
SetMenuStrip(CoordWindow,MPaintMenu);
}
/*============================================================================*/
CloseCoordWindow()
{
/* NewCoordWindow.LeftEdge = CoordWindow->LeftEdge;
NewCoordWindow.TopEdge = CoordWindow->TopEdge;
*/
if(CoordWindow)
{
ClearMenuStrip(CoordWindow);
CloseWindow(CoordWindow);
}
CoordWindow = NULL;
if(CoordRemember)
FreeRemember(&CoordRemember,(long)TRUE);
}