VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gxcontext.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // gxcontext.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gxdef.h"
23 #include "gxcontext.h"
24 #include "gxdisplay.h"
25 #include "gxdrawable.h"
26 #include "gxerror.h"
27 
28 GX::Context::Context( Display & display , Drawable & drawable ) :
29  m_display(display) ,
30  m_owned(true)
31 {
32  unsigned long value_mask = 0UL ;
33  XGCValues * values = nullptr ;
34  m_context = XCreateGC( display.x() , drawable.xd() , value_mask , values ) ;
35 }
36 
37 GX::Context::Context( Display & display , ::GC gc ) :
38  m_display(display) ,
39  m_context(gc) ,
40  m_owned(false)
41 {
42 }
43 
44 GX::Context::Context( const Context & other ) :
45  m_display(other.m_display) ,
46  m_context(other.m_context) ,
47  m_owned(other.m_owned)
48 {
49 }
50 
52 {
53  try
54  {
55  if( m_owned )
56  XFreeGC( m_display.x() , m_context ) ;
57  }
58  catch(...)
59  {
60  }
61 }
62 
64 {
65  return m_context ;
66 }
67 
68 void GX::Context::setForeground( unsigned long c )
69 {
70  XSetForeground( m_display.x() , m_context , c ) ;
71 }
72 
73 void GX::Context::setLineWidth( unsigned long n )
74 {
75  XSetLineAttributes( m_display.x() , m_context , n ,
76  LineSolid , CapRound , JoinRound ) ;
77 }
78 
79 
80 /// \file gxcontext.cpp
::Display * x()
Returns the X object.
Definition: gxdisplay.cpp:53
An Xlib Display wrapper.
Definition: gxdisplay.h:38
::GC x()
Returns the X object.
Definition: gxcontext.cpp:63
virtual ::Drawable xd()=0
Returns the X object.
void setLineWidth(unsigned long)
Sets the line width.
Definition: gxcontext.cpp:73
An Xlib GC wrapper.
Definition: gxcontext.h:37
void setForeground(unsigned long cc)
Sets the foreground drawing colour.
Definition: gxcontext.cpp:68
Context(Display &, Drawable &)
Constructor for a new graphics context.
Definition: gxcontext.cpp:28
An abstract base class for xserver-side drawables (windows, pixmaps, etc) with methods for drawing po...
Definition: gxdrawable.h:38
~Context()
Destructor.
Definition: gxcontext.cpp:51