First checkin, AXE release 0.2
[AXE.git] / src / gc.h
1 /**************************************************************************
2 **  (c) Copyright 1998, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : gc.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.1 $
9 **
10 **  DESCRIPTION      : Definition of gc class 
11 **
12 **  EXPORTED OBJECTS : class gc
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Feb 22, 1998
20 **      LAST UPDATE     : Oct 28, 1999
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: gc.h,v $
26    Revision 1.1  2002-07-25 08:01:27  arjen
27    First checkin, AXE release 0.2
28
29 *****************************/
30
31 /* static const char *RCSID = "$Id: gc.h,v 1.1 2002-07-25 08:01:27 arjen Exp $"; */
32
33 #include <X11/Xlib.h>
34 #include "display.h"
35 #include "color.h"
36 #include "font.h"
37 #include "pattern.h"
38
39 /*
40 ///////////////////////////////////////////////////////////////////////////
41 //  NAME           : gc
42 //  BASECLASS      :
43 //  MEMBERS        : XID gc_id
44 //  OPERATORS      :
45 //  METHODS        :
46 //
47 //  DESCRIPTION    :
48 //
49 //  RELATIONS      :
50 //  SEE ALSO       :
51 //  LAST MODIFIED  : Oct 28, 1999
52 ///////////////////////////////////////////////////////////////////////////
53 */
54
55 class gc
56 {
57    GC  gc_id;
58
59 public:
60
61    gc()
62    {
63       gc_id = 0;
64    }
65
66    gc(const color &fg)
67    {
68       gc_id = XCreateGC(stddpy, stddpy.Root(), 0, 0);
69       XSetForeground(stddpy, gc_id, fg);
70    }
71
72    gc(font &fn, color &fg)
73    {
74       gc_id = XCreateGC(stddpy, stddpy.Root(), 0, 0);
75       if (fn)
76       {
77          XSetFont(stddpy, gc_id, fn);
78       }
79       XSetForeground(stddpy, gc_id, fg);
80    }
81
82    gc(font &fn, color &fg, stipple &stip)
83    {
84       gc_id = XCreateGC(stddpy, stddpy.Root(), 0, 0);
85       if (fn)
86       {
87          XSetFont(stddpy, gc_id, fn);
88       }
89       XSetForeground(stddpy, gc_id, fg);
90       XSetStipple(stddpy, gc_id, stip);
91       XSetFillStyle(stddpy, gc_id, FillStippled);
92
93    }
94
95    ~gc()
96    {
97       XFreeGC(stddpy, gc_id);
98    }
99
100    operator GC() const
101    {
102       return gc_id;
103    }
104
105    void Create()
106    {
107       gc_id = XCreateGC(stddpy, stddpy.Root(), 0, 0);
108    }
109
110    void SetFunction(int func)
111    {
112       XSetFunction(stddpy, gc_id, func);
113    }
114
115    void SetForeground(unsigned long fg)
116    {
117       XSetForeground(stddpy, gc_id, fg);
118    }
119
120    void SetBackground(unsigned long fg)
121    {
122       XSetBackground(stddpy, gc_id, fg);
123    }
124
125    void SetFont(font &fn)
126    {
127       if (fn)
128       {
129          XSetFont(stddpy, gc_id, fn);
130       }
131    }
132
133    void SetLineAttributes(unsigned width, int line_style = LineSolid,
134                            int cap_style = CapButt, int join_style = JoinMiter)
135    {
136       XSetLineAttributes(stddpy, gc_id, width, line_style,
137                                     cap_style, join_style);
138    }
139 };
140