Commit Graph

218 Commits

Author SHA1 Message Date
Stefan Csomor
62052e365e Do not offset coordinates in case of filling 2017-06-28 07:34:53 +02:00
Stefan Csomor
d9228f471c Optimize rectangle drawing under Cairo 2017-06-26 09:55:17 +02:00
Stefan Csomor
4cce63d904 Support transparency and masks under macOS / Cairo 2017-06-26 09:49:39 +02:00
Stefan Csomor
6dfa897b4a Adding a native implementation for clearing bitmap/window contexts
Filling a bitmap surface is filled with ARGB 0,0,0,0. This way eg buffered transparent layers can be properly cleared.
2017-06-25 22:48:58 +02:00
Artur Wieczorek
e811c0640a Optimize creating wxCairoContext from wxMemoryDC associated with ARGB wxBitmap (MSW)
Legacy API cairo_win32_surface_create() can create only 24 bpp RGB surfaces but new API cairo_win32_surface_create_with_format() introduced in 1.15.4 supports creating also 32 bpp ARGB surfaces.
So, this new API can be used to create ARGB surface directly from ARGB bitmap (HDC), superseding current implementation based on the access to the bitmap data with cairo_image_surface_create_for_data().
Unfortunately, 0RGB bitmaps are not supported by cairo_win32_surface_create_with_format() and for such bitmaps surface has to be still created from bitmap data.
2017-01-10 21:34:51 +01:00
Václav Slavík
e71be91ebe Add API to create wxGraphicsContext from win32 HDC
Add wxGraphicsContext::CreateFromNativeHDC() and wxGraphicsRenderer::
CreateContextFromNativeHDC() to allow creation not only from native
renderer object, but also from HDC, which is something universally
supported by win32 implementations.
2017-01-06 14:35:09 +01:00
Graham Dawes
d639e4ffce Fix wxQt build errors when using gcc 4.4
Closes #17733.
2016-11-30 16:13:46 +01:00
Artur Wieczorek
4d6d73eab3 Fix wxGraphicsMatrix concatenation (Cairo)
The parameter matrix in wxGraphicsMatrixData::Concat() should be a multiplicand, not a multiplier.

Closes #17670.
2016-09-18 23:07:59 +02:00
Artur Wieczorek
f68dad69cc Implement Flush() method for Cairo graphics context
wxCairoContext implementation for wxMSW and wxQT use internally helper surface so there is a need to flush it on demand.
2016-09-08 19:34:46 +02:00
Artur Wieczorek
480a003c00 Add wxGraphicsContext::GetClipBox() function
This method returns bounding box of the current clipping region.
Added declaration, documentation and implemented for GDI+, Direct2D, Cairo renderers.
2016-08-21 20:57:40 +02:00
Artur Wieczorek
47791737db Revert code commented out by mistake in f06bfe37.
We need to restore HDC after Cairo operations.
2016-06-23 22:23:05 +02:00
Artur Wieczorek
f06bfe37ae Fixed creating wxGraphicContext from native DC with Cairo renderer (MSW).
When x- or y-coordinate of DC origin > 0 then surface created with cairo_win32_surface_create() is not fully operational (for some Cairo operations memory access violation errors occur - see Cairo bug 96482) so in this case we would need to apply a workaround and pass non-transformed DC to Cairo and next apply original DC transformation to the Cairo context operations on our own.

Closes #17564
2016-06-11 23:20:12 +02:00
Artur Wieczorek
a5d4a99bb0 Use native methods to draw some geometric figures using Cairo renderer
There are straightforward ways to draw rectangles, circles and ellipses using native methods provided by Cairo renderer and they should be used instead of generic implementations.

