Skip to content

Commit abfe1a0

Browse files
authored
Merge pull request #219 from RobLoach/drawing-returnthis
Make Draw() functions not return the object
2 parents 67f6758 + 1ab778f commit abfe1a0

File tree

16 files changed

+135
-229
lines changed

16 files changed

+135
-229
lines changed

examples/textures/textures_image_drawing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ int main(void) {
3333
// Draw one image over the other with a scaling of 1.5f
3434
parrots
3535
.Draw(cat,
36-
raylib::Rectangle(0, 0, cat.GetWidth(), cat.GetHeight()),
37-
raylib::Rectangle(30, 40, cat.GetWidth() * 1.5f, cat.GetHeight() * 1.5f))
38-
.Crop(raylib::Rectangle(0, 50, parrots.GetWidth(), parrots.GetHeight() - 100)); // Crop resulting image
36+
raylib::Rectangle(0, 0, cat.GetWidth(), cat.GetHeight()),
37+
raylib::Rectangle(30, 40, cat.GetWidth() * 1.5f, cat.GetHeight() * 1.5f));
38+
parrots.Crop(raylib::Rectangle(0, 50, parrots.GetWidth(), parrots.GetHeight() - 100)); // Crop resulting image
3939

4040
// Load custom font for frawing on image
4141
raylib::Font font("resources/custom_jupiter_crash.png");

