1 // This file is part of the utio library, a terminal I/O library.
3 // Copyright (C) 2004 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
9 #ifndef GC_H_2E08A62D1060EA48355708BC7A3C12AF
10 #define GC_H_2E08A62D1060EA48355708BC7A3C12AF
17 /// \brief Graphics context.
19 /// Can be used to draw into a character cell array. Quite useful for
20 /// internal buffer (Canvas()).
24 typedef vector
<CCharCell
> canvas_t
; ///< Type of the output buffer.
25 typedef gdt::coord_t coord_t
;
26 typedef gdt::dim_t dim_t
;
27 typedef gdt::Point2d Point2d
;
28 typedef gdt::Size2d Size2d
;
29 typedef gdt::Rect Rect
;
32 void Clear (wchar_t c
= ' ');
34 void Bar (Rect r
, wchar_t c
= ' ');
35 void HLine (Point2d p
, dim_t l
);
36 void VLine (Point2d p
, dim_t l
);
37 void GetImage (Rect r
, canvas_t
& cells
) const;
38 void Image (Rect r
, const canvas_t
& cells
);
39 void Char (Point2d p
, wchar_t c
);
40 void Text (Point2d p
, const string
& str
);
41 inline const canvas_t
& Canvas (void) const { return (m_Canvas
); }
42 inline canvas_t
& Canvas (void) { return (m_Canvas
); }
43 inline const Size2d
& Size (void) const { return (m_Size
); }
44 inline dim_t
Width (void) const { return (m_Size
[0]); }
45 inline dim_t
Height (void) const { return (m_Size
[1]); }
46 inline void Box (coord_t x
, coord_t y
, dim_t w
, dim_t h
) { Box (Rect (x
, y
, w
, h
)); }
47 inline void Bar (coord_t x
, coord_t y
, dim_t w
, dim_t h
, wchar_t c
= ' ') { Bar (Rect (x
, y
, w
, h
), c
); }
48 inline void HLine (coord_t x
, coord_t y
, dim_t l
) { HLine (Point2d (x
, y
), l
); }
49 inline void VLine (coord_t x
, coord_t y
, dim_t l
) { VLine (Point2d (x
, y
), l
); }
50 inline void GetImage (coord_t x
, coord_t y
, dim_t w
, dim_t h
, canvas_t
& cells
) { GetImage (Rect (x
, y
, w
, h
), cells
); }
51 inline void Image (coord_t x
, coord_t y
, dim_t w
, dim_t h
, const canvas_t
& cells
) { Image (Rect (x
, y
, w
, h
), cells
); }
52 inline void Image (const CGC
& cells
) { Image (Rect (0, 0, cells
.Width(), cells
.Height()), cells
.Canvas()); }
53 inline void Char (coord_t x
, coord_t y
, wchar_t c
) { Char (Point2d (x
, y
), c
); }
54 inline void Text (coord_t x
, coord_t y
, const string
& str
) { Text (Point2d (x
, y
), str
); }
55 inline void FgColor (EColor c
) { m_Template
.m_FgColor
= c
; }
56 inline void BgColor (EColor c
) { m_Template
.m_BgColor
= c
; }
57 inline void Color (EColor fg
, EColor bg
= color_Preserve
) { FgColor(fg
); BgColor(bg
); }
58 inline void AttrOn (EAttribute a
) { m_Template
.SetAttr (a
); }
59 inline void AttrOff (EAttribute a
) { m_Template
.ClearAttr (a
); }
60 inline void AllAttrsOff (void) { m_Template
.m_Attrs
= 0; }
61 inline void Resize (dim_t x
,dim_t y
){ Resize (Size2d (x
, y
)); }
62 void Resize (Size2d sz
);
63 bool Clip (Rect
& r
) const;
64 bool Clip (Point2d
& r
) const;
65 inline void SetTabSize (size_t nts
= 8) { assert (nts
&& "Tab size can not be 0"); m_TabSize
= nts
; }
66 bool MakeDiffFrom (const CGC
& src
);
68 inline canvas_t::iterator
CanvasAt (Point2d p
);
69 inline canvas_t::const_iterator
CanvasAt (Point2d p
) const;
71 canvas_t m_Canvas
; ///< The output buffer.
72 CCharCell m_Template
; ///< Current drawing values.
73 Size2d m_Size
; ///< Size of the output buffer.
74 uint32_t m_TabSize
; ///< Tab size as expanded by Text