]> git.saurik.com Git - wxWidgets.git/blame - src/common/effects.cpp
Font updates
[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{
a756f210
VS
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) ;
3f4fc796
JS
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
33ac7e6f 57void wxEffects::DrawSunkenEdge(wxDC& dc, const wxRect& rect, int WXUNUSED(borderSize))
3f4fc796
JS
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();
33ac7e6f 96
3f4fc796 97 wxMemoryDC dcMem;
33ac7e6f 98
d275c7eb 99#if wxUSE_PALETTE
3f4fc796
JS
100 if (bitmap.GetPalette() && !hiColour)
101 {
102 dc.SetPalette(* bitmap.GetPalette());
103 dcMem.SetPalette(* bitmap.GetPalette());
104 }
d275c7eb
VZ
105#endif // wxUSE_PALETTE
106
3f4fc796
JS
107 dcMem.SelectObject(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
d275c7eb 117#if wxUSE_PALETTE
3f4fc796
JS
118 if (bitmap.GetPalette() && !hiColour)
119 {
120 dc.SetPalette(wxNullPalette);
121 dcMem.SetPalette(wxNullPalette);
122 }
d275c7eb 123#endif // wxUSE_PALETTE
3f4fc796
JS
124
125 return TRUE;
126}