wx_BGI_Graphics
Classic BGI-compatible graphics API with modern OpenGL extension API
Loading...
Searching...
No Matches
wx_bgi_canvas.h
Go to the documentation of this file.
1#pragma once
2// wx_bgi_canvas.h — WxBgiCanvas: BGI drawing surface embedded in a wxWidgets panel.
3// Include this header in your application AFTER the wxWidgets headers.
4//
5// WxBgiCanvas is compiled into the wx_bgi_wx static library (not the DLL),
6// so it uses your application''s copy of wxWidgets — no DLL-boundary issues.
7
8#include <wx/glcanvas.h>
9#include "wx_bgi.h"
10#include "wx_bgi_ext.h"
11
12namespace wxbgi {
13
31class WxBgiCanvas : public wxGLCanvas
32{
33public:
34 explicit WxBgiCanvas(wxWindow* parent,
35 wxWindowID id = wxID_ANY,
36 const wxPoint& pos = wxDefaultPosition,
37 const wxSize& size = wxDefaultSize,
38 long style = 0,
39 const wxString& name = wxASCII_STR("WxBgiCanvas"));
40
41 ~WxBgiCanvas() override;
42
44 void Render();
45
50 void SetAutoRefreshHz(int hz);
51
52protected:
65 virtual void PreBlit(int w, int h) { (void)w; (void)h; }
66
80 virtual void PostBlit(int pageW, int pageH, int vpW, int vpH)
81 {
82 (void)pageW; (void)pageH; (void)vpW; (void)vpH;
83 }
84
85private:
86 wxGLContext* m_glContext{nullptr};
87 bool m_ownsGLCtx{false};
88 bool m_glewInited{false};
89 bool m_bgiInited{false};
90 int m_autoRefreshHz{0};
91 wxLongLong_t m_lastRenderMs{0};
92
93public:
103 virtual void OnPaint(wxPaintEvent& evt);
104
115 virtual void OnSize(wxSizeEvent& evt);
116
127 virtual void OnIdle(wxIdleEvent& evt);
128
139 virtual void OnKeyDown(wxKeyEvent& evt);
140
151 virtual void OnKeyUp(wxKeyEvent& evt);
152
163 virtual void OnChar(wxKeyEvent& evt);
164
175 virtual void OnMouseMove(wxMouseEvent& evt);
176
187 virtual void OnMouseDown(wxMouseEvent& evt);
188
199 virtual void OnMouseUp(wxMouseEvent& evt);
200
211 virtual void OnMouseWheel(wxMouseEvent& evt);
212
213private:
214 static int WxKeyToGlfw(int wxKey);
215
225 void RouteKeyEvent(wxKeyEvent& evt, int action);
226};
227
228} // namespace wxbgi
virtual void OnPaint(wxPaintEvent &evt)
Handles paint events for the canvas.
~WxBgiCanvas() override
virtual void OnMouseDown(wxMouseEvent &evt)
Handles mouse button press events.
virtual void OnSize(wxSizeEvent &evt)
Handles resize events for the canvas.
virtual void PostBlit(int pageW, int pageH, int vpW, int vpH)
Called AFTER wxbgi_wx_render_page_gl_vp() and all 3-D solid GL passes, but BEFORE SwapBuffers().
Definition wx_bgi_canvas.h:80
virtual void OnChar(wxKeyEvent &evt)
Handles character input events.
virtual void OnKeyUp(wxKeyEvent &evt)
Handles key release events.
virtual void PreBlit(int w, int h)
Called inside Render() after the GL context is current and BGI is initialised, but before the BGI pix...
Definition wx_bgi_canvas.h:65
virtual void OnKeyDown(wxKeyEvent &evt)
Handles key press events.
virtual void OnMouseMove(wxMouseEvent &evt)
Handles mouse movement over the canvas.
virtual void OnMouseUp(wxMouseEvent &evt)
Handles mouse button release events.
virtual void OnMouseWheel(wxMouseEvent &evt)
Handles mouse wheel events.
virtual void OnIdle(wxIdleEvent &evt)
Handles idle events for auto-refresh.
void SetAutoRefreshHz(int hz)
Enable idle-driven auto-refresh at the requested frame rate.
WxBgiCanvas(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxASCII_STR("WxBgiCanvas"))
void Render()
Render the BGI buffer immediately.
Definition wx_bgi_canvas.h:12
Public classic BGI-compatible C API exported by the library.
Advanced non-BGI extension API for modern OpenGL workflows.