LibreOffice Module sd (master) 1
SlsTheme.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <bitmaps.hlst>
21#include <view/SlsTheme.hxx>
23#include <tools/color.hxx>
24#include <vcl/outdev.hxx>
25#include <vcl/svapp.hxx>
26#include <vcl/settings.hxx>
27
28#include <osl/diagnose.h>
29
30namespace sd::slidesorter::view {
31
32const Color Black(0x000000);
33const Color White(0xffffff);
34
35static Color ChangeLuminance (Color aColor, const int nValue)
36{
37 if (nValue > 0)
39 else
41 return aColor;
42}
43
45 const Color aColor,
46 const sal_Int32 nNewSaturation,
47 const sal_Int32 nNewBrightness)
48{
49 sal_uInt16 nHue (0);
50 sal_uInt16 nSaturation (0);
51 sal_uInt16 nBrightness (0);
52 aColor.RGBtoHSB(nHue, nSaturation, nBrightness);
53 return Color::HSBtoRGB(
54 nHue,
55 nNewSaturation>=0 ? nNewSaturation : nSaturation,
56 nNewBrightness>=0 ? nNewBrightness : nBrightness);
57}
58
59Theme::Theme (const std::shared_ptr<controller::Properties>& rpProperties)
60 : maBackgroundColor(rpProperties->GetBackgroundColor())
61{
70
71 Update(rpProperties);
72}
73
74void Theme::Update (const std::shared_ptr<controller::Properties>& rpProperties)
75{
76 // Set up colors.
77 maBackgroundColor = rpProperties->GetBackgroundColor();
78
80
82
84 const Color aSelectionColor (rpProperties->GetSelectionColor());
85 maColor[Color_Selection] = aSelectionColor;
86 if (aSelectionColor.IsBright())
88 else
90
91 // Set up gradients.
92 SetGradient(Gradient_MouseOverPage, aSelectionColor, 0, 60, +80,+100, +50,+25);
93 SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +80,+100, +50,+25);
94 SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
95 SetGradient(Gradient_MouseOverSelected, aSelectionColor, 55, 60, +80,+100, +50,+25);
96 SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +80,+100, -50,-75);
97 SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 55, 60, +80,+100, -50,-75);
98
100
101 // The focused gradient needs special handling because its fill color is
102 // like that of the NormalPage gradient.
105
106 // Set up icons.
107 if (maIcons.empty())
108 {
109 maIcons.resize(IconType_Size_);
110
111 InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
112 InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
113 InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
114 InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
115 }
116}
117
118std::shared_ptr<vcl::Font> Theme::GetFont (
119 const FontType eType,
120 const OutputDevice& rDevice)
121{
122 std::shared_ptr<vcl::Font> pFont;
123
124 switch (eType)
125 {
126 case Font_PageNumber:
127 pFont = std::make_shared<vcl::Font>(Application::GetSettings().GetStyleSettings().GetAppFont());
128 pFont->SetTransparent(true);
129 pFont->SetWeight(WEIGHT_BOLD);
130 break;
131
132 case Font_PageCount:
133 pFont = std::make_shared<vcl::Font>(Application::GetSettings().GetStyleSettings().GetAppFont());
134 pFont->SetTransparent(true);
135 pFont->SetWeight(WEIGHT_NORMAL);
136 {
137 const Size aSize (pFont->GetFontSize());
138 pFont->SetFontSize(Size(aSize.Width()*5/3, aSize.Height()*5/3));
139 }
140 break;
141 }
142
143 if (pFont)
144 {
145 // Transform the point size to pixel size.
146 const MapMode aFontMapMode (MapUnit::MapPoint);
147 const Size aFontSize (rDevice.LogicToPixel(pFont->GetFontSize(), aFontMapMode));
148
149 // Transform the font size to the logical coordinates of the device.
150 pFont->SetFontSize(rDevice.PixelToLogic(aFontSize));
151 }
152
153 return pFont;
154}
155
157{
158 if (sal_uInt32(eType)<maColor.size())
159 return maColor[eType];
160 else
161 return Color(0);
162}
163
165 const GradientColorType eType,
166 const GradientColorClass eClass)
167{
168 GradientDescriptor& rDescriptor (GetGradient(eType));
169
170 switch (eClass)
171 {
172 case GradientColorClass::Border1: return rDescriptor.maBorderColor1;
173 case GradientColorClass::Border2: return rDescriptor.maBorderColor2;
174 case GradientColorClass::Fill1: return rDescriptor.maFillColor1;
175 case GradientColorClass::Fill2: return rDescriptor.maFillColor2;
176 }
177 return Color(0);
178}
179
181 const GradientColorType eType,
182 const Color aBaseColor,
183 const sal_Int32 nSaturationOverride,
184 const sal_Int32 nBrightnessOverride,
185 const sal_Int32 nFillStartOffset,
186 const sal_Int32 nFillEndOffset,
187 const sal_Int32 nBorderStartOffset,
188 const sal_Int32 nBorderEndOffset)
189{
191
192 const Color aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
193 ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
194 : aBaseColor);
195
196 rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
197 rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
198 rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
199 rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
200}
201
202const BitmapEx& Theme::GetIcon (const IconType eType)
203{
204 if (size_t(eType)<maIcons.size())
205 return maIcons[eType];
206 else
207 {
208 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
209 return maIcons[0];
210 }
211}
212
214{
215 if (size_t(eType)<maGradients.size())
216 return maGradients[eType];
217 else
218 {
219 OSL_ASSERT(eType>=0 && size_t(eType)<maGradients.size());
220 return maGradients[0];
221 }
222}
223
224void Theme::InitializeIcon(const IconType eType, const OUString& rResourceId)
225{
226 if (size_t(eType)<maIcons.size())
227 {
228 const BitmapEx aIcon(rResourceId);
229 maIcons[eType] = aIcon;
230 }
231 else
232 {
233 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
234 }
235}
236
237} // end of namespace ::sd::slidesorter::view
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Color maBackgroundColor
static const AllSettings & GetSettings()
void DecreaseLuminance(sal_uInt8 cLumDec)
void RGBtoHSB(sal_uInt16 &nHue, sal_uInt16 &nSaturation, sal_uInt16 &nBrightness) const
bool IsBright() const
void IncreaseLuminance(sal_uInt8 cLumInc)
static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
::std::vector< GradientDescriptor > maGradients
Definition: SlsTheme.hxx:122
Color GetColor(const ColorType eType)
Definition: SlsTheme.cxx:156
void SetGradient(const GradientColorType eType, const Color aBaseColor, const sal_Int32 nSaturationOverride, const sal_Int32 nBrightnessOverride, const sal_Int32 nFillStartOffset, const sal_Int32 nFillEndOffset, const sal_Int32 nBorderStartOffset, const sal_Int32 nBorderEndOffset)
Definition: SlsTheme.cxx:180
Theme(const std::shared_ptr< controller::Properties > &rpProperties)
Definition: SlsTheme.cxx:59
Color GetGradientColor(const GradientColorType eType, const GradientColorClass eClass)
Definition: SlsTheme.cxx:164
GradientDescriptor & GetGradient(const GradientColorType eType)
Definition: SlsTheme.cxx:213
void InitializeIcon(const IconType eType, const OUString &rResourceId)
Guarded initialization of the specified icon in the maIcons container.
Definition: SlsTheme.cxx:224
::std::vector< Color > maColor
Definition: SlsTheme.hxx:124
static std::shared_ptr< vcl::Font > GetFont(const FontType eType, const OutputDevice &rDevice)
Definition: SlsTheme.cxx:118
const BitmapEx & GetIcon(const IconType eType)
Definition: SlsTheme.cxx:202
void Update(const std::shared_ptr< controller::Properties > &rpProperties)
Call this method to update some colors as response to a change of a system color change.
Definition: SlsTheme.cxx:74
::std::vector< BitmapEx > maIcons
Definition: SlsTheme.hxx:123
DocumentType eType
sal_Int16 nValue
WEIGHT_BOLD
WEIGHT_NORMAL
static Color ChangeLuminance(Color aColor, const int nValue)
Definition: SlsTheme.cxx:35
const Color White(0xffffff)
const Color Black(0x000000)
static Color HGBAdapt(const Color aColor, const sal_Int32 nNewSaturation, const sal_Int32 nNewBrightness)
Definition: SlsTheme.cxx:44