LibreOffice Module vcl (master)  1
salgdicommon.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  * 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 #ifndef INCLUDED_VCL_INC_QUARTZ_SALGDICOMMON_HXX
21 #define INCLUDED_VCL_INC_QUARTZ_SALGDICOMMON_HXX
22 
23 #include <iostream>
24 
25 #include <premac.h>
26 #ifdef IOS
27 #include <CoreGraphics/CoreGraphics.h>
28 #else
29 #include <ApplicationServices/ApplicationServices.h>
30 #endif
31 #include <postmac.h>
32 
33 #include <tools/color.hxx>
34 #include <vcl/salgtype.hxx>
35 
36 // abstracting quartz color instead of having to use a CGFloat[] array
37 class RGBAColor
38 {
39 public:
40  RGBAColor( ::Color );
41  RGBAColor( float fRed, float fGreen, float fBlue, float fAlpha ); //NOTUSEDYET
42  const CGFloat* AsArray() const { return m_fRGBA; }
43  bool IsVisible() const { return m_fRGBA[3] > 0; }
44  void SetAlpha( float fAlpha ) { m_fRGBA[3] = fAlpha; }
45 
46  CGFloat GetRed() const { return m_fRGBA[0]; }
47  CGFloat GetGreen() const { return m_fRGBA[1]; }
48  CGFloat GetBlue() const { return m_fRGBA[2]; }
49  CGFloat GetAlpha() const { return m_fRGBA[3]; }
50 private:
51  CGFloat m_fRGBA[4]; // red, green, blue, alpha
52 };
53 
54 inline RGBAColor::RGBAColor( ::Color nColor )
55 {
56  m_fRGBA[0] = nColor.GetRed() * (1.0/255);
57  m_fRGBA[1] = nColor.GetGreen() * (1.0/255);
58  m_fRGBA[2] = nColor.GetBlue() * (1.0/255);
59  m_fRGBA[3] = 1.0; // opaque
60 }
61 
62 inline RGBAColor::RGBAColor( float fRed, float fGreen, float fBlue, float fAlpha )
63 {
64  m_fRGBA[0] = fRed;
65  m_fRGBA[1] = fGreen;
66  m_fRGBA[2] = fBlue;
67  m_fRGBA[3] = fAlpha;
68 }
69 
70 inline std::ostream &operator <<(std::ostream& s, const RGBAColor &aColor)
71 {
72 #ifndef SAL_LOG_INFO
73  (void) aColor;
74 #else
75  s << "{" << aColor.GetRed() << "," << aColor.GetGreen() << "," << aColor.GetBlue() << "," << aColor.GetAlpha() << "}";
76 #endif
77  return s;
78 }
79 
80 // XOR emulation suckage.
81 // See http://www.openoffice.org/marketing/ooocon2008/programme/wednesday_1401.pdf
82 // and https://bugs.freedesktop.org/show_bug.cgi?id=38844 .
83 
85 {
86 public:
87  XorEmulation();
88  ~XorEmulation();
89 
90  void SetTarget( int nWidth, int nHeight, int nBitmapDepth, CGContextRef, CGLayerRef );
91  bool UpdateTarget();
92  void Enable() { m_bIsEnabled = true; }
93  void Disable() { m_bIsEnabled = false; }
94  bool IsEnabled() const { return m_bIsEnabled; }
95  CGContextRef GetTargetContext() const { return m_xTargetContext; }
96  CGContextRef GetMaskContext() const { return (m_bIsEnabled ? m_xMaskContext : nullptr); }
97 
98 private:
99  CGLayerRef m_xTargetLayer;
100  CGContextRef m_xTargetContext;
101  CGContextRef m_xMaskContext;
102  CGContextRef m_xTempContext;
107 };
108 
109 #endif // INCLUDED_VCL_INC_QUARTZ_SALGDICOMMON_HXX
110 
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uLong * m_pTempBuffer
sal_uInt8 GetRed() const
RGBAColor(::Color)
sal_uIntPtr sal_uLong
void SetTarget(int nWidth, int nHeight, int nBitmapDepth, CGContextRef, CGLayerRef)
CGContextRef GetTargetContext() const
CGLayerRef m_xTargetLayer
sal_uInt8 GetBlue() const
bool UpdateTarget()
bool IsEnabled() const
CGFloat GetBlue() const
CGContextRef GetMaskContext() const
void SetAlpha(float fAlpha)
bool IsVisible() const
CGContextRef m_xTempContext
std::ostream & operator<<(std::ostream &s, const RGBAColor &aColor)
sal_uInt8 GetGreen() const
CGContextRef m_xMaskContext
CGContextRef m_xTargetContext
const CGFloat * AsArray() const
sal_uLong * m_pMaskBuffer
CGFloat GetRed() const
CGFloat GetAlpha() const
CGFloat GetGreen() const
CGFloat m_fRGBA[4]
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo