bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsTheme.cxx
blobf495ef6a4810201ec7812fb6cff6e52f2aacaf3b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <bitmaps.hlst>
21 #include <view/SlsTheme.hxx>
22 #include <controller/SlsProperties.hxx>
23 #include <tools/color.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/image.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/settings.hxx>
29 #include <svtools/colorcfg.hxx>
30 #include <osl/diagnose.h>
32 namespace sd { namespace slidesorter { namespace view {
34 const static Color Black(0x000000);
35 const static Color White(0xffffff);
37 static Color ChangeLuminance (Color aColor, const int nValue)
39 if (nValue > 0)
40 aColor.IncreaseLuminance(nValue);
41 else
42 aColor.DecreaseLuminance(-nValue);
43 return aColor;
46 static Color HGBAdapt (
47 const Color aColor,
48 const sal_Int32 nNewSaturation,
49 const sal_Int32 nNewBrightness)
51 sal_uInt16 nHue (0);
52 sal_uInt16 nSaturation (0);
53 sal_uInt16 nBrightness (0);
54 aColor.RGBtoHSB(nHue, nSaturation, nBrightness);
55 return Color::HSBtoRGB(
56 nHue,
57 nNewSaturation>=0 ? nNewSaturation : nSaturation,
58 nNewBrightness>=0 ? nNewBrightness : nBrightness);
61 Theme::Theme (const std::shared_ptr<controller::Properties>& rpProperties)
62 : maBackgroundColor(rpProperties->GetBackgroundColor()),
63 maGradients(),
64 maIcons(),
65 maColor()
67 maColor.resize(ColorType_Size_);
68 maColor[Color_Background] = maBackgroundColor;
69 maColor[Color_PageNumberDefault] = Color(0x0808080);
70 maColor[Color_PageNumberHover] = Color(0x4c4c4c);
71 maColor[Color_PageNumberHighContrast] = White;
72 maColor[Color_PageNumberBrightBackground] = Color(0x333333);
73 maColor[Color_PageNumberDarkBackground] = Color(0xcccccc);
74 maColor[Color_PreviewBorder] = Color(0x949599);
76 Update(rpProperties);
79 void Theme::Update (const std::shared_ptr<controller::Properties>& rpProperties)
81 // Set up colors.
82 maBackgroundColor = rpProperties->GetBackgroundColor();
84 maColor[Color_Background] = maBackgroundColor;
86 maGradients.resize(GradientColorType_Size_);
88 maColor[Color_Background] = maBackgroundColor;
89 const Color aSelectionColor (rpProperties->GetSelectionColor());
90 maColor[Color_Selection] = aSelectionColor;
91 if (aSelectionColor.IsBright())
92 maColor[Color_PageCountFontColor] = Black;
93 else
94 maColor[Color_PageCountFontColor] = White;
96 // Set up gradients.
97 SetGradient(Gradient_MouseOverPage, aSelectionColor, 0, 60, +80,+100, +50,+25);
98 SetGradient(Gradient_SelectedPage, aSelectionColor, 50, 50, +80,+100, +50,+25);
99 SetGradient(Gradient_FocusedPage, aSelectionColor, -1,-1, 0,0, -50,-75);
100 SetGradient(Gradient_MouseOverSelected, aSelectionColor, 55, 60, +80,+100, +50,+25);
101 SetGradient(Gradient_SelectedAndFocusedPage, aSelectionColor, 50, 50, +80,+100, -50,-75);
102 SetGradient(Gradient_MouseOverSelectedAndFocusedPage, aSelectionColor, 55, 60, +80,+100, -50,-75);
104 SetGradient(Gradient_NormalPage, maBackgroundColor, -1,-1, 0,0, 0,0);
106 // The focused gradient needs special handling because its fill color is
107 // like that of the NormalPage gradient.
108 GetGradient(Gradient_FocusedPage).maFillColor1 = GetGradient(Gradient_NormalPage).maFillColor1;
109 GetGradient(Gradient_FocusedPage).maFillColor2 = GetGradient(Gradient_NormalPage).maFillColor2;
111 // Set up icons.
112 if (maIcons.empty())
114 maIcons.resize(IconType_Size_);
116 InitializeIcon(Icon_RawShadow, IMAGE_SHADOW);
117 InitializeIcon(Icon_RawInsertShadow, IMAGE_INSERT_SHADOW);
118 InitializeIcon(Icon_HideSlideOverlay, IMAGE_HIDE_SLIDE_OVERLAY);
119 InitializeIcon(Icon_FocusBorder, IMAGE_FOCUS_BORDER);
123 std::shared_ptr<vcl::Font> Theme::GetFont (
124 const FontType eType,
125 const OutputDevice& rDevice)
127 std::shared_ptr<vcl::Font> pFont;
129 switch (eType)
131 case Font_PageNumber:
132 pFont.reset(new vcl::Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
133 pFont->SetTransparent(true);
134 pFont->SetWeight(WEIGHT_BOLD);
135 break;
137 case Font_PageCount:
138 pFont.reset(new vcl::Font(Application::GetSettings().GetStyleSettings().GetAppFont()));
139 pFont->SetTransparent(true);
140 pFont->SetWeight(WEIGHT_NORMAL);
142 const Size aSize (pFont->GetFontSize());
143 pFont->SetFontSize(Size(aSize.Width()*5/3, aSize.Height()*5/3));
145 break;
148 if (pFont)
150 // Transform the point size to pixel size.
151 const MapMode aFontMapMode (MapUnit::MapPoint);
152 const Size aFontSize (rDevice.LogicToPixel(pFont->GetFontSize(), aFontMapMode));
154 // Transform the font size to the logical coordinates of the device.
155 pFont->SetFontSize(rDevice.PixelToLogic(aFontSize));
158 return pFont;
161 Color Theme::GetColor (const ColorType eType)
163 if (sal_uInt32(eType)<maColor.size())
164 return maColor[eType];
165 else
166 return Color(0);
169 Color Theme::GetGradientColor (
170 const GradientColorType eType,
171 const GradientColorClass eClass)
173 GradientDescriptor& rDescriptor (GetGradient(eType));
175 switch (eClass)
177 case GradientColorClass::Border1: return rDescriptor.maBorderColor1;
178 case GradientColorClass::Border2: return rDescriptor.maBorderColor2;
179 case GradientColorClass::Fill1: return rDescriptor.maFillColor1;
180 case GradientColorClass::Fill2: return rDescriptor.maFillColor2;
182 return Color(0);
185 void Theme::SetGradient (
186 const GradientColorType eType,
187 const Color aBaseColor,
188 const sal_Int32 nSaturationOverride,
189 const sal_Int32 nBrightnessOverride,
190 const sal_Int32 nFillStartOffset,
191 const sal_Int32 nFillEndOffset,
192 const sal_Int32 nBorderStartOffset,
193 const sal_Int32 nBorderEndOffset)
195 GradientDescriptor& rGradient (GetGradient(eType));
197 const Color aColor (nSaturationOverride>=0 || nBrightnessOverride>=0
198 ? HGBAdapt(aBaseColor, nSaturationOverride, nBrightnessOverride)
199 : aBaseColor);
201 rGradient.maFillColor1 = ChangeLuminance(aColor, nFillStartOffset);
202 rGradient.maFillColor2 = ChangeLuminance(aColor, nFillEndOffset);
203 rGradient.maBorderColor1 = ChangeLuminance(aColor, nBorderStartOffset);
204 rGradient.maBorderColor2 = ChangeLuminance(aColor, nBorderEndOffset);
207 const BitmapEx& Theme::GetIcon (const IconType eType)
209 if (size_t(eType)<maIcons.size())
210 return maIcons[eType];
211 else
213 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
214 return maIcons[0];
218 Theme::GradientDescriptor& Theme::GetGradient (const GradientColorType eType)
220 if (size_t(eType)<maGradients.size())
221 return maGradients[eType];
222 else
224 OSL_ASSERT(eType>=0 && size_t(eType)<maGradients.size());
225 return maGradients[0];
229 void Theme::InitializeIcon(const IconType eType, const OUString& rResourceId)
231 if (size_t(eType)<maIcons.size())
233 const BitmapEx aIcon(rResourceId);
234 maIcons[eType] = aIcon;
236 else
238 OSL_ASSERT(eType>=0 && size_t(eType)<maIcons.size());
242 } } } // end of namespace ::sd::slidesorter::view
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */