Make it build on Windows again (don't expect it to actually work sensibly
[dasher.git] / Src / Win32 / Widgets / Screen.h
blobfee5e29f6efa98243b98bcaa6c7b36ce33011540
1 // Screen.h
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002-2004 David Ward
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef __Screen_h__
10 #define __Screen_h__
12 #include "../../Common/Hash.h"
14 #include "../../DasherCore/DasherScreen.h"
15 #include "../DasherInterface.h"
16 #include "../../Common/NoClones.h"
18 #include "../GDI/FontStore.h"
20 #include <vector>
21 #include <map>
22 #include <hash_map>
24 #ifndef _WIN32_WCE
25 #include <cmath>
26 #endif
28 using namespace Dasher;
30 /////////////////////////////////////////////////////////////////////////////
32 class CScreen:public Dasher::CDasherScreen, private NoClones {
33 public:
35 CScreen(HDC hdc, Dasher::screenint width, Dasher::screenint height);
36 ~CScreen();
38 void SetInterface(CDasherInterface * DasherInterface);
39 void SetColourScheme(const Dasher::CColourIO::ColourInfo *pColours);
41 void SetFont(const std::string &strFont);
43 void DrawMousePosBox(int which, int iMousePosDist);
45 void TextSize(const std::string & String, Dasher::screenint * Width, Dasher::screenint * Height, int Size);
47 //! Draw UTF8-encoded string String of size Size positioned at x1 and y1
48 void DrawString(const std::string & String, Dasher::screenint x1, Dasher::screenint y1, int Size);
50 void DrawRectangle(Dasher::screenint x1, Dasher::screenint y1, Dasher::screenint x2, Dasher::screenint y2, int Color, int iOutlineColour, Dasher::Opts::ColorSchemes ColorScheme, bool bDrawOutlines, bool bFill, int iThickness);
52 void CScreen::DrawCircle(screenint iCX, screenint iCY, screenint iR, int iColour, int iFillColour, int iThickness, bool bFill);
54 // Draw a line of fixed colour (usually black). Intended for static UI elements such as a cross-hair
55 //! Draw a line between each of the points in the array
57 //! \param Number the number of points in the array
58 void Polyline(point * Points, int Number, int iWidth);
60 // Draw a line of arbitrary colour.
61 //! Draw a line between each of the points in the array
63 //! \param Number the number of points in the array
64 //! \param Colour the colour to be drawn
65 void Polyline(point * Points, int Number, int iWidth, int Colour);
67 // Draw a filled polygon - given vertices and color id
68 // This is not (currently) used in standard Dasher. However, it could be very
69 // useful in the future. Please implement unless it will be very difficult,
70 // in which case make this function call Polyline.
71 //! Draw a filled polygon
72 //!
73 //! \param Points array of points defining the edge of the polygon
74 //! \param Number number of points in the array
75 //! \param Color colour of the polygon (numeric)
76 virtual void Polygon(point * Points, int Number, int Color);
77 virtual void Polygon(point * Points, int Number, int Color, int iWidth);
79 void DrawPolygon(point * Points, int Number, int Color, Dasher::Opts::ColorSchemes ColorScheme);
80 void Blank();
81 void Display();
83 void SendMarker(int iMarker);
85 private:
86 const void point2POINT(const point * In, POINT * Out, int Number);
88 void TextSize_Impl(const std::string & String, Dasher::screenint * Width, Dasher::screenint * Height, int Size);
90 HDC m_hdc;
91 HDC m_hDCBuffer;
92 HDC m_hDCBufferBackground;
93 HDC m_hDCBufferDecorations;
94 HBITMAP m_hbmBitBackground; // Offscreen buffer for background
95 HBITMAP m_hbmBitDecorations; // Offscreen buffer for decorations
96 HGDIOBJ m_prevhbmBitBackground;
97 HGDIOBJ m_prevhbmBitDecorations;
98 UINT CodePage;
100 const Dasher::CColourIO::ColourInfo *m_pColours;
102 // USE GET() FUNCTIONS AS THEY CACHE TO AVOID RECREATION OF PENS/BRUSHES/FONT SIZES
103 HPEN& GetPen(int iColor, int iWidth);
104 HBRUSH& GetBrush(int iColor);
105 HFONT& GetFont(int iSize);
106 stdext::hash_map <int, HPEN> m_cPens; // Holds cached pens
107 stdext::hash_map <int, HBRUSH> m_cBrushes; // Holds cached brushes
108 stdext::hash_map <int, HFONT> m_cFonts; // Holds cached font sizes for current font
109 std::string FontName; // Shouldn't need to cache, should work on events to reset font cache
111 struct CTextSizeInput {
112 std::string m_String;
113 int m_iSize;
115 bool operator<(const CTextSizeInput & rhs) const {
116 if(m_iSize < rhs.m_iSize)
117 return true;
118 if(m_iSize > rhs.m_iSize)
119 return false;
120 return m_String < rhs.m_String;
121 } bool operator!=(const CTextSizeInput & rhs)const {
122 return ((m_iSize != rhs.m_iSize) || (m_String != rhs.m_String));
124 struct CTextSizeOutput {
125 screenint m_iWidth;
126 screenint m_iHeight;
129 struct hash_textsize {
130 enum {
131 bucket_size = 4, // 0 < bucket_size
132 min_buckets = 8 // min_buckets = 2 ^^ N, 0 < N
135 size_t operator() (const CTextSizeInput & x)const {
136 return hash_string(x.m_String.c_str()) ^ x.m_iSize;
137 } bool operator() (const CTextSizeInput & x, const CTextSizeInput & y)const {
138 return (x != y);
141 mutable std::map < CTextSizeInput, CTextSizeOutput > m_mapTextSize;
144 #include "Screen.inl"
146 #endif /* #ifndef __Screen_h__ */