]> git.saurik.com Git - wxWidgets.git/blob - src/common/effects.cpp
cleanup - reformat
[wxWidgets.git] / src / common / effects.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: effects.cpp
3 // Purpose: wxEffects 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/gdicmn.h"
20 #include "wx/pen.h"
21 #include "wx/dcmemory.h"
22 #include "wx/settings.h"
23 #include "wx/effects.h"
24
25 /*
26 * wxEffects: various 3D effects
27 */
28
29 IMPLEMENT_CLASS(wxEffects, wxObject)
30
31 // Assume system colours
32 wxEffects::wxEffects()
33 {
34 m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT) ;
35 m_lightShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT) ;
36 m_faceColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE) ;
37 m_mediumShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW) ;
38 m_darkShadow = wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW) ;
39 }
40
41 // Going from lightest to darkest
42 wxEffects::wxEffects(const wxColour& highlightColour, const wxColour& lightShadow,
43 const wxColour& faceColour, const wxColour& mediumShadow, const wxColour& darkShadow)
44 {
45 m_highlightColour = highlightColour;
46 m_lightShadow = lightShadow;
47 m_faceColour = faceColour;
48 m_mediumShadow = mediumShadow;
49 m_darkShadow = darkShadow;
50 }
51
52 // Draw a sunken edge
53 void wxEffects::DrawSunkenEdge(wxDC& dc, const wxRect& rect, int WXUNUSED(borderSize))
54 {
55 wxPen highlightPen(m_highlightColour, 1, wxSOLID);
56 wxPen lightShadowPen(m_lightShadow, 1, wxSOLID);
57 wxPen facePen(m_faceColour, 1, wxSOLID);
58 wxPen mediumShadowPen(m_mediumShadow, 1, wxSOLID);
59 wxPen darkShadowPen(m_darkShadow, 1, wxSOLID);
60
61 //// LEFT AND TOP
62 // Draw a medium shadow pen on left and top, followed by dark shadow line to
63 // right and below of these lines
64
65 dc.SetPen(mediumShadowPen);
66 dc.DrawLine(rect.x, rect.y, rect.x+rect.width-1, rect.y); // Top
67 dc.DrawLine(rect.x, rect.y, rect.x, rect.y+rect.height-1); // Left
68
69 dc.SetPen(darkShadowPen);
70 dc.DrawLine(rect.x+1, rect.y+1, rect.x+rect.width-2, rect.y+1); // Top
71 dc.DrawLine(rect.x+1, rect.y+1, rect.x+1, rect.y+rect.height-1); // Left
72
73 //// RIGHT AND BOTTOM
74
75 dc.SetPen(highlightPen);
76 dc.DrawLine(rect.x+rect.width-1, rect.y, rect.x+rect.width-1, rect.y+rect.height-1); // Right
77 dc.DrawLine(rect.x, rect.y+rect.height-1, rect.x+rect.width, rect.y+rect.height-1); // Bottom
78
79 dc.SetPen(lightShadowPen);
80 dc.DrawLine(rect.x+rect.width-2, rect.y+1, rect.x+rect.width-2, rect.y+rect.height-2); // Right
81 dc.DrawLine(rect.x+1, rect.y+rect.height-2, rect.x+rect.width-1, rect.y+rect.height-2); // Bottom
82
83 dc.SetPen(wxNullPen);
84 }
85
86 bool wxEffects::TileBitmap(const wxRect& rect, wxDC& dc, const wxBitmap& bitmap)
87 {
88 static bool hiColour = (wxDisplayDepth() >= 16) ;
89
90 int w = bitmap.GetWidth();
91 int h = bitmap.GetHeight();
92
93 wxMemoryDC dcMem;
94
95 #if wxUSE_PALETTE
96 if (bitmap.GetPalette() && !hiColour)
97 {
98 dc.SetPalette(* bitmap.GetPalette());
99 dcMem.SetPalette(* bitmap.GetPalette());
100 }
101 #endif // wxUSE_PALETTE
102
103 dcMem.SelectObject(bitmap);
104
105 int i, j;
106 for (i = rect.x; i < rect.x + rect.width; i += w)
107 {
108 for (j = rect.y; j < rect.y + rect.height; j+= h)
109 dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
110 }
111 dcMem.SelectObject(wxNullBitmap);
112
113 #if wxUSE_PALETTE
114 if (bitmap.GetPalette() && !hiColour)
115 {
116 dc.SetPalette(wxNullPalette);
117 dcMem.SetPalette(wxNullPalette);
118 }
119 #endif // wxUSE_PALETTE
120
121 return true;
122 }