Add Direct2D support to wxSTC
This commit is contained in:
28
include/wx/msw/private/graphicsd2d.h
Normal file
28
include/wx/msw/private/graphicsd2d.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/msw/private/graphicsd2d.h
|
||||
// Purpose: Allow functions from graphicsd2d.cpp to be used in othe files
|
||||
// Author: New Pagodi
|
||||
// Created: 2017-10-31
|
||||
// Copyright: (c) 2017 wxWidgets development team
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef WX_MSW_PRIVATE_GRAPHICSD2D_H_
|
||||
#define WX_MSW_PRIVATE_GRAPHICSD2D_H_
|
||||
|
||||
#if wxUSE_GRAPHICS_DIRECT2D
|
||||
|
||||
// Ensure no previous defines interfere with the Direct2D API headers
|
||||
#undef GetHwnd
|
||||
|
||||
#include <d2d1.h>
|
||||
#include <dwrite.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
WXDLLIMPEXP_CORE IWICImagingFactory* wxWICImagingFactory();
|
||||
WXDLLIMPEXP_CORE ID2D1Factory* wxD2D1Factory();
|
||||
WXDLLIMPEXP_CORE IDWriteFactory* wxDWriteFactory();
|
||||
|
||||
#endif // wxUSE_GRAPHICS_DIRECT2D
|
||||
|
||||
#endif // WX_MSW_PRIVATE_GRAPHICSD2D_H_
|
@@ -3963,6 +3963,12 @@ public:
|
||||
// to overlap from one line to the next.
|
||||
void SetPhasesDraw(int phases);
|
||||
|
||||
// Choose the quality level for text.
|
||||
void SetFontQuality(int fontQuality);
|
||||
|
||||
// Retrieve the quality level for text.
|
||||
int GetFontQuality() const;
|
||||
|
||||
// Scroll so that a display line is at the top of the display.
|
||||
void SetFirstVisibleLine(int displayLine);
|
||||
|
||||
|
@@ -5153,6 +5153,27 @@ public:
|
||||
*/
|
||||
void SetPhasesDraw(int phases);
|
||||
|
||||
/**
|
||||
Choose the quality level for text.
|
||||
|
||||
The input should be one of the
|
||||
@link wxStyledTextCtrl::wxSTC_EFF_QUALITY_DEFAULT wxSTC_EFF_QUALITY_* @endlink constants.
|
||||
@remarks
|
||||
This method only has any effect with the wxMSW port and when
|
||||
technology has been set to wxSTC_TECHNOLOGY_DIRECTWRITE.
|
||||
@since 3.1.1
|
||||
*/
|
||||
void SetFontQuality(int fontQuality);
|
||||
|
||||
/**
|
||||
Retrieve the quality level for text.
|
||||
|
||||
The return value will be one of the
|
||||
@link wxStyledTextCtrl::wxSTC_EFF_QUALITY_DEFAULT wxSTC_EFF_QUALITY_* @endlink constants.
|
||||
@since 3.1.1
|
||||
*/
|
||||
int GetFontQuality() const;
|
||||
|
||||
/**
|
||||
Change internal focus flag.
|
||||
*/
|
||||
@@ -5166,8 +5187,10 @@ public:
|
||||
/**
|
||||
Set the technology used.
|
||||
|
||||
The input should be one of the
|
||||
@link wxStyledTextCtrl::wxSTC_TECHNOLOGY_DEFAULT wxSTC_TECHNOLOGY_* @endlink constants.
|
||||
@remarks
|
||||
For the wxMSW port, the input can be either wxSTC_TECHNOLOGY_DEFAULT
|
||||
or wxSTC_TECHNOLOGY_DIRECTWRITE. With other ports, this method has
|
||||
no effect.
|
||||
*/
|
||||
void SetTechnology(int technology);
|
||||
|
||||
|
@@ -72,6 +72,7 @@
|
||||
#include "wx/private/graphics.h"
|
||||
#include "wx/stack.h"
|
||||
#include "wx/sharedptr.h"
|
||||
#include "wx/msw/private/graphicsd2d.h"
|
||||
|
||||
// This must be the last header included to only affect the DEFINE_GUID()
|
||||
// occurrences below but not any GUIDs declared in the standard files included
|
||||
@@ -219,6 +220,9 @@ wxDirect2D::DWriteCreateFactory_t wxDirect2D::DWriteCreateFactory = NULL;
|
||||
DEFINE_GUID(wxIID_IWICImagingFactory,
|
||||
0xec5ec8a9, 0xc395, 0x4314, 0x9c, 0x77, 0x54, 0xd7, 0xa9, 0x35, 0xff, 0x70);
|
||||
|
||||
DEFINE_GUID(wxIID_ID2D1Factory,
|
||||
0x06152247, 0x6f50, 0x465a, 0x92, 0x45, 0x11, 0x8b, 0xfd, 0x3b, 0x60, 0x07);
|
||||
|
||||
DEFINE_GUID(wxIID_IDWriteFactory,
|
||||
0xb859ee5a, 0xd838, 0x4b5b, 0xa2, 0xe8, 0x1a, 0xdc, 0x7d, 0x93, 0xdb, 0x48);
|
||||
|
||||
@@ -299,6 +303,39 @@ IWICImagingFactory* wxWICImagingFactory()
|
||||
return gs_WICImagingFactory;
|
||||
}
|
||||
|
||||
static ID2D1Factory* gs_ID2D1Factory = NULL;
|
||||
|
||||
ID2D1Factory* wxD2D1Factory()
|
||||
{
|
||||
if (!wxDirect2D::Initialize())
|
||||
return NULL;
|
||||
|
||||
if (gs_ID2D1Factory == NULL)
|
||||
{
|
||||
D2D1_FACTORY_OPTIONS factoryOptions = {D2D1_DEBUG_LEVEL_NONE};
|
||||
|
||||
// According to
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee794287(v=vs.85).aspx
|
||||
// the Direct2D Debug Layer is only available starting with Windows 8
|
||||
// and Visual Studio 2012.
|
||||
#if defined(__WXDEBUG__) && defined(__VISUALC__) && wxCHECK_VISUALC_VERSION(11)
|
||||
if ( wxGetWinVersion() >= wxWinVersion_8 )
|
||||
{
|
||||
factoryOptions.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
|
||||
}
|
||||
#endif //__WXDEBUG__
|
||||
|
||||
HRESULT hr = wxDirect2D::D2D1CreateFactory(
|
||||
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
||||
wxIID_ID2D1Factory,
|
||||
&factoryOptions,
|
||||
reinterpret_cast<void**>(&gs_ID2D1Factory)
|
||||
);
|
||||
wxCHECK_HRESULT_RET_PTR(hr);
|
||||
}
|
||||
return gs_ID2D1Factory;
|
||||
}
|
||||
|
||||
static IDWriteFactory* gs_IDWriteFactory = NULL;
|
||||
|
||||
IDWriteFactory* wxDWriteFactory()
|
||||
@@ -4457,13 +4494,9 @@ wxGraphicsRenderer* wxGraphicsRenderer::GetDirect2DRenderer()
|
||||
return gs_D2DRenderer;
|
||||
}
|
||||
|
||||
wxD2DRenderer::wxD2DRenderer()
|
||||
wxD2DRenderer::wxD2DRenderer():m_direct2dFactory(wxD2D1Factory())
|
||||
{
|
||||
|
||||
HRESULT result;
|
||||
result = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_direct2dFactory);
|
||||
|
||||
if (FAILED(result))
|
||||
if ( m_direct2dFactory.get() == NULL )
|
||||
{
|
||||
wxFAIL_MSG("Could not create Direct2D Factory.");
|
||||
}
|
||||
@@ -4770,6 +4803,12 @@ public:
|
||||
gs_D2DRenderer = NULL;
|
||||
}
|
||||
|
||||
if ( gs_ID2D1Factory )
|
||||
{
|
||||
gs_ID2D1Factory->Release();
|
||||
gs_ID2D1Factory = NULL;
|
||||
}
|
||||
|
||||
::CoUninitialize();
|
||||
}
|
||||
|
||||
|
1196
src/stc/PlatWX.cpp
1196
src/stc/PlatWX.cpp
File diff suppressed because it is too large
Load Diff
@@ -6,3 +6,69 @@ wxRect wxRectFromPRectangle(PRectangle prc);
|
||||
PRectangle PRectangleFromwxRect(wxRect rc);
|
||||
wxColour wxColourFromCD(const ColourDesired& ca);
|
||||
|
||||
class SurfaceData
|
||||
{
|
||||
public:
|
||||
virtual ~SurfaceData(){}
|
||||
};
|
||||
|
||||
#if wxUSE_GRAPHICS_DIRECT2D
|
||||
|
||||
#include <wx/msw/private/graphicsd2d.h>
|
||||
#include <wx/msw/private/comptr.h>
|
||||
|
||||
class ScintillaWX;
|
||||
|
||||
class SurfaceDataD2D: public SurfaceData
|
||||
{
|
||||
public:
|
||||
SurfaceDataD2D(ScintillaWX*);
|
||||
bool Initialised() const;
|
||||
void DiscardGraphicsResources();
|
||||
HRESULT CreateGraphicsResources();
|
||||
void SetEditorPaintAbandoned();
|
||||
|
||||
ID2D1DCRenderTarget* GetRenderTarget() const {return m_pRenderTarget.get();}
|
||||
ID2D1SolidColorBrush* GetSolidBrush() const {return m_pSolidBrush.get();}
|
||||
ID2D1BitmapBrush* GetPatternBrush() const {return m_pPatternBrush.get();}
|
||||
IDWriteRenderingParams* GetDefaultRenderingParams() const
|
||||
{return m_defaultRenderingParams;}
|
||||
IDWriteRenderingParams* GetCustomClearTypeRenderingParams() const
|
||||
{return m_customClearTypeRenderingParams;}
|
||||
|
||||
private:
|
||||
wxCOMPtr<ID2D1Factory> m_pD2DFactory;
|
||||
wxCOMPtr<IDWriteFactory> m_pDWriteFactory;
|
||||
wxCOMPtr<ID2D1DCRenderTarget> m_pRenderTarget;
|
||||
wxCOMPtr<ID2D1SolidColorBrush> m_pSolidBrush;
|
||||
wxCOMPtr<ID2D1BitmapBrush> m_pPatternBrush;
|
||||
wxCOMPtr<IDWriteRenderingParams> m_defaultRenderingParams;
|
||||
wxCOMPtr<IDWriteRenderingParams> m_customClearTypeRenderingParams;
|
||||
|
||||
ScintillaWX* m_editor;
|
||||
};
|
||||
|
||||
class SurfaceFontDataD2D: public SurfaceData
|
||||
{
|
||||
public:
|
||||
SurfaceFontDataD2D(const FontParameters& fp);
|
||||
bool Initialised() const;
|
||||
|
||||
XYPOSITION GetAscent() const {return m_ascent;}
|
||||
XYPOSITION GetDescent() const {return m_descent;}
|
||||
XYPOSITION GetInternalLeading() const {return m_internalLeading;}
|
||||
XYPOSITION GetAverageCharWidth() const {return m_averageCharWidth;}
|
||||
|
||||
D2D1_TEXT_ANTIALIAS_MODE GetFontQuality() const {return m_aaMode;}
|
||||
IDWriteTextFormat* GetFormat() const {return m_pTextFormat.get();}
|
||||
|
||||
private:
|
||||
XYPOSITION m_ascent;
|
||||
XYPOSITION m_descent;
|
||||
XYPOSITION m_internalLeading;
|
||||
XYPOSITION m_averageCharWidth;
|
||||
D2D1_TEXT_ANTIALIAS_MODE m_aaMode;
|
||||
wxCOMPtr<IDWriteTextFormat> m_pTextFormat;
|
||||
};
|
||||
|
||||
#endif // wxUSE_GRAPHICS_DIRECT2D
|
||||
|
@@ -118,6 +118,7 @@ public:
|
||||
m_ct(ct), m_swx(swx), m_cx(wxDefaultCoord), m_cy(wxDefaultCoord)
|
||||
{
|
||||
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
|
||||
SetName("wxSTCCallTip");
|
||||
}
|
||||
|
||||
~wxSTCCallTip() {
|
||||
@@ -134,7 +135,7 @@ public:
|
||||
void OnPaint(wxPaintEvent& WXUNUSED(evt))
|
||||
{
|
||||
wxAutoBufferedPaintDC dc(this);
|
||||
Surface* surfaceWindow = Surface::Allocate(0);
|
||||
Surface* surfaceWindow = Surface::Allocate(m_swx->technology);
|
||||
surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
|
||||
m_ct->PaintCT(surfaceWindow);
|
||||
surfaceWindow->Release();
|
||||
@@ -270,6 +271,8 @@ ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) {
|
||||
timers[tickScroll] = new wxSTCTimer(this,tickScroll);
|
||||
timers[tickWiden] = new wxSTCTimer(this,tickWiden);
|
||||
timers[tickDwell] = new wxSTCTimer(this,tickDwell);
|
||||
|
||||
m_surfaceData = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -278,6 +281,11 @@ ScintillaWX::~ScintillaWX() {
|
||||
delete i->second;
|
||||
}
|
||||
timers.clear();
|
||||
|
||||
if ( m_surfaceData != NULL ) {
|
||||
delete m_surfaceData;
|
||||
}
|
||||
|
||||
Finalise();
|
||||
}
|
||||
|
||||
@@ -817,6 +825,36 @@ sptr_t ScintillaWX::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if wxUSE_GRAPHICS_DIRECT2D
|
||||
case SCI_SETTECHNOLOGY:
|
||||
if ((wParam == SC_TECHNOLOGY_DEFAULT) || (wParam == SC_TECHNOLOGY_DIRECTWRITE)) {
|
||||
if (technology != static_cast<int>(wParam)) {
|
||||
SurfaceDataD2D* newSurfaceData(NULL);
|
||||
|
||||
if (static_cast<int>(wParam) > SC_TECHNOLOGY_DEFAULT) {
|
||||
newSurfaceData = new SurfaceDataD2D(this);
|
||||
|
||||
if (!newSurfaceData->Initialised()) {
|
||||
// Failed to load Direct2D or DirectWrite so no effect
|
||||
delete newSurfaceData;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
technology = static_cast<int>(wParam);
|
||||
if ( m_surfaceData ) {
|
||||
delete m_surfaceData;
|
||||
}
|
||||
m_surfaceData = newSurfaceData;
|
||||
|
||||
// Invalidate all cached information including layout.
|
||||
DropGraphics(true);
|
||||
InvalidateStyleRedraw();
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef SCI_LEXER
|
||||
case SCI_LOADLEXERLIBRARY:
|
||||
LexerManager::GetInstance()->Load((const char*)lParam);
|
||||
|
@@ -87,6 +87,7 @@ class WXDLLIMPEXP_FWD_CORE wxDC;
|
||||
class WXDLLIMPEXP_FWD_STC wxStyledTextCtrl; // forward
|
||||
class ScintillaWX;
|
||||
class wxSTCTimer;
|
||||
class SurfaceData;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Helper classes
|
||||
@@ -196,6 +197,8 @@ public:
|
||||
void ClipChildren(wxDC& dc, PRectangle rect);
|
||||
void SetUseAntiAliasing(bool useAA);
|
||||
bool GetUseAntiAliasing();
|
||||
SurfaceData* GetSurfaceData() const {return m_surfaceData;}
|
||||
void SetPaintAbandoned(){paintState = paintAbandoned;}
|
||||
|
||||
private:
|
||||
bool capturedMouse;
|
||||
@@ -212,6 +215,7 @@ private:
|
||||
|
||||
int wheelVRotation;
|
||||
int wheelHRotation;
|
||||
SurfaceData* m_surfaceData;
|
||||
|
||||
// For use in creating a system caret
|
||||
bool HasCaretSizeChanged();
|
||||
|
@@ -517,6 +517,7 @@ docsMap = {
|
||||
'SetMouseDwellTime':'Notifications',
|
||||
'GetBufferedDraw':'OtherSettings',
|
||||
'GetCodePage':'OtherSettings',
|
||||
'GetFontQuality':'OtherSettings',
|
||||
'GetFocus':'OtherSettings',
|
||||
'GetIMEInteraction':'OtherSettings',
|
||||
'GetPhasesDraw':'OtherSettings',
|
||||
@@ -525,6 +526,7 @@ docsMap = {
|
||||
'SetBufferedDraw':'OtherSettings',
|
||||
'SetCodePage':'OtherSettings',
|
||||
'SetFocus':'OtherSettings',
|
||||
'SetFontQuality':'OtherSettings',
|
||||
'SetIMEInteraction':'OtherSettings',
|
||||
'SetLayoutCache':'OtherSettings',
|
||||
'SetPhasesDraw':'OtherSettings',
|
||||
@@ -840,7 +842,9 @@ docSubstitutions = {
|
||||
|
||||
'SetSelectionMode':{'SC_SEL_STREAM':'wxSTC_SEL_STREAM',
|
||||
'SC_SEL_RECTANGLE':'wxSTC_SEL_RECTANGLE','SC_SEL_THIN':'wxSTC_SEL_THIN',
|
||||
'SC_SEL_LINES':'wxSTC_SEL_LINES'}
|
||||
'SC_SEL_LINES':'wxSTC_SEL_LINES'},
|
||||
|
||||
'SetFontQuality':{' from the FontQuality enumeration':''}
|
||||
}
|
||||
|
||||
|
||||
@@ -1033,10 +1037,24 @@ extendedDocs = {
|
||||
'@endlink constants.',),
|
||||
|
||||
'SetTechnology':
|
||||
('The input should be one of the',
|
||||
'@link wxStyledTextCtrl::wxSTC_TECHNOLOGY_DEFAULT wxSTC_TECHNOLOGY_* '
|
||||
('@remarks',
|
||||
'For the wxMSW port, the input can be either wxSTC_TECHNOLOGY_DEFAULT',
|
||||
'or wxSTC_TECHNOLOGY_DIRECTWRITE. With other ports, this method has',
|
||||
'no effect.',),
|
||||
|
||||
'GetFontQuality':
|
||||
('The return value will be one of the',
|
||||
'@link wxStyledTextCtrl::wxSTC_EFF_QUALITY_DEFAULT wxSTC_EFF_QUALITY_* '
|
||||
'@endlink constants.',),
|
||||
|
||||
'SetFontQuality':
|
||||
('The input should be one of the',
|
||||
'@link wxStyledTextCtrl::wxSTC_EFF_QUALITY_DEFAULT wxSTC_EFF_QUALITY_* '
|
||||
'@endlink constants.',
|
||||
'@remarks',
|
||||
'This method only has any effect with the wxMSW port and when',
|
||||
'technology has been set to wxSTC_TECHNOLOGY_DIRECTWRITE.',),
|
||||
|
||||
'GetIMEInteraction':
|
||||
('The return value will be one of the',
|
||||
'@link wxStyledTextCtrl::wxSTC_IME_WINDOWED wxSTC_IME_* @endlink constants.',),
|
||||
@@ -1362,6 +1380,7 @@ sinceAnnotations= {
|
||||
'FoldDisplayTextSetStyle':'3.1.1',
|
||||
'GetDirectFunction':'3.1.1',
|
||||
'GetDirectPointer':'3.1.1',
|
||||
'GetFontQuality':'3.1.1',
|
||||
'GetIdleStyling':'3.1.1',
|
||||
'GetLexerLanguage':'3.1.1',
|
||||
'GetMarginBackN':'3.1.1',
|
||||
@@ -1374,6 +1393,7 @@ sinceAnnotations= {
|
||||
'MultiEdgeClearAll':'3.1.1',
|
||||
'MultipleSelectAddEach':'3.1.1',
|
||||
'MultipleSelectAddNext':'3.1.1',
|
||||
'SetFontQuality':'3.1.1',
|
||||
'SetIdleStyling':'3.1.1',
|
||||
'SetMarginBackN':'3.1.1',
|
||||
'SetMargins':'3.1.1',
|
||||
|
@@ -895,8 +895,6 @@ methodOverrideMap = {
|
||||
return stc2wx(buf);'''
|
||||
),
|
||||
|
||||
'SetFontQuality' : (None, 0, 0),
|
||||
'GetFontQuality' : (None, 0, 0),
|
||||
'SetSelection' : (None, 0, 0),
|
||||
|
||||
'GetCharacterPointer' : (0,
|
||||
|
@@ -231,6 +231,10 @@ bool wxStyledTextCtrl::Create(wxWindow *parent,
|
||||
SetBufferedDraw(true);
|
||||
#endif
|
||||
|
||||
#if wxUSE_GRAPHICS_DIRECT2D
|
||||
SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2533,6 +2537,18 @@ void wxStyledTextCtrl::SetPhasesDraw(int phases)
|
||||
SendMsg(SCI_SETPHASESDRAW, phases, 0);
|
||||
}
|
||||
|
||||
// Choose the quality level for text.
|
||||
void wxStyledTextCtrl::SetFontQuality(int fontQuality)
|
||||
{
|
||||
SendMsg(SCI_SETFONTQUALITY, fontQuality, 0);
|
||||
}
|
||||
|
||||
// Retrieve the quality level for text.
|
||||
int wxStyledTextCtrl::GetFontQuality() const
|
||||
{
|
||||
return SendMsg(SCI_GETFONTQUALITY, 0, 0);
|
||||
}
|
||||
|
||||
// Scroll so that a display line is at the top of the display.
|
||||
void wxStyledTextCtrl::SetFirstVisibleLine(int displayLine)
|
||||
{
|
||||
|
@@ -231,6 +231,10 @@ bool wxStyledTextCtrl::Create(wxWindow *parent,
|
||||
SetBufferedDraw(true);
|
||||
#endif
|
||||
|
||||
#if wxUSE_GRAPHICS_DIRECT2D
|
||||
SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user