]> git.saurik.com Git - wxWidgets.git/blame - src/common/effects.cpp
fixed false alert in wxRegKey::DeleteSelf
[wxWidgets.git] / src / common / effects.cpp
CommitLineData
3f4fc796
JS
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#ifdef __GNUG__
13#pragma implementation "effects.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#include "wx/gdicmn.h"
24#include "wx/pen.h"
25#include "wx/dcmemory.h"
3bd380a3 26#include "wx/settings.h"
3f4fc796
JS
27#include "wx/effects.h"
28
29/*
30 * wxEffects: various 3D effects
31 */
32
33IMPLEMENT_CLASS(wxEffects, wxObject)
34
35// Assume system colours
36wxEffects::wxEffects()
37{
38 m_highlightColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT) ;
39 m_lightShadow = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT) ;
40 m_faceColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE) ;
41 m_mediumShadow = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW) ;
42 m_darkShadow = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DDKSHADOW) ;
43}
44
45// Going from lightest to darkest
46wxEffects::wxEffects(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 wxEffects::DrawSunkenEdge(wxDC& dc, const wxRect& rect, int borderSize)
58{
59 wxPen highlightPen(m_highlightColour, 1, wxSOLID);
60 wxPen lightShadowPen(m_lightShadow, 1, wxSOLID);
61 wxPen facePen(m_faceColour, 1, wxSOLID);
62 wxPen mediumShadowPen(m_mediumShadow, 1, wxSOLID);
63 wxPen darkShadowPen(m_darkShadow, 1, wxSOLID);
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 wxEffects::TileBitmap(const wxRect& rect, wxDC& dc, wxBitmap& bitmap)
91{
92 static bool hiColour = (wxDisplayDepth() >= 16) ;
93
94 int w = bitmap.GetWidth();
95 int h = bitmap.GetHeight();
96
97 wxMemoryDC dcMem;
98
99 if (bitmap.GetPalette() && !hiColour)
100 {
101 dc.SetPalette(* bitmap.GetPalette());
102 dcMem.SetPalette(* bitmap.GetPalette());
103 }
104 dcMem.SelectObject(bitmap);
105
106 int i, j;
107 for (i = rect.x; i < rect.x + rect.width; i += w)
108 {
109 for (j = rect.y; j < rect.y + rect.height; j+= h)
110 dc.Blit(i, j, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
111 }
112 dcMem.SelectObject(wxNullBitmap);
113
114 if (bitmap.GetPalette() && !hiColour)
115 {
116 dc.SetPalette(wxNullPalette);
117 dcMem.SetPalette(wxNullPalette);
118 }
119
120 return TRUE;
121}