See #17554
2016-05-31 21:31:15 +02:00
Artur Wieczorek
32d76cefe2 Refactored code to get access to wxBitmap's bit values in wxCairoContext ctor (MSW).
Use simpler version of wxAlphaPixelData and wxNativePixelData ctors and invoke respective accessors to obtain bitmap size.
2016-04-17 19:15:49 +02:00
Artur Wieczorek
be6f93d725 Fixed initialization sequence in wxCairoContext ctor.
Shared method Init should be invoked to initialize the context to assure consistency with other ctors.
2016-04-17 19:15:32 +02:00
Artur Wieczorek
fdc2189808 Move duplicated code to the shared function.
Code to store initial Cairo transformation settings can be moved from wxCairoContext ctor bodies to the shared method wxCairoContext::Init.
2016-04-17 19:15:12 +02:00
Artur Wieczorek
ca7670d2fc Fixed creating wxGraphicsContext from Cairo context.
Reference count of the source Cairo context should be increased to prevent source context from being destroyed in wxGraphicsContex dtor (where cairo_destroy is invoked).
2016-04-16 21:34:08 +02:00
Artur Wieczorek
495a88ba73 Fixed creating wxPrinterDC from wxGraphicsContext with Cairo renderer (GTK).
When wxGraphicsContext is created from wxPrinterDC then also logical scaling factor applied to the source wxPrinterDC has to be explicitly applied to the Cairo context.
All inherited transformation settings should be used only internally by wxGraphicsContext object and shouldn't be exposed through e.g. GetTransform() function and hence they are stored separately (in a dedicated variable) and "subtracted" from actual transformation settings for reporting purposes.

Closes #17496.
2016-04-16 21:23:21 +02:00
Artur Wieczorek
9a215bb393 Fixed creating wxGraphicsContext from wxPrinterDC with Cairo (MSW).
Modification of the mapping mode of underlying DC encapsulated in wxPrinterDC (from MM_ANISOTROPIC to MM_TEXT) which is done prior to creating Cairo context affects the value of device origin which needs to be applied to the Cairo context. Due to the change of the mapping mode it has to be rescaled based on the current scaling factor value.

See #17496.
2016-04-16 21:06:03 +02:00
Artur Wieczorek
a662e306be Fixed reporting transformation settings for wxGraphicsContext with Cairo renderer.
When wxGraphicsContext is created from "native" Cairo context (cairo_t*) then transformation settings applied initially to the underlying source Cairo context need to be stored (in a dedicated variable) to make possible determining what transformations were applied to wxGC instance since its creation. Only these explicitly applied transformations are reported by GetTransform().
2016-04-14 20:49:07 +02:00
Artur Wieczorek
a1a3f7309b Fixes and optimizations for determining wxCairoContext size (wxMSW).
1. Because Cairo uses internally GetClipBox Win API to determine surface size so we can employ the same approach in wxGraphicsRenderer::CreateContextFromNativeContext and just call this API instead of executing complicated code to determine size of underlying objects selected into DC.
2. Determine context size (and initialize respective data members with proper values) for wxCairoContext created from wxWindow.
3. Initialize respective data members with 0 values for generic wxCairoContext (with no source object provided).
2016-04-14 20:47:41 +02:00
Artur Wieczorek
0ae78d608a Restore source DC state when wxCairoContext is destroyed (wxMSW).
Since raw DC (encapsulated in source wxDC) can be modified in wxCairoContext explicitly (e.g. when context is instantiated from wxPrinterDC or wxEnhMetaFileDC) or implicitly (by some Cairo functions) we have to store its state in ctor and restore it in dtor to assure consistent state of the source wxDC.
2016-04-14 20:45:42 +02:00
Artur Wieczorek
c911f737e3 Implemented wxGraphicsContext created from wxEnhMetaFileDC for Cairo renderer (wxMSW). 2016-04-14 20:44:35 +02:00
Artur Wieczorek
0ee25aaa76 Fixed creating Cairo bitmap from wxBitmap (wxMSW).
Iterating over bit values with wxAlphaPixelData sets the internal wxBitmap's "has alpha" flag but we want to left it unchanged so we have to save its original value and restore it afterward.
2016-04-11 18:06:42 +02:00
Artur Wieczorek
c7e7c3873d Fixed determining wxCairoContext size (wxMSW).
Determine actual size of wxCairoContext created from native DC and HWND. This allows to report proper size of wxGraphicsContext created by wxGraphicsRenderer::CreateContextFromNativeContext / CreateContextFromNativeWindow.
2016-04-10 20:41:53 +02:00
Artur Wieczorek
c7a498a163 Fixed reporting transformation settings from wxGraphicsContext with Cairo renderer (GTK+ 3).
When wxGraphicsContext is created from wxWindowDC or wxMemoryDC then transformation settings applied initially to the underlying source Cairo context need to be stored (in a dedicated variable) in order to have ability to determine what transformations were applied to wxGC instance since its creation. Only these explicitly applied transformations are reported by GetTransform().

