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