Make it build on Windows again (don't expect it to actually work sensibly
[dasher.git] / Src / Win32 / Widgets / Screen.inl
blob02031672ba3ff63bcf6847cb755ae045df4b325e
1 // Screen.inl
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 David Ward
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 /////////////////////////////////////////////////////////////////////////////
11 inline void CScreen::DrawRectangle(screenint x1, screenint y1, screenint x2, screenint y2, int Color, int iOutlineColour, Dasher::Opts::ColorSchemes ColorScheme, bool bDrawOutlines, bool bFill, int iThickness) {
12 //      HBRUSH brush=m_Brushes[ColorScheme][Color%m_Brushes[ColorScheme].size()];
13   HBRUSH brush = CScreen::GetBrush(Color);
14   RECT Rect;
15   Rect.left = x1;
16   Rect.top = y1;
17   Rect.right = x2;
18   Rect.bottom = y2;
19   if(bFill)
20     FillRect(m_hDCBuffer, &Rect, brush);
22 #ifndef DASHER_WINCE
24   if(bDrawOutlines) {
26     point aPoints[5];
28     aPoints[0].x=x1; aPoints[0].y=y1;
29     aPoints[1].x=x2; aPoints[1].y=y1;
30     aPoints[2].x=x2; aPoints[2].y=y2;
31     aPoints[3].x=x1; aPoints[3].y=y2;
32     aPoints[4].x=x1; aPoints[4].y=y1;
34     if(iOutlineColour == -1)
35      //FrameRect(m_hDCBuffer, &Rect, CScreen::GetBrush(3));
36      Polyline(aPoints, 5, iThickness, 3);
37     else
38       //FrameRect(m_hDCBuffer, &Rect, CScreen::GetBrush(iOutlineColour));
39       Polyline(aPoints, 5, iThickness, iOutlineColour);
40   }
41 #endif
45 inline void CScreen::DrawCircle(screenint iCX, screenint iCY, screenint iR, int iColour, int iFillColour, int iThickness, bool bFill) {
46   HGDIOBJ hpOld;
47   hpOld = (HPEN) SelectObject(m_hDCBuffer, GetPen(iColour, iThickness));
49   if(bFill) {
50     HBRUSH hBrush = CScreen::GetBrush(iFillColour);
51     HBRUSH hBrushOld;
52     hBrushOld = (HBRUSH)SelectObject(m_hDCBuffer, hBrush);
53   
54     Ellipse(m_hDCBuffer, iCX - iR, iCY - iR, iCX + iR, iCY + iR);
56     SelectObject(m_hDCBuffer, hBrushOld);
57   }
58   else
59     Arc(m_hDCBuffer, iCX - iR, iCY - iR, iCX + iR, iCY + iR,
60                      iCX, iCY - iR, iCX, iCY - iR );
62   SelectObject(m_hDCBuffer, hpOld);
65 inline void CScreen::Polyline(point *Points, int Number, int iWidth, int iColour) {
66   HGDIOBJ hpOld;
67   hpOld = (HPEN) SelectObject(m_hDCBuffer, GetPen(iColour, iWidth));
68   POINT *WinPoints = new POINT[Number];
69   point2POINT(Points, WinPoints, Number);
70   ::Polyline(m_hDCBuffer, WinPoints, Number);
71   delete[]WinPoints;
72   SelectObject(m_hDCBuffer, hpOld);
75 inline void CScreen::Polyline(point *Points, int Number, int iWidth) {
76   Polyline(Points, Number, iWidth, 0);
79 inline void CScreen::DrawPolygon(point *Points, int Number, int Color, Dasher::Opts::ColorSchemes ColorScheme) {
80   HPEN pen = (HPEN) GetStockObject(NULL_PEN);
81   HPEN hpold = (HPEN) SelectObject(m_hDCBuffer, pen);
82   HBRUSH hbold = (HBRUSH) SelectObject(m_hDCBuffer, CScreen::GetBrush(ColorScheme));
83   POINT *WinPoints = new POINT[Number];
84   point2POINT(Points, WinPoints, Number);
85   ::Polygon(m_hDCBuffer, WinPoints, Number);
86   delete[]WinPoints;
87   SelectObject(m_hDCBuffer, hpold);
88   SelectObject(m_hDCBuffer, hbold);
91 inline void CScreen::Blank() {
92   RECT rect;
93   rect.top = 0;
94   rect.right = long (m_iWidth);
95   rect.bottom = long (m_iHeight);
96   rect.left = 0;
97   FillRect(m_hDCBuffer, &rect, (HBRUSH) GetStockObject(WHITE_BRUSH));
100 inline void CScreen::Display() {
101   BitBlt(m_hdc, 0, 0, m_iWidth, m_iHeight, m_hDCBuffer, 0, 0, SRCCOPY);
104 inline const void CScreen::point2POINT(const point *In, POINT *Out, int Number) {
105   // Yuck!
106   for(int i = 0; i < Number; i++) {
107     Out[i].x = In[i].x;
108     Out[i].y = In[i].y;
109   }
112 inline HPEN& CScreen::GetPen(int iColor, int iWidth) {
113   stdext::hash_map <int, HPEN> :: const_iterator hm1_RcIter;
114   int key = iColor+iWidth*256;
116   hm1_RcIter = m_cPens.find( key );
117   if( hm1_RcIter == m_cPens.end() ) {
118     HPEN pen = CreatePen(PS_SOLID, iWidth, RGB(m_pColours->Reds[iColor], m_pColours->Greens[iColor], m_pColours->Blues[iColor]));
119     m_cPens[key] = pen;
120   }
121   
122   return m_cPens[key];
125 inline HBRUSH& CScreen::GetBrush(int iColor) {
126   stdext::hash_map <int, HBRUSH> :: const_iterator hm1_RcIter;
127   int key = iColor;
129   hm1_RcIter = m_cBrushes.find( key );
130   if( hm1_RcIter == m_cBrushes.end() ) {
131     HBRUSH brush = CreateSolidBrush(RGB(m_pColours->Reds[iColor], m_pColours->Greens[iColor], m_pColours->Blues[iColor]));
132     m_cBrushes[key] = brush;
133   }
134   
135   return m_cBrushes[key];
138 inline void CScreen::SetFont(const std::string &strFont) {
139   if(FontName != strFont) {
140     FontName = strFont;
141      for(stdext::hash_map<int, HFONT>::const_iterator it(m_cFonts.begin()); it != m_cFonts.end(); ++it)
142            DeleteObject(it->second);
143     m_cFonts.clear();
144   }
147 inline HFONT& CScreen::GetFont(int iSize) {
148   // TODO: Reimplement
149   //if(FontName != m_pDasherInterface->GetStringParameter(SP_DASHER_FONT)) {
150   //  FontName = m_pDasherInterface->GetStringParameter(SP_DASHER_FONT);
151   //   for(stdext::hash_map<int, HFONT>::const_iterator it(m_cFonts.begin()); it != m_cFonts.end(); ++it)
152   //           DeleteObject(it->second);
153   //  m_cFonts.clear();
154   //}
156   if (iSize > 50) // ???? Is there a limit to size, should it be a setting?
157     iSize = 50;
159   stdext::hash_map <int, HFONT> :: const_iterator hm1_RcIter;
160   int key = iSize;
162   std::wstring wstrOutput;
163   WinUTF8::UTF8string_to_wstring(FontName, wstrOutput);
165   hm1_RcIter = m_cFonts.find( key );
166   if( hm1_RcIter == m_cFonts.end() ) {
167     HFONT font = CreateFont(int (-iSize), 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, LPCWSTR(wstrOutput.c_str())); // DEFAULT_CHARSET => font made just from Size and FontName
168     m_cFonts[key] = font;
169   }
170   
171   return m_cFonts[key];