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