aboutsummaryrefslogtreecommitdiff
path: root/CURBRUSH.C
blob: c1bde476c632d947bd62bfe225e9af7890bc66c4 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*----------------------------------------------------------------------*/
/*  									*/
/*        curbrush.c -- The current brush & pen				*/
/*  									*/
/*----------------------------------------------------------------------*/
#include <system.h>
#include <prism.h>

extern short xShft, yShft;
extern Box screenBox;
extern SHORT prevColors[];
extern SHORT LoadBrColors[32];
extern struct BitMap brBM,brSVBM;
extern BMOB curbr;
extern SHORT curpen;
extern struct BitMap penBM,penSVBM;
extern BMOB curpenob;
extern BOOL modeHelp;

#define local static 

BOOL LegalMode(i) int i; {
    if (modeHelp)
	return((BOOL)! ( (curpen!=USERBRUSH) && ((i==Mask)||(i==Replace)) ) );
    else  return((BOOL)YES);
    }

BOOL BrushDefined() { return((BOOL)(curbr.pict.bm->Planes[0] != NULL)); }

UseBrPalette() { if (curpen==USERBRUSH) {
	GetColors(prevColors);
	LoadCMap(LoadBrColors);
	}
    }
    
/* Pens have only a MASK and no source bit-planes.  FixUpPen
   fixes pen data structure to reflect this */
local FixUpPen() {
    curpenob.xpcolor = 0;
    curpenob.minTerm = COOKIEOP;
    DFree(curpenob.mask);
    curpenob.mask = penBM.Planes[0];
    penBM.Planes[0] = (APTR)0;
    penBM.Depth = 0;
    curpenob.planeUse = 0;
    curpenob.planeDef = 0; 
    curpenob.xoffs = curpenob.pict.box.w/2;
    curpenob.yoffs = curpenob.pict.box.h/2;
    }

local SzPen() { return(NewSizeBitMap(curpenob.pict.bm,1,
	    curpenob.pict.box.w,curpenob.pict.box.h));}

local SizePenBM() {
    if (SzPen()) {
	FreeBMOB(&curbr);
	if (SzPen()) return(FAIL);
	}
    ClearBitMap(&penBM);
    return(SUCCESS);
    }

/* ------------- Circular Pen radius r: 
    r is in VDC (virtual device coords )
*/ 
RoundPen(r) SHORT r; {
    struct RastPort crp;
    SHORT rx,ry;
    rx = PMapX(r);
    ry = MAX(PMapY(r),1);
    MakeBox(&curpenob.pict.box,0,0,2*rx+1,2*ry+1);
    InitRastPort(&crp);
    SizePenBM();
    crp.BitMap = &penBM;
    SetAPen(&crp,15);
    PushGrDest(&crp,&screenBox); /* any large box with x=y=0 will do */
    PFillCirc(rx,ry,rx);
    PopGrDest();
    FixUpPen();
    }

OneBitPen() {
    MakeBox(&curpenob.pict.box,0,0,1,1);
    NewSizeBitMap(&penBM,1,1,1);
    *((SHORT *)penBM.Planes[0]) = 0x8000;
    FixUpPen();
    }

    
/*---------------- Square Pen side s ------------- */ 
SquarePen(s) SHORT s; {
    struct RastPort crp;
    SHORT pw = PMapX(s);
    SHORT ph = PMapY(s);
    MakeBox(&curpenob.pict.box,0,0,pw,ph);
    InitRastPort(&crp);
    SizePenBM();
    crp.BitMap = &penBM;
    SetAPen(&crp,15);
    WaitBlit();
    RectFill(&crp,0,0,pw-1,ph-1);
    FixUpPen();
    }

#define NPENS	9

#ifdef fromprism_h
/* Pen TYPE ENcoding */
#define USERBRUSH -1
#define ROUND_B		1
#define SQUARE_B	2
#define DOT_B		3
#define AIR_B		4    
#define RoundB(n)	((ROUND_B<<12)|n)
#define SquareB(n)	((SQUARE_B<<12)|n)
#define DotB(n)		((DOT_B<<12)|n)
#define AirB		AIR_B<<12

#endif



/* dot pens ---------------- */
extern UWORD dots10[],dots20[],dots30[],dots40[],dots50[],dots60[];
UWORD *dotbms[] = { dots10, dots20, dots30, dots40, dots50, dots60};

DotBFromRad(r) int r; {  return( DotB(r/2));  }

DotsPen(s) int s; {
    int pensz;
    s = MIN(6, MAX(1,s));
    pensz = 4*s+1;
    MakeBox(&curpenob.pict.box,0,0,pensz,pensz);
    SizePenBM();
    movmem(dotbms[s-1], penBM.Planes[0], BytesNeeded(pensz)*pensz);
    FixUpPen();
    }

/** Select a builtin Pen --------------- */
        
void SelPen(n) int n; {
    int type,size;
    if (n==USERBRUSH) { 
	if (!BrushDefined()) return; 
	else UseBrush(); 
	}
    else {
	if (n==0) OneBitPen(); 
	else {
	    type = (n>>12)&0xf;
	    size = n&0xfff;
	    switch(type) {
		case ROUND_B: size = MIN(size,50); RoundPen(VMapY(size)); break;
		case SQUARE_B: size = MIN(size,100); SquarePen(VMapY(size)); break;
		case DOT_B: DotsPen(size); break;
		default: break;
		}
	    n = (n&0xf000)|size;
	    }
	if (curpen==USERBRUSH){
	    curpen=n;	/* have to do this first so LegalMode() works right*/
	    if (modeHelp) SetModeMenu(Color);
	    }
	UsePen();
	}
    curpen = n;
    FixUsePen();	/* this updates the usePen variable*/
    ResetCursor();
    }