Closes #17491.
2016-04-10 20:40:33 +02:00
Artur Wieczorek
cc628f5e87 Fixed wxCairoContext::SetTransform
Actual transformation is a concatenation of internal (hidden) transformation and requested one.
2016-04-09 23:51:42 +02:00
Artur Wieczorek
42c08aae12 Fixed creating wxGraphicsContext from wxMemoryDC with Cairo renderer (wxMSW).
Create RGB Cairo surface as a fallback if we failed to create ARGB surface for 32bpp wxBitmap.
2016-04-09 23:47:58 +02:00
Artur Wieczorek
ac49e3829a Fixed inheriting wxWindowDC transformation settings by wxGraphicsContext with Cairo renderer (GTK+ 2).
When wxGraphicsContext is created from wxWindowDC then transformation settings already applied to the source wxWindowDC are not passed directly to the Cairo context through underlying GdkDrawable and therefore they need to be passed to the context explicitly.
These inherited transformation settings should be used only internally by wxGraphicsContext object and shouldn't be exposed through e.g. GetTransform() function and hence they are stored separately (in a dedicated variable) and "subtracted" from actual transformation settings for reporting purposes.

See #17491.
2016-04-09 23:46:29 +02:00
Artur Wieczorek
4b6c0718e9 Fixed inheriting wxMemoryDC transformation settings by wxGraphicsContext with Cairo renderer (GTK+ 2).
When wxGraphicsContext is created from wxMemoryDC then transformation settings applied to the source wxMemoryDC are not passed directly to the Cairo context through underlying GdkDrawable and therefore they need to be passed to the context explicitly.
These inherited transformations settings should be used only internally by wxGraphicsContext object and shouldn't be exposed through e.g. GetTransform() function and hence they are stored separately (in a dedicated variable) and "subtracted" from actual transformation settings for reporting purposes.

Closes #17482.
2016-04-07 19:30:01 +02:00
Artur Wieczorek
b4ffe734c1 Fixed inheriting wxMemoryDC transformation settings by wxGraphicsContext with Cairo renderer (wxMSW).
When wxGraphicsContext is created from wxMemoryDC with selected 32bppp wxBitmap then transformation settings applied to the source wxMemoryDC are not passed directly to the Cairo context through underlying HDC and therefore they need to be passed to the context explicitly.
These inherited transformations settings should be used only internally by wxGraphicsContext object and shouldn't be exposed through e.g. GetTransform() function and hence they are stored separately (in a dedicated variable) and "subtracted" from actual transformation settings for reporting purposes.

See #17482.
2016-04-05 23:46:33 +02:00
Artur Wieczorek
cb14859d10 Fixed drawing on wxMemoryDC with Cairo (wxMSW).
When Cairo surface is created from 32bpp wxBitmap then there is necessary to provide a location of its bit values to cairo_image_surface_create_for_data function and hence bitmap selected into wxMemoryDC has to be converted to DIB, if it is not a DIB already.
Moreover, if 32bpp bitmap doesn't contain real transparency data (is 0RGB bitmap) then its alpha values have to be corrected and set to wxALPHA_OPAQUE value (255).

Closes #17469.
2016-03-31 19:40:08 +02:00
Vadim Zeitlin
7c4145490e Compilation fix for wxCairoRenderer with Cairo < 1.12
cairo_surface_create_similar_image() introduced by the changes of
d6afb66388 is only available in 1.12 and later,
check for it being available and fall back to cairo_surface_create_similar()
with older versions.

