aboutsummaryrefslogtreecommitdiff
path: root/SPARE.C
blob: 1426049f07c73c52035d4f4fc18a32246912f912 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*----------------------------------------------------------------------*/
/*									*/
/*		spare.c  - Spare screen					*/
/*									*/
/*----------------------------------------------------------------------*/

#include "system.h"
#include "prism.h"

#define local static

extern struct BitMap hidbm;
extern struct ViewPort *vport;
extern SHORT nColors, curxpc;

extern struct RastPort *curRP;
extern MagContext magCntxt;
extern struct TmpRas tmpRas;
extern Box screenBox, clipBox;
extern SHORT curDepth;


extern BOOL spareThere;
extern BOOL newSpare;
extern SHORT spareXPCol;
extern struct BitMap sparebm;
extern SHORT didType;

local void NotEnough() {
    UndoSave();
    InfoMessage("Insufficient Memory","for Spare Screen");
    }
    
local BOOL AllocSpare() {
    LONG freeMem,imSize;
    if (!spareThere) {
	freeMem = AvailMem(MEMF_CHIP|MEMF_PUBLIC);
	imSize = hidbm.BytesPerRow*hidbm.Rows*hidbm.Depth;
	if (freeMem < (2*imSize)) { NotEnough(); return((BOOL)FAIL); }
	InitBitMap(&sparebm,curDepth,screenBox.w,screenBox.h);
	if (AllocBitMap(&sparebm)) { NotEnough(); return((BOOL)FAIL);} 
	SetBitMap(&sparebm,0);
	spareThere = YES;
	}
    return(SUCCESS);
    }

void SwapSpare() {
    struct BitMap mytemp;
    SHORT tmp;
    if (AllocSpare()) return;
    UndoSave();
    KillCCyc();
    mytemp = hidbm;
    hidbm = sparebm;
    sparebm = mytemp;
    tmp = spareXPCol;
    spareXPCol = curxpc;
    if (!newSpare) { CPChgBg(tmp); }
    newSpare = NO;
    UpdtDisplay();
    }

void CopyToSpare() {
    if (AllocSpare()) return;
    UndoSave();
    CopyBitMap(&hidbm,&sparebm);
    spareXPCol = curxpc;
    newSpare = NO;
    }
           

extern SHORT xorg,yorg;
    
local BOOL inFront;

local MakeMrgMask() {
    if (inFront) 
	MakeMask(&sparebm, tmpRas.RasPtr, spareXPCol, NEGATIVE);
    else  MakeMask(&hidbm, tmpRas.RasPtr, curxpc, POSITIVE);
    }
	
void MergeSpare() {
    BYTE *mask = tmpRas.RasPtr;
    Point spos,dpos;
    if (spareThere) {
	UndoSave();
	spos.x = xorg;	spos.y = yorg;
	dpos.x = dpos.y = 0;
	MakeMrgMask();
	MaskBlit(&sparebm, &spos, mask, curRP->BitMap,&dpos, &screenBox,
	    &clipBox, COOKIEOP, mask, 0xff, 0);
	MagUpdate(&screenBox);
	didType = DIDMerge;
	}
    }

void MrgSpareFront() { inFront = YES; MergeSpare(); }
void MrgSpareBack() { inFront = NO; MergeSpare(); }
    
MrgSpareUpdt() {
    Point pos;
    pos.x = pos.y = 0;
    MakeMrgMask();
    MaskBlit(&sparebm, &pos, tmpRas.RasPtr, &hidbm, &pos, &screenBox,
	&screenBox, COOKIEOP, tmpRas.RasPtr, 0xff, 0);
    }