17 #include <core_ui/canvas.h> 18 #include <third_party/box2d/box2d.h> 24 class Box2dSandboxWindow;
32 virtual void render(QPainter& ,
const QRectF& ) {}
35 virtual void mousePressEvent(
const QPointF& , QMouseEvent* ) {}
36 virtual void mouseReleaseEvent(
const QPointF& , QMouseEvent* ) {}
37 virtual void mouseMoveEvent(
const QPointF& , QMouseEvent* ) {}
40 virtual void keyPressEvent(QKeyEvent* ) {}
41 virtual void keyReleaseEvent(QKeyEvent* ) {}
44 virtual void focusInEvent() {}
45 virtual void focusOutEvent() {}
49 virtual void step() {}
52 virtual QString help()
const {
return ""; }
61 const QColor kBackgroundColor{ 255, 255, 255 };
62 const QColor kViewportColor{ 240, 240, 255 };
65 explicit Box2dWidget(QWidget* parent);
67 void setWorld(b2World* world,
const QRectF& viewport);
68 void setSceneUi(Box2dSceneUi* scene_ui);
70 bool debugRender()
const {
return enable_debug_render_; }
71 void setDebugRender(
bool enable);
73 bool renderLights()
const {
return render_lights_; }
74 void setRenderLights(
bool enable);
80 void paintEvent(QPaintEvent* event)
override;
82 void mousePressEvent(QMouseEvent* event)
override;
83 void mouseReleaseEvent(QMouseEvent* event)
override;
84 void mouseMoveEvent(QMouseEvent* event)
override;
86 void keyPressEvent(QKeyEvent* event)
override;
87 void keyReleaseEvent(QKeyEvent* event)
override;
89 void focusInEvent(QFocusEvent*)
override;
90 void focusOutEvent(QFocusEvent*)
override;
92 void renderDebugLayer(QPainter& painter)
const;
93 void renderGeneric(QPainter& painter)
const;
96 b2World* world_ =
nullptr;
97 Box2dSceneUi* scene_ui_ =
nullptr;
98 bool enable_debug_render_ =
true;
99 bool render_lights_ =
false;
A reusable canvas with support for logical coordinates and auto-scalling the content.
Definition: canvas.h:36
Custom box2d scene rendering & input processing.
Definition: box2d_widget.h:27
Definition: accelerometer_widget.cpp:23