]> git.saurik.com Git - wxWidgets.git/blob - src/common/effects.cpp
Fix VC6 compilation after r73880.
[wxWidgets.git] / src / common / effects.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/effects.cpp
3 // Purpose: wxEffectsImpl implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 25/4/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #include "wx/effects.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/dcmemory.h"
23 #include "wx/pen.h"
24 #include "wx/settings.h"
25 #include "wx/gdicmn.h"
26 #endif //WX_PRECOMP
27
28 #if WXWIN_COMPATIBILITY_2_8
29
30 /*
31 * wxEffectsImpl: various 3D effects
32 */
33
34 IMPLEMENT_CLASS(wxEffectsImpl, wxObject)
35
36 // Assume system colours
37 wxEffectsImpl::wxEffectsImpl()
38 {
39 m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT) ;
40 m_lightShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT) ;
41 m_faceColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) ;
42 m_mediumShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ;
43 m_darkShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW) ;
44 }
45
46 // Going from lightest to darkest
47 wxEffectsImpl::wxEffectsImpl(const wxColour& highlightColour, const wxColour& lightShadow,
48 const wxColour& faceColour, const wxColour& mediumShadow, const wxColour& darkShadow)
49 {
50 m_highlightColour = highlightColour;
51 m_lightShadow = lightShadow;
52 m_faceColour = faceColour;
53 m_mediumShadow = mediumShadow;
54 m_darkShadow = darkShadow;
55 }
56
57 // Draw a sunken edge
58 void wxEffectsImpl::DrawSunkenEdge(wxDC& dc, const wxRect& rect, int WXUNUSED(borderSize))
59 {
60 wxPen highlightPen(m_highlightColour, 1, wxPENSTYLE_SOLID);
61 wxPen lightShadowPen(m_lightShadow, 1, wxPENSTYLE_SOLID);
62 wxPen facePen(m_faceColour, 1, wxPENSTYLE_SOLID);
63 wxPen mediumShadowPen(m_mediumShadow, 1, wxPENSTYLE_SOLID);
64 wxPen darkShadowPen(m_darkShadow, 1, wxPENSTYLE_SOLID);
65
66 //// LEFT AND TOP
67 // Draw a medium shadow pen on left and top, followed by dark shadow line to
68 // right and below of these lines
69
70 dc.SetPen(mediumShadowPen);
71 dc.DrawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y); // Top
72 dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1); // Left
73
74 dc.SetPen(darkShadowPen);
75 dc.DrawLine(rect.x+1, rect.y+1, rect.x+rect.width-2, rect.y+1); // Top
76 dc.DrawLine(rect.x+1, rect.y+1, rect.x+1, rect.y+rect.height-1); // Left
77
78 //// RIGHT AND BOTTOM
79
80 dc.SetPen(highlightPen);
81 dc.DrawLine(rect.x+rect.width-1, rect.y, rect.x+rect.width-1, rect.y+rect.height-1); // Right
82 dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1); // Bottom
83
84 dc.SetPen(lightShadowPen);
85 dc.DrawLine(rect.x+rect.width-2, rect.y+1, rect.x+rect.width-2, rect.y+rect.height-2); // Right
86 dc.DrawLine(rect.x+1, rect.y+rect.height-2, rect.x+rect.width-1, rect.y+rect.height-2); // Bottom
87
88 dc.SetPen(wxNullPen);
89 }
90
91 bool wxEffectsImpl::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap)
92 {
93 int w = bitmap.GetWidth();
94 int h = bitmap.GetHeight();
95
96 wxMemoryDC dcMem;
97
98 #if wxUSE_PALETTE
99 static bool hiColour = (wxDisplayDepth() >= 16) ;
100 if (bitmap.GetPalette() && !hiColour)
101 {
102 dc.SetPalette(* bitmap.GetPalette());
103 dcMem.SetPalette(* bitmap.GetPalette());
104 }
105 #endif // wxUSE_PALETTE
106
107 dcMem.SelectObjectAsSource(bitmap);
108
109 int i, j;
110 for (i = rect.x; i < rect.x + rect.width; i += w)
111 {
112 for (j = rect.y; j < rect.y + rect.height; j+= h)
113 dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
114 }
115 dcMem.SelectObject(wxNullBitmap);
116
117 #if wxUSE_PALETTE
118 if (bitmap.GetPalette() && !hiColour)
119 {
120 dc.SetPalette(wxNullPalette);
121 dcMem.SetPalette(wxNullPalette);
122 }
123 #endif // wxUSE_PALETTE
124
125 return true;
126 }
127
128 #endif // WXWIN_COMPATIBILITY_2_8
129