LibreOffice Module vcl (master) 1
CGHelpers.hxx
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 */
10
11#ifndef INCLUDED_VCL_INC_QUARTZ_CGHELPER_HXX
12#define INCLUDED_VCL_INC_QUARTZ_CGHELPER_HXX
13
14#include <premac.h>
15#include <CoreGraphics/CoreGraphics.h>
16#include <postmac.h>
17
18#include <quartz/utils.h>
19
21{
22private:
23 CGLayerRef mpLayer;
24
25 // Layer's scaling factor
26 float mfScale;
27
28public:
30 : mpLayer(nullptr)
31 , mfScale(1.0)
32 {
33 }
34
35 CGLayerHolder(CGLayerRef pLayer, float fScale = 1.0)
36 : mpLayer(pLayer)
37 , mfScale(fScale)
38 {
39 }
40
41 // Just the size of the layer in pixels
42 CGSize getSizePixels() const
43 {
44 CGSize aSize;
45 if (mpLayer)
46 {
47 aSize = CGLayerGetSize(mpLayer);
48 }
49 return aSize;
50 }
51
52 // Size in points is size in pixels divided by the scaling factor
53 CGSize getSizePoints() const
54 {
55 CGSize aSize;
56 if (mpLayer)
57 {
58 const CGSize aLayerSize = getSizePixels();
59 aSize.width = aLayerSize.width / mfScale;
60 aSize.height = aLayerSize.height / mfScale;
61 }
62 return aSize;
63 }
64
65 CGLayerRef get() const { return mpLayer; }
66
67 bool isSet() const { return mpLayer != nullptr; }
68
69 void set(CGLayerRef const& pLayer) { mpLayer = pLayer; }
70
71 float getScale() const { return mfScale; }
72
73 void setScale(float fScale) { mfScale = fScale; }
74};
75
77{
78private:
79 CGContextRef mpContext;
80
81public:
83 : mpContext(nullptr)
84 {
85 }
86
87 CGContextHolder(CGContextRef pContext)
88 : mpContext(pContext)
89 {
90 }
91
92 CGContextRef get() const { return mpContext; }
93
94 bool isSet() const { return mpContext != nullptr; }
95
96 void set(CGContextRef const& pContext) { mpContext = pContext; }
97
98 void saveState() { CGContextSaveGState(mpContext); }
99
100 void restoreState() { CGContextRestoreGState(mpContext); }
101};
102
103#endif // INCLUDED_VCL_INC_QUARTZ_CGHELPER_HXX
104
105/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void set(CGContextRef const &pContext)
Definition: CGHelpers.hxx:96
void saveState()
Definition: CGHelpers.hxx:98
bool isSet() const
Definition: CGHelpers.hxx:94
CGContextHolder(CGContextRef pContext)
Definition: CGHelpers.hxx:87
CGContextRef get() const
Definition: CGHelpers.hxx:92
void restoreState()
Definition: CGHelpers.hxx:100
CGContextRef mpContext
Definition: CGHelpers.hxx:79
void setScale(float fScale)
Definition: CGHelpers.hxx:73
void set(CGLayerRef const &pLayer)
Definition: CGHelpers.hxx:69
CGLayerRef get() const
Definition: CGHelpers.hxx:65
CGLayerHolder(CGLayerRef pLayer, float fScale=1.0)
Definition: CGHelpers.hxx:35
CGSize getSizePixels() const
Definition: CGHelpers.hxx:42
CGSize getSizePoints() const
Definition: CGHelpers.hxx:53
float getScale() const
Definition: CGHelpers.hxx:71
bool isSet() const
Definition: CGHelpers.hxx:67
CGLayerRef mpLayer
Definition: CGHelpers.hxx:23