-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinates_transform_canvas_wrapper.cpp
More file actions
41 lines (32 loc) · 1.05 KB
/
coordinates_transform_canvas_wrapper.cpp
File metadata and controls
41 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "coordinates_transform_canvas_wrapper.h"
namespace breakout {
void CoordinatesTransformCanvasWrapper::draw_box(
Vector2 center,
double width,
double height,
Color color) {
canvas_->draw_box(
to_screen_vector(center),
to_screen_x(width),
to_screen_height(height),
color);
}
void CoordinatesTransformCanvasWrapper::draw_text(
Vector2 position,
std::string_view text,
Color color) {
canvas_->draw_text(to_screen_vector(position), text, color);
}
Vector2 CoordinatesTransformCanvasWrapper::to_screen_vector(Vector2 v) const {
return Vector2(to_screen_x(v.x()), to_screen_y(v.y()));
}
double CoordinatesTransformCanvasWrapper::to_screen_x(double x) const {
return x / width() * canvas_->width();
}
double CoordinatesTransformCanvasWrapper::to_screen_y(double y) const {
return (height() - y) / height() * canvas_->height();
}
double CoordinatesTransformCanvasWrapper::to_screen_height(double engine_height) const {
return engine_height / height() * canvas_->height();
}
} // namespace breakout