This should fix Travis CI builds.
2016-03-28 17:51:16 +02:00
Artur Wieczorek
ab891932cd Added additional check if source bitmap is valid in wxCairoRenderer::CreateSubBitmap.
Check if source bitmap contains Cairo surface.
2016-03-24 23:00:08 +01:00
Artur Wieczorek
5ea0a0f5f9 Fixed creating Cairo bitmap from wxBitmap (wxMSW).
Fixed creating wxCairoBitmapData from 32bpp wxBitmap (with and without alpha channel). This also fixes wxCairoRenderer::CreateBitmap method.
1. 32bpp bitmap can represent under MSW either ARGB or RGB bitmap so there is necessary to examine its real contents with wxBitmap::HasAlpha function.
2. ARGB bitmaps are premultiplied and there is not necessary to premultiply them again.
2016-03-24 22:24:54 +01:00
Artur Wieczorek
d6afb66388 Implemented wxCairoRenderer::CreateSubBitmap method. 2016-03-24 22:24:53 +01:00
Artur Wieczorek
e7a9916878 Fixed calculating widths in wxCairoContext::GetPartialTextExtents (wxMSW).
Widths from the beginning of text to the corresponding character should be calculated instead of widths of individual characters.
2016-03-17 21:06:26 +01:00
Artur Wieczorek
e26e8f38b9 Fixed wxCairoContext ctor (wxMSW).
Variable referencing Cairo surface has to be initialized to NULL because otherwise crash can happen in dtor while attempting to destroy the surface.
2016-03-17 20:52:12 +01:00
Artur Wieczorek
3bf30d14fd Implemented GetPartialTextExtents for Cairo context (wxMSW).
This implementation should work fine not only for wxMSW port.
2016-03-16 21:42:37 +01:00
Artur Wieczorek
b8e82accbe Allow creating wxCairoContext from native window (wxMSW).
Implemented new wxCairoContext ctor to allow creating Cairo context in wxCairoRenderer::CreateContextFromNativeWindow.
2016-03-16 21:42:06 +01:00
Artur Wieczorek
1fa4efc47e Implemented measuring context for Cairo renderer (wxMSW). 2016-03-16 21:41:20 +01:00
Artur Wieczorek
07274d7925 Allow creating wxGraphicsContext from memory DC with Cairo renderer (wxMSW).
Not only paint DC but also memory DC can be used as a source to create wxGraphicsContext with Cairo renderer.
2016-03-14 21:03:31 +01:00
Gilbert Pelletier
46df3a1794 Allow creating wxGraphicsContext from cairo_t object (wxMSW).
Input void* parameter of wxCairoRenderer::CreateContextFromNativeContext can represent either DC handle or pointer to cairo_t object. It can be checked if it is a real HDC or not and proper wxCairoContext ctor can be invoked.

Closes #16991.
2016-03-14 21:03:11 +01:00
Paul Cornett
371ee79f88 Avoid wxGraphicsContext offsetting on HiDPI displays
For a typical scale factor of 2, there won't be any odd-width lines,
and for any factor greater than 1.0, it won't be doing what was intended,
so just don't do it. See #17375
2016-02-22 10:25:16 -08:00
Paul Cornett
5524cec193 implement Flush() for wxImage wxGraphicsContext under Cairo and GDI+, see #16694 2015-12-20 10:20:30 -08:00
Paul Cornett
cd27b73237 flush Cairo surface before converting to wxImage 2015-12-20 10:10:04 -08:00
Paul Cornett
27a8d28029 more use of wxOVERRIDE 2015-09-06 17:20:42 -07:00
Vadim Zeitlin
b6e5a0a679 Try to avoid crashing in wxGTK wxCairoContext ctor.
Don't use an uninitialized pointer in wxCairoContext ctor from wxPrinterDC in
wxGTK if retrieving Cairo context of the DC failed, set m_context to NULL in
this case (not sure if this is still not going to crash when used in
cairo_translate() below though).
2015-05-24 02:51:54 +02:00
Dimitri Schoolwerth
8f8d58d193 Use wx-prefixed macros throughout the repository.
Change {DECLARE,IMPLEMENT}_*CLASS and {DECLARE,BEGIN,END}_EVENT_TABLE
occurrences to use the wx-prefixed version of the macros.
2015-04-23 22:00:35 +04:00
Paul Cornett
7f7c619c85 avoid duplicate initialization and warnings about initialization order
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77877 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2014-09-24 03:39:30 +00:00