Skip to content

Commit ac6900e

Browse files
committed
Add Mat3 modelview parameter to Widget::draw
1 parent 0f80641 commit ac6900e

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/jngl/Container.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Copyright 2020-2024 Jan Niklas Hasse <jhasse@bixense.com>
1+
// Copyright 2020-2026 Jan Niklas Hasse <jhasse@bixense.com>
22
// For conditions of distribution and use, see copyright notice in LICENSE.txt
33
#include "Container.hpp"
44

55
#include "Finally.hpp"
66
#include "Widget.hpp"
7+
#include "matrix.hpp"
78

89
#include <algorithm>
910

@@ -39,7 +40,7 @@ void Container::step() {
3940

4041
void Container::draw() const {
4142
for (const auto& widget : widgets) {
42-
widget->draw();
43+
widget->draw(modelview());
4344
}
4445
}
4546

src/jngl/Widget.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2020 Jan Niklas Hasse <jhasse@bixense.com>
1+
// Copyright 2020-2026 Jan Niklas Hasse <jhasse@bixense.com>
22
// For conditions of distribution and use, see copyright notice in LICENSE.txt
33

44
#include "Widget.hpp"
55

6+
#include "../opengl.hpp"
67
#include "effects.hpp"
7-
#include "matrix.hpp"
88

99
#include <algorithm>
1010

@@ -18,13 +18,13 @@ Widget::~Widget() = default;
1818
Widget::Action Widget::step() {
1919
for (const auto& effect : effects) {
2020
switch (effect->step()) {
21-
case jngl::Effect::Action::NONE:
22-
break;
23-
case jngl::Effect::Action::REMOVE_EFFECT:
24-
removeEffect(effect.get());
25-
break;
26-
case jngl::Effect::Action::REMOVE_WIDGET:
27-
return Action::REMOVE;
21+
case jngl::Effect::Action::NONE:
22+
break;
23+
case jngl::Effect::Action::REMOVE_EFFECT:
24+
removeEffect(effect.get());
25+
break;
26+
case jngl::Effect::Action::REMOVE_WIDGET:
27+
return Action::REMOVE;
2828
}
2929
}
3030
if (!needToRemove.empty()) {
@@ -40,21 +40,20 @@ Widget::Action Widget::step() {
4040
return Action::NONE;
4141
}
4242

43-
void Widget::draw() const {
44-
jngl::pushMatrix();
45-
jngl::translate(position);
43+
void Widget::draw(Mat3 modelview) const {
44+
std::swap(opengl::modelview, modelview);
45+
opengl::modelview.translate(position);
4646
for (const auto& effect : effects) {
4747
effect->beginDraw();
4848
}
49-
auto mv = jngl::modelview();
5049
for (const auto& effect : effects) {
51-
effect->updateModelview(mv);
50+
effect->updateModelview(opengl::modelview);
5251
}
53-
drawSelf(mv);
52+
drawSelf(opengl::modelview);
5453
for (const auto& effect : effects) {
5554
effect->endDraw();
5655
}
57-
jngl::popMatrix();
56+
std::swap(opengl::modelview, modelview);
5857
}
5958

6059
void Widget::addEffect(std::unique_ptr<Effect> e) {

src/jngl/Widget.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2024 Jan Niklas Hasse <jhasse@bixense.com>
1+
// Copyright 2020-2026 Jan Niklas Hasse <jhasse@bixense.com>
22
// For conditions of distribution and use, see copyright notice in LICENSE.txt
33
/// Contains jngl::Container class
44
/// @file
@@ -34,7 +34,7 @@ class Widget {
3434
[[nodiscard]] virtual Action step();
3535

3636
/// Draws the widget with all effects applied
37-
virtual void draw() const;
37+
virtual void draw(Mat3 modelview) const;
3838

3939
/// Override this function to draw the widget
4040
virtual void drawSelf(Mat3 modelview) const = 0;

0 commit comments

Comments
 (0)