In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Description
The existing wxDC and all derived class-related device environments do not achieve anti-aliasing. After all, wxDC is only an encapsulation of CDC, and only GDI+ supports anti-aliasing.
The core reason for defining static variables such as rasterizer in the following code is that it allocates a large amount of memory when performing rendering calculations, which is easy to cause memory fragmentation, of course agg::pixfmt_bgra32 and agg::renderer_scanline_aa_solid
There is no memory allocation, but for the sake of unity, it is constructed as a static variable. in fact, the area pointed to by the applied rendering cache should also be set to static variables, and then by specifying width and height, memory fragmentation can be avoided to the maximum extent.
Code
Header file
# include "wx/wx.h"
# include "agg/agg_scanline_p.h"
# include "agg/agg_renderer_scanline.h"
# include "agg/agg_pixfmt_rgba.h"
# include "agg/agg_rasterizer_scanline_aa.h"
Struct PosCoordinate
{
Double x
Double y
}
Class CFlightInstrumentCompassCtrl: public wxControl
{
Private:
DECLARE_EVENT_TABLE ()
Public:
CFlightInstrumentCompassCtrl () {Init ();}
Void Init () {}
CFlightInstrumentCompassCtrl (wxWindow * parent
WxWindowID id
Const wxPoint& pos = wxDefaultPosition
Const wxSize& size = wxDefaultSize
Long style = 0
Const wxValidator& validator = wxDefaultValidator)
{
Init ()
Create (parent, id, pos, size, style, validator)
}
Bool Create (wxWindow * parent
WxWindowID id
Const wxPoint& pos = wxDefaultPosition
Const wxSize& size = wxDefaultSize
Long style = 0
Const wxValidator& validator = wxDefaultValidator)
~ CFlightInstrumentCompassCtrl (void)
Void SetCompassParameter (double leanAngle, double leanDistance, int rollAngle)
Void SetSize (wxSize size)
{
M_size = size
}
Private:
Void GetFitCircleInfo (double & circleRaduis, double & circleCenterX, double & circleCenterY)
Private:
Double m_arrowDiviationAngle
Double m_arrowAngle
Double m_leanDistance
Int m_curRollAngle
WxSize m_size
Protected:
Void OnPaint (wxPaintEvent& event)
Void OnEraseBackground (wxEraseEvent& event)
Public:
/ / declare a pair of AGG objects that need to be used, because they are static variables and need to be defined in the source file, otherwise there will be an unparsed external symbol error
Static agg::rendering_buffer m_rbuf
Static agg::pixfmt_bgra32 m_pixf
Static agg::renderer_base m_renb
Static agg::renderer_scanline_aa_solid m_ren
Static agg::rasterizer_scanline_aa m_ras
Static agg::scanline_p8 m_sl
}
Source file
# include "flightinstrumentcompass.h"
# include "wx/msw/window.h"
# include
# include "wx/dc.h"
BEGIN_EVENT_TABLE (CFlightInstrumentCompassCtrl, wxControl)
EVT_PAINT (CFlightInstrumentCompassCtrl::OnPaint)
EVT_ERASE_BACKGROUND (CFlightInstrumentCompassCtrl::OnEraseBackground)
END_EVENT_TABLE ()
/ / definition of static AGG object
Agg::rendering_buffer CFlightInstrumentCompassCtrl::m_rbuf
Agg::pixfmt_bgra32 CFlightInstrumentCompassCtrl::m_pixf
Agg::renderer_base CFlightInstrumentCompassCtrl::m_renb
Agg::renderer_scanline_aa_solid CFlightInstrumentCompassCtrl::m_ren
Agg::rasterizer_scanline_aa CFlightInstrumentCompassCtrl::m_ras
Agg::scanline_p8 CFlightInstrumentCompassCtrl::m_sl
Bool CFlightInstrumentCompassCtrl::Create (wxWindow * parent
WxWindowID id
Const wxPoint& pos
Const wxSize& size
Long style
Const wxValidator& validator)
{
If (! wxControl::Create (parent, id, pos, size, style, validator))
{
Return false
}
Return true
}
CFlightInstrumentCompassCtrl::~CFlightInstrumentCompassCtrl (void)
{
}
Void CFlightInstrumentCompassCtrl::OnPaint (wxPaintEvent& event)
{
WXHWND hWnd = GetHWND ()
PAINTSTRUCT ps
HDC hdc = BeginPaint (hWnd, & ps)
RECT rt
:: GetClientRect (hWnd, & rt)
Int width = rt.right-rt.left
Int height = rt.bottom-rt.top
BITMAPINFO bmp_info
Bmp_info.bmiHeader.biSize = sizeof (BITMAPINFOHEADER)
Bmp_info.bmiHeader.biWidth = width
Bmp_info.bmiHeader.biHeight = height
Bmp_info.bmiHeader.biPlanes = 1
Bmp_info.bmiHeader.biBitCount = 32
Bmp_info.bmiHeader.biCompression = BI_RGB
Bmp_info.bmiHeader.biSizeImage = 0
Bmp_info.bmiHeader.biXPelsPerMeter = 0
Bmp_info.bmiHeader.biYPelsPerMeter = 0
Bmp_info.bmiHeader.biClrUsed = 0
Bmp_info.bmiHeader.biClrImportant = 0
HDC mem_dc =:: CreateCompatibleDC (hdc)
Void* buf = 0
HBITMAP bmp =:: CreateDIBSection (
Mem_dc
& bmp_info
DIB_RGB_COLORS
& buf
0
0
);
/ / Selecting the object before doing anything allows you
/ / to use AGG together with native Windows GDI.
HBITMAP temp = (HBITMAP):: SelectObject (mem_dc, bmp)
/ / =
/ / AGG lowest level code.
M_rbuf.attach ((unsigned char*) buf, width, height,-width*4); / / Use negative stride in order
M_pixf.attach (m_rbuf)
M_renb.attach (m_pixf)
M_ren.attach (m_renb)
M_renb.clear (agg::rgba8 (255,255,255,255))
M_ras.move_to_d (20.7,34.15)
M_ras.line_to_d (398.23, 123.43)
M_ras.line_to_d (165.45, 401.87)
/ / Setting the attrribute (color) & Rendering
M_ren.color (agg::rgba8 (80,90,60))
Agg::render_scanlines (m_ras, m_sl, m_ren)
/ / =
/ /-
/ / Display the p_w_picpath. If the p_w_picpath is B-G-R-A (32-bits per pixel)
/ / one can use AlphaBlend instead of BitBlt. In case of AlphaBlend
/ / one also should clear the p_w_picpath with zero alpha, i.e. Rgba8 (0pr 0j0j0j0pl 0)
:: BitBlt (
Hdc
Rt.left
Rt.top
Width
Height
Mem_dc
0
0
SRCCOPY
);
/ / Free resources
:: SelectObject (mem_dc, temp)
:: DeleteObject (bmp)
:: DeleteObject (mem_dc)
EndPaint (hWnd, & ps)
Return
}
Be careful
1 in order to be able to use wxDC-derived classes such as wxClientDC, you need to include the header file wx/wx.h, otherwise the following compilation error occurs when calling DrawText to render fonts: DrawTextW is not a member of wxClientDC
2 after using AGG rendering, it is not necessary to use a derived class of wxDC for rendering. AGG rendering is to first build a bitmap, then finish rendering on this basis, and paste the image. If you want to use wxClientDC, it will cause flicker. If you use wxMemoryDC (also build a memory bitmap and then map it), you can only use the cropping function to map a certain area, and it is impossible to carry out mixed rendering, otherwise it will overwrite the existing rendering, and in the process of stretching the window, you will find that AGG rendering is successful. But wxClientDC and others can't see any rendering results.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.