include/BoundingBox.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ class BoundingBox : public ::BoundingBox {
3838
/**
3939
* Draw a bounding box with wires
4040
*/
41-
inline BoundingBox& Draw(::Color color = {255, 255, 255, 255}) {
41+
inline void Draw(::Color color = {255, 255, 255, 255}) const {
4242
::DrawBoundingBox(*this, color);
43-
return *this;
4443
}
4544

4645
/**

include/Camera3D.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,24 @@ class Camera3D : public ::Camera3D {
126126
/**
127127
* Draw a billboard texture.
128128
*/
129-
inline Camera3D& DrawBillboard(
129+
inline void DrawBillboard(
130130
const ::Texture2D& texture,
131131
::Vector3 center,
132132
float size,
133-
::Color tint = {255, 255, 255, 255}) {
133+
::Color tint = {255, 255, 255, 255}) const {
134134
::DrawBillboard(*this, texture, center, size, tint);
135-
return *this;
136135
}
137136

138137
/**
139138
* Draw a billboard texture defined by source.
140139
*/
141-
inline Camera3D& DrawBillboard(
140+
inline void DrawBillboard(
142141
const ::Texture2D& texture,
143142
::Rectangle sourceRec,
144143
::Vector3 center,
145144
::Vector2 size,
146-
::Color tint = {255, 255, 255, 255}) {
145+
::Color tint = {255, 255, 255, 255}) const {
147146
::DrawBillboardRec(*this, texture, sourceRec, center, size, tint);
148-
return *this;
149147
}
150148

151149
private:

include/Color.hpp

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -111,98 +111,82 @@ class Color : public ::Color {
111111
return *this;
112112
}
113113

114-
inline Color& DrawPixel(int x, int y) {
114+
inline void DrawPixel(int x, int y) const {
115115
::DrawPixel(x, y, *this);
116-
return *this;
117116
}
118117

119118
/**
120119
* Draw a pixel
121120
*/
122-
inline Color& DrawPixel(::Vector2 pos) {
121+
inline void DrawPixel(::Vector2 pos) const {
123122
::DrawPixelV(pos, *this);
124-
return *this;
125123
}
126124

127125
/**
128126
* Draw a line
129127
*/
130-
inline Color& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) {
128+
inline void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY) const {
131129
::DrawLine(startPosX, startPosY, endPosX, endPosY, *this);
132-
return *this;
133130
}
134131

135-
inline Color& DrawLine(::Vector2 startPos, ::Vector2 endPos) {
132+
inline void DrawLine(::Vector2 startPos, ::Vector2 endPos) const {
136133
::DrawLineV(startPos, endPos, *this);
137-
return *this;
138134
}
139135

140-
inline Color& DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) {
136+
inline void DrawLine(::Vector2 startPos, ::Vector2 endPos, float thick) const {
141137
::DrawLineEx(startPos, endPos, thick, *this);
142-
return *this;
143138
}
144139

145-
inline Color& DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick) {
140+
inline void DrawLineBezier(::Vector2 startPos, ::Vector2 endPos, float thick) const {
146141
::DrawLineBezier(startPos, endPos, thick, *this);
147-
return *this;
148142
}
149143

150-
inline Color& DrawLineStrip(::Vector2 *points, int numPoints) {
144+
inline void DrawLineStrip(::Vector2 *points, int numPoints) const {
151145
::DrawLineStrip(points, numPoints, *this);
152-
return *this;
153146
}
154147

155-
inline Color& DrawText(const std::string& text, int posX, int posY, int fontSize) {
148+
inline void DrawText(const std::string& text, int posX, int posY, int fontSize) const {
156149
::DrawText(text.c_str(), posX, posY, fontSize, *this);
157-
return *this;
158150
}
159151

160-
inline Color& DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
161-
float fontSize, float spacing) {
152+
inline void DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
153+
float fontSize, float spacing) const {
162154
::DrawTextEx(font, text.c_str(), position, fontSize, spacing, *this);
163-
return *this;
164155
}
165156

166-
inline Color& DrawText(
157+
inline void DrawText(
167158
const ::Font& font,
168159
const std::string& text,
169160
::Vector2 position,
170161
::Vector2 origin,
171162
float rotation,
172163
float fontSize,
173-
float spacing) {
164+
float spacing) const {
174165
::DrawTextPro(font, text.c_str(), position, origin, rotation, fontSize, spacing, *this);
175-
return *this;
176166
}
177167

178-
inline Color& DrawRectangle(int posX, int posY, int width, int height) {
168+
inline void DrawRectangle(int posX, int posY, int width, int height) const {
179169
::DrawRectangle(posX, posY, width, height, *this);
180-
return *this;
181170
}
182171

183-
inline Color& DrawRectangle(::Vector2 position, ::Vector2 size) {
172+
inline void DrawRectangle(::Vector2 position, ::Vector2 size) const {
184173
::DrawRectangleV(position, size, *this);
185-
return *this;
186174
}
187175

188-
inline Color& DrawRectangle(::Rectangle rec) {
176+
inline void DrawRectangle(::Rectangle rec) const {
189177
::DrawRectangleRec(rec, *this);
190-
return *this;
191178
}
192179

193-
inline Color& DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation) {
180+
inline void DrawRectangle(::Rectangle rec, ::Vector2 origin, float rotation) const {
194181
::DrawRectanglePro(rec, origin, rotation, *this);
195-
return *this;
196182
}
197183

198-
inline Color& DrawRectangleLines(int posX, int posY, int width, int height) {
184+
inline void DrawRectangleLines(int posX, int posY, int width, int height) const {
199185
::DrawRectangleLines(posX, posY, width, height, *this);
200-
return *this;
201186
}
202187

203-
inline Color& DrawRectangleLines(::Rectangle rec, float lineThick) {
188+
inline void DrawRectangleLines(::Rectangle rec, float lineThick) const {
204189
::DrawRectangleLinesEx(rec, lineThick, *this);
205-
return *this;
206190
}
207191

208192
/**

include/Font.hpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,61 +209,56 @@ class Font : public ::Font {
209209
/**
210210
* Draw text using font and additional parameters.
211211
*/
212-
inline Font& DrawText(const std::string& text, ::Vector2 position, float fontSize,
213-
float spacing, ::Color tint = WHITE) {
212+
inline void DrawText(const std::string& text, ::Vector2 position, float fontSize,
213+
float spacing, ::Color tint = WHITE) const {
214214
::DrawTextEx(*this, text.c_str(), position, fontSize, spacing, tint);
215-
return *this;
216215
}
217216

218217
/**
219218
* Draw text using font and additional parameters.
220219
*/
221-
inline Font& DrawText(const std::string& text, int posX, int posY, float fontSize,
222-
float spacing, ::Color tint = WHITE) {
220+
inline void DrawText(const std::string& text, int posX, int posY, float fontSize,
221+
float spacing, ::Color tint = WHITE) const {
223222
::DrawTextEx(*this, text.c_str(),
224223
{ static_cast<float>(posX), static_cast<float>(posY) },
225224
fontSize, spacing, tint);
226-
return *this;
227225
}
228226

229-
inline Font& DrawText(
227+
inline void DrawText(
230228
const std::string& text,
231229
::Vector2 position,
232230
::Vector2 origin,
233231
float rotation,
234232
float fontSize,
235233
float spacing,
236-
::Color tint = WHITE) {
234+
::Color tint = WHITE) const {
237235
::DrawTextPro(*this, text.c_str(),
238236
position, origin,
239237
rotation, fontSize,
240238
spacing, tint);
241-
return *this;
242239
}
243240

244241
/**
245242
* Draw one character (codepoint)
246243
*/
247-
inline Font& DrawText(int codepoint,
244+
inline void DrawText(int codepoint,
248245
::Vector2 position,
249246
float fontSize,
250-
::Color tint = { 255, 255, 255, 255 }) {
247+
::Color tint = { 255, 255, 255, 255 }) const {
251248
::DrawTextCodepoint(*this, codepoint, position, fontSize, tint);
252-
return *this;
253249
}
254250

255251
/**
256252
* Draw multiple character (codepoint)
257253
*/
258-
inline Font& DrawText(const int *codepoints,
254+
inline void DrawText(const int *codepoints,
259255
int count, ::Vector2 position,
260256
float fontSize, float spacing,
261-
::Color tint = { 255, 255, 255, 255 }) {
257+
::Color tint = { 255, 255, 255, 255 }) const {
262258
::DrawTextCodepoints(*this,
263259
codepoints, count,
264260
position, fontSize,
265261
spacing, tint);
266-
return *this;
267262
}
268263

269264
/**

include/Image.hpp

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -586,89 +586,75 @@ class Image : public ::Image {
586586
/**
587587
* Draw pixel within an image
588588
*/
589-
inline Image& DrawPixel(int posX, int posY, ::Color color = {255, 255, 255, 255}) {
589+
inline void DrawPixel(int posX, int posY, ::Color color = {255, 255, 255, 255}) {
590590
::ImageDrawPixel(this, posX, posY, color);
591-
return *this;
592591
}
593592

594-
inline Image& DrawPixel(::Vector2 position, ::Color color = {255, 255, 255, 255}) {
593+
inline void DrawPixel(::Vector2 position, ::Color color = {255, 255, 255, 255}) {
595594
::ImageDrawPixelV(this, position, color);
596-
return *this;
597595
}
598596

599-
inline Image& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY,
597+
inline void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY,
600598
::Color color = {255, 255, 255, 255}) {
601599
::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
602-
return *this;
603600
}
604601

605-
inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::Color color = {255, 255, 255, 255}) {
602+
inline void DrawLine(::Vector2 start, ::Vector2 end, ::Color color = {255, 255, 255, 255}) {
606603
::ImageDrawLineV(this, start, end, color);
607-
return *this;
608604
}
609605

610-
inline Image& DrawCircle(int centerX, int centerY, int radius,
606+
inline void DrawCircle(int centerX, int centerY, int radius,
611607
::Color color = {255, 255, 255, 255}) {
612608
::ImageDrawCircle(this, centerX, centerY, radius, color);
613-
return *this;
614609
}
615610

616-
inline Image& DrawCircle(::Vector2 center, int radius,
611+
inline void DrawCircle(::Vector2 center, int radius,
617612
::Color color = {255, 255, 255, 255}) {
618613
::ImageDrawCircleV(this, center, radius, color);
619-
return *this;
620614
}
621615

622-
inline Image& DrawRectangle(int posX, int posY, int width, int height,
616+
inline void DrawRectangle(int posX, int posY, int width, int height,
623617
::Color color = {255, 255, 255, 255}) {
624618
::ImageDrawRectangle(this, posX, posY, width, height, color);
625-
return *this;
626619
}
627620

628-
inline Image& DrawRectangle(Vector2 position, Vector2 size,
621+
inline void DrawRectangle(Vector2 position, Vector2 size,
629622
::Color color = {255, 255, 255, 255}) {
630623
::ImageDrawRectangleV(this, position, size, color);
631-
return *this;
632624
}
633625

634-
inline Image& DrawRectangle(::Rectangle rec, ::Color color = {255, 255, 255, 255}) {
626+
inline void DrawRectangle(::Rectangle rec, ::Color color = {255, 255, 255, 255}) {
635627
::ImageDrawRectangleRec(this, rec, color);
636-
return *this;
637628
}
638629

639-
inline Image& DrawRectangleLines(::Rectangle rec, int thick = 1,
630+
inline void DrawRectangleLines(::Rectangle rec, int thick = 1,
640631
::Color color = {255, 255, 255, 255}) {
641632
::ImageDrawRectangleLines(this, rec, thick, color);
642-
return *this;
643633
}
644634

645-
inline Image& Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec,
635+
inline void Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec,
646636
::Color tint = {255, 255, 255, 255}) {
647637
::ImageDraw(this, src, srcRec, dstRec, tint);
648-
return *this;
649638
}
650639

651-
inline Image& DrawText(const std::string& text, ::Vector2 position, int fontSize,
640+
inline void DrawText(const std::string& text, ::Vector2 position, int fontSize,
652641
::Color color = {255, 255, 255, 255}) {
653642
::ImageDrawText(this,
654643
text.c_str(),
655644
static_cast<int>(position.x),
656645
static_cast<int>(position.y),
657646
fontSize,
658647
color);
659-
return *this;
660648
}
661649

662-
inline Image& DrawText(const std::string& text, int x, int y, int fontSize,
650+
inline void DrawText(const std::string& text, int x, int y, int fontSize,
663651
::Color color = {255, 255, 255, 255}) {
664652
::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
665-
return *this;
666653
}
667654

668-
inline Image& DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
655+
inline void DrawText(const ::Font& font, const std::string& text, ::Vector2 position,
669656
float fontSize, float spacing, ::Color tint = {255, 255, 255, 255}) {
670657
::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
671-
return *this;
672658
}
673659

674660
/**

include/Material.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@ class Material : public ::Material {
9898
/**
9999
* Draw a 3d mesh with material and transform
100100
*/
101-
inline const Material& DrawMesh(const ::Mesh& mesh, ::Matrix transform) const {
101+
inline void DrawMesh(const ::Mesh& mesh, ::Matrix transform) const {
102102
::DrawMesh(mesh, *this, transform);
103-
return *this;
104103
}
105104

106105
/**
107106
* Draw multiple mesh instances with material and different transforms
108107
*/
109-
inline const Material& DrawMesh(const ::Mesh& mesh, ::Matrix* transforms, int instances) const {
108+
inline void DrawMesh(const ::Mesh& mesh, ::Matrix* transforms, int instances) const {
110109
::DrawMeshInstanced(mesh, *this, transforms, instances);
111-
return *this;
112110
}
113111

114112
private:

include/Mesh.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ class Mesh : public ::Mesh {
198198
/**
199199
* Draw a 3d mesh with material and transform
200200
*/
201-
inline void Draw(const ::Material& material, const ::Matrix& transform) {
201+
inline void Draw(const ::Material& material, const ::Matrix& transform) const {
202202
::DrawMesh(*this, material, transform);
203203
}
204204

205205
/**
206206
* Draw multiple mesh instances with material and different transforms
207207
*/
208-
inline void Draw(const ::Material& material, ::Matrix* transforms, int instances) {
208+
inline void Draw(const ::Material& material, ::Matrix* transforms, int instances) const {
209209
::DrawMeshInstanced(*this, material, transforms, instances);
210210
}
211211

0 commit comments

Comments
 (0)