File: vmemdc.cxx

package info (click to toggle)
v1 1.20-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,240 kB
  • ctags: 9,439
  • sloc: cpp: 48,033; ansic: 8,939; makefile: 1,369; sh: 30
file content (159 lines) | stat: -rw-r--r-- 4,030 bytes parent folder | download | duplicates (2)
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
//===============================================================
// vMemoryDC - a memory drawing canvas
//
// Copyright (C) 1995,1996  Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================

#include <v/vmemdc.h>
#include <v/vapp.h>

//================>>> vMemoryDC::vMemoryDC <<<========================
  vMemoryDC::vMemoryDC(int width, int height)
  {
    XColor fg;
    XColor bg;

    _physHeight = height;		// V 1.15a
    _physWidth = width;

    SysDebug(Constructor,"vMemoryDC::vMemoryDC() constructor\n")

    _GC = _XorGC = 0;

    _GCFont =
    _font = theApp->GetDefaultFont();	// get the default font

    _XDisplay = theApp->display();

    if (_physWidth == 0)
	_physWidth = theApp->DefaultWidth();
    if (_physHeight == 0)
	_physHeight = theApp->DefaultHeight();
    
    // Create the Pixmap to draw into

    _pixmap = XCreatePixmap(_XDisplay, theApp->xWindow(),
	_physWidth, _physHeight, theApp->Xdepth());

    if (_pixmap == 0)
	return;

    _GC = makeGC();		// make a normal GC to use
    _XorGC = makeXorGC();	// make a GC to use

    _pen.SetPenToPixel(_canvasFG);
    _brush.SetBrushToPixel(_canvasFG);

    SetPen(_pen);
    SetBrush(_brush);

  }

//================>>> vMemoryDC::~vMemoryDC <<<========================
  vMemoryDC::~vMemoryDC()
  {
    SysDebug(Destructor,"vMemoryDC::~vMemoryDC() destructor\n")

    if (_XorGC)					// Free the GCs
	XFreeGC(_XDisplay, _XorGC);
    if (_GC)
	XFreeGC(_XDisplay, _GC);
    if (_pixmap != 0)
	XFreePixmap(_XDisplay, _pixmap);	// free the pixmap

  }

//=====================>>> vMemoryDC::GetDrawable <<<======================
  Drawable vMemoryDC::GetDrawable()
  {
    return (Drawable) _pixmap;
  }

//=====================>>> vMemoryDC::Clear <<<==========================
  void vMemoryDC::Clear(void)
  {
    // Clear by setting to background color
    XSetForeground(_XDisplay, _GC, _canvasBG);
    XFillRectangle(_XDisplay, _pixmap, _GC, 0,0, _physWidth, _physHeight);
  }

//=====================>>> vMemoryDC::makeGC <<<=========================
  GC vMemoryDC::makeGC()
  {
    // This one gets a default GC to used for the base canvas

    GC gc;		// local copy
    XGCValues values;	// to setup values
    Pixel fg, bg;

    int n = 0;

    // set colors according to type of canvas

    _canvasFG = theApp->Xfg();
    _canvasBG = theApp->Xbg();


    values.line_style = LineSolid;	// only solid lines for now
    values.line_width = 1;		// width 1
    values.fill_style = FillSolid;
    values.function = GXcopy;
    values.foreground = _canvasFG;
    values.background = _canvasBG;

    // This not a shared GC for memory canvases.

    gc = XCreateGC(_XDisplay, GetDrawable(),
	GCForeground | GCBackground | GCFunction | GCLineStyle | 
	  GCLineWidth | GCFillStyle ,
	&values);

    // set the font

    // Be sure the font is loaded
    _font.LoadFont();

    XSetFont(theApp->display(), gc, _font.GetXFont()->fid);

    return gc;
  }

//=====================>>> vMemoryDC::makeXorGC <<<==========================
  GC vMemoryDC::makeXorGC()
  {
    // This one gets a default GC to used for the base canvas

    GC gc;		// local copy
    XGCValues values;	// to setup values

    int n = 0;

    // set colors according to type of canvas

    values.line_width = 1;		// width 1
    values.function = GXxor;

    if (_canvasFG == 0)
	values.foreground = ~0;		// force black
    else
	values.foreground = _canvasFG;

    // This not a shared GC for memory canvases.

    gc = XCreateGC(_XDisplay, GetDrawable(),
	GCForeground | GCFunction | GCLineWidth,
	&values);

    return gc;
  }

//================>>> vMemoryDC::SetBackground <<<==========================
  void vMemoryDC::SetBackground(vColor& color)
  {
    vXDC::SetBackground(color);
  }