xref: /trunk/main/vcl/inc/aqua/scaledlayer.h (revision 2f650597a53288477d43605d48cfc4072d97408f) !
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_SCALEDLAYER_H
25 #define _SV_SCALEDLAYER_H
26 
27 #include "premac.h"
28 #include <ApplicationServices/ApplicationServices.h>
29 #include "postmac.h"
30 
31 // A CGLayer sized in pixels and the number of its pixels per point.
32 // It does not retain or release the layer.
33 class ScaledLayer
34 {
35 public:
ScaledLayer()36     ScaledLayer() : mxLayer( NULL ), mfScale( 1.0f ) {}
ScaledLayer(CGLayerRef xLayer,float fScale)37     ScaledLayer( CGLayerRef xLayer, float fScale ) : mxLayer( xLayer ), mfScale( fScale ) {}
38 
get()39     CGLayerRef  get() const { return mxLayer; }
getScale()40     float       getScale() const { return mfScale; }
41 
getPixelSize()42     CGSize      getPixelSize() const { return mxLayer ? CGLayerGetSize( mxLayer ) : CGSizeZero; }
getPointSize()43     CGSize      getPointSize() const
44     {
45         const CGSize aPixels = getPixelSize();
46         return CGSizeMake( aPixels.width / mfScale, aPixels.height / mfScale );
47     }
48 
toPixels(CGFloat fWidth,CGFloat fHeight,float fScale)49     static CGSize toPixels( CGFloat fWidth, CGFloat fHeight, float fScale )
50     {
51         return CGSizeMake( fWidth * fScale, fHeight * fScale );
52     }
toPixels(CGFloat fWidth,CGFloat fHeight)53     CGSize      toPixels( CGFloat fWidth, CGFloat fHeight ) const { return toPixels( fWidth, fHeight, mfScale ); }
54 
55     // lets a layer context take VCL coordinates in points
scaleContext(CGContextRef xContext)56     void        scaleContext( CGContextRef xContext ) const { CGContextScaleCTM( xContext, mfScale, mfScale ); }
57 
58 private:
59     CGLayerRef  mxLayer;
60     float       mfScale;
61 };
62 
63 #endif // _SV_SCALEDLAYER_H
64