LibreOffice Module vcl (master)  1
pixel.cxx
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 #include <cassert>
21 
22 #include <vcl/gdimtf.hxx>
23 #include <vcl/metaact.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/virdev.hxx>
26 
27 #include <drawmode.hxx>
28 #include <salgdi.hxx>
29 
30 Color OutputDevice::GetPixel(const Point& rPoint) const
31 {
32  Color aColor;
33 
34  if (mpGraphics || AcquireGraphics())
35  {
36  assert(mpGraphics);
37  if (mbInitClipRegion)
38  const_cast<OutputDevice*>(this)->InitClipRegion();
39 
40  if (!mbOutputClipped)
41  {
42  const tools::Long nX = ImplLogicXToDevicePixel(rPoint.X());
43  const tools::Long nY = ImplLogicYToDevicePixel(rPoint.Y());
44  aColor = mpGraphics->GetPixel(nX, nY, *this);
45 
46  if (mpAlphaVDev)
47  {
48  Color aAlphaColor = mpAlphaVDev->GetPixel(rPoint);
49  aColor.SetAlpha(255 - aAlphaColor.GetBlue());
50  }
51  }
52  }
53  return aColor;
54 }
55 
56 void OutputDevice::DrawPixel( const Point& rPt )
57 {
58  assert(!is_double_buffered_window());
59 
60  if ( mpMetaFile )
61  mpMetaFile->AddAction( new MetaPointAction( rPt ) );
62 
64  return;
65 
66  Point aPt = ImplLogicToDevicePixel( rPt );
67 
68  if ( !mpGraphics && !AcquireGraphics() )
69  return;
70  assert(mpGraphics);
71 
72  if ( mbInitClipRegion )
74 
75  if ( mbOutputClipped )
76  return;
77 
78  if ( mbInitLineColor )
79  InitLineColor();
80 
81  mpGraphics->DrawPixel( aPt.X(), aPt.Y(), *this );
82 
83  if( mpAlphaVDev )
84  mpAlphaVDev->DrawPixel( rPt );
85 }
86 
87 void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor )
88 {
89  assert(!is_double_buffered_window());
90 
91  Color aColor = vcl::drawmode::GetLineColor(rColor, GetDrawMode(), GetSettings().GetStyleSettings());
92 
93  if ( mpMetaFile )
94  mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) );
95 
97  return;
98 
99  Point aPt = ImplLogicToDevicePixel( rPt );
100 
101  if ( !mpGraphics && !AcquireGraphics() )
102  return;
103  assert(mpGraphics);
104 
105  if ( mbInitClipRegion )
106  InitClipRegion();
107 
108  if ( mbOutputClipped )
109  return;
110 
111  mpGraphics->DrawPixel( aPt.X(), aPt.Y(), aColor, *this );
112 
113  if (mpAlphaVDev)
114  {
115  Color aAlphaColor(255 - rColor.GetAlpha(), 255 - rColor.GetAlpha(), 255 - rColor.GetAlpha());
116  mpAlphaVDev->DrawPixel(rPt, aAlphaColor);
117  }
118 }
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DrawPixel(tools::Long nX, tools::Long nY, const OutputDevice &rOutDev)
sal_uInt8 GetAlpha() const
void SetAlpha(sal_uInt8 nAlpha)
SAL_DLLPRIVATE bool ImplIsRecordLayout() const
Definition: outdev.cxx:702
long Long
bool mbOutputClipped
Definition: outdev.hxx:244
SAL_DLLPRIVATE bool is_double_buffered_window() const
SAL_DLLPRIVATE void InitLineColor()
Definition: line.cxx:84
SAL_DLLPRIVATE tools::Long ImplLogicXToDevicePixel(tools::Long nX) const
Convert a logical X coordinate to a device pixel's X coordinate.
Definition: map.cxx:306
sal_uInt8 GetBlue() const
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:181
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
bool mbInitLineColor
Definition: outdev.hxx:247
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
bool mbLineColor
Definition: outdev.hxx:245
const AllSettings & GetSettings() const
Definition: outdev.hxx:287
DrawModeFlags GetDrawMode() const
Definition: outdev.hxx:483
void DrawPixel(const Point &rPt)
Definition: pixel.cxx:56
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:195
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:562
Color GetLineColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:30
bool mbInitClipRegion
Definition: outdev.hxx:251
virtual void InitClipRegion()
SAL_DLLPRIVATE tools::Rectangle ImplLogicToDevicePixel(const tools::Rectangle &rLogicRect) const
Convert a logical rectangle to a rectangle in physical device pixel units.
Definition: map.cxx:386
SAL_DLLPRIVATE tools::Long ImplLogicYToDevicePixel(tools::Long nY) const
Convert a logical Y coordinate to a device pixel's Y coordinate.
Definition: map.cxx:315
Color GetPixel(tools::Long nX, tools::Long nY, const OutputDevice &rOutDev)
Color GetPixel(const Point &rPt) const
Definition: pixel.cxx:30
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:477
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:184