bump product version to 7.2.5.1
[LibreOffice.git] / vcl / inc / quartz / CGHelpers.hxx
bloba43b3e97518578e60cebae48b93e14010b0f9498
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 */
11 #ifndef INCLUDED_VCL_INC_QUARTZ_CGHELPER_HXX
12 #define INCLUDED_VCL_INC_QUARTZ_CGHELPER_HXX
14 #include <premac.h>
15 #include <CoreGraphics/CoreGraphics.h>
16 #include <postmac.h>
18 #include <quartz/utils.h>
20 class CGLayerHolder
22 private:
23 CGLayerRef mpLayer;
25 // Layer's scaling factor
26 float mfScale;
28 public:
29 CGLayerHolder()
30 : mpLayer(nullptr)
31 , mfScale(1.0)
35 CGLayerHolder(CGLayerRef pLayer, float fScale = 1.0)
36 : mpLayer(pLayer)
37 , mfScale(fScale)
41 // Just the size of the layer in pixels
42 CGSize getSizePixels() const
44 CGSize aSize;
45 if (mpLayer)
47 aSize = CGLayerGetSize(mpLayer);
49 return aSize;
52 // Size in points is size in pixels divided by the scaling factor
53 CGSize getSizePoints() const
55 CGSize aSize;
56 if (mpLayer)
58 const CGSize aLayerSize = getSizePixels();
59 aSize.width = aLayerSize.width / mfScale;
60 aSize.height = aLayerSize.height / mfScale;
62 return aSize;
65 CGLayerRef get() const { return mpLayer; }
67 bool isSet() const { return mpLayer != nullptr; }
69 void set(CGLayerRef const& pLayer) { mpLayer = pLayer; }
71 float getScale() const { return mfScale; }
73 void setScale(float fScale) { mfScale = fScale; }
76 class CGContextHolder
78 private:
79 CGContextRef mpContext;
81 public:
82 CGContextHolder()
83 : mpContext(nullptr)
87 CGContextHolder(CGContextRef pContext)
88 : mpContext(pContext)
92 CGContextRef get() const { return mpContext; }
94 bool isSet() const { return mpContext != nullptr; }
96 void set(CGContextRef const& pContext) { mpContext = pContext; }
98 void saveState() { CGContextSaveGState(mpContext); }
100 void restoreState() { CGContextRestoreGState(mpContext); }
103 #endif // INCLUDED_VCL_INC_QUARTZ_CGHELPER_HXX
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */