Skip to content

Commit af4212c

Browse files
authored
Merge pull request #358 from OneLoneCoder/develop
V2.24 Homogenise
2 parents 147c25a + 0365c10 commit af4212c

File tree

7 files changed

+1465
-237
lines changed

7 files changed

+1465
-237
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ olcPixelGameEngine is used by 100s, if not 1000s of programmers at all levels of
4242
Please see https://github.com/OneLoneCoder/olcPixelGameEngine/wiki
4343

4444
# License (OLC-3)
45-
46-
Copyright 2018, 2019, 2020, 2021, 2022, 2023 OneLoneCoder.com
45+
Copyright 2018 - 2024 OneLoneCoder.com
4746

4847
Redistribution and use in source and binary forms, with or without
4948
modification, are permitted provided that the following conditions

extensions/olcPGEX_QuickGUI.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
OneLoneCoder - QuickGUI v1.02
2+
OneLoneCoder - QuickGUI v1.03
33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
A semi-immediate mode GUI for very simple GUI stuff.
55
Includes:
@@ -15,7 +15,7 @@
1515
License (OLC-3)
1616
~~~~~~~~~~~~~~~
1717
18-
Copyright 2018 - 2021 OneLoneCoder.com
18+
Copyright 2018 - 2024 OneLoneCoder.com
1919
2020
Redistribution and use in source and binary forms, with or without
2121
modification, are permitted provided that the following conditions
@@ -56,7 +56,7 @@
5656
5757
Author
5858
~~~~~~
59-
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022
59+
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022, 2023, 2024
6060
6161
Changes
6262
~~~~~~~
@@ -68,6 +68,7 @@
6868
+ListBox::bSelectionChanged flag, true when list selected item changes
6969
=Fix - Text box mouse behaviours, mouse release is now meaningless
7070
+CheckBox Fix for decal display
71+
v1.03 =Fix ImageCheckBox
7172
7273
*/
7374

@@ -807,6 +808,12 @@ namespace olc::QuickGUI
807808
return;
808809

809810
ImageButton::DrawDecal(pge);
811+
812+
if (bChecked)
813+
{
814+
pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colClick);
815+
pge->DrawDecal(vPos + olc::vi2d(4, 4), pIcon.Decal());
816+
}
810817

811818
pge->SetDecalMode(olc::DecalMode::WIREFRAME);
812819
pge->FillRectDecal(vPos + olc::vf2d(2, 2), vSize - olc::vf2d(4, 4), m_manager.colBorder);

extensions/olcPGEX_SplashScreen.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
License (OLC-3)
1818
~~~~~~~~~~~~~~~
1919
20-
Copyright 2018 - 2022 OneLoneCoder.com
20+
Copyright 2018 - 2024 OneLoneCoder.com
2121
2222
Redistribution and use in source and binary forms, with or without
2323
modification, are permitted provided that the following conditions
@@ -58,7 +58,7 @@
5858
5959
Author
6060
~~~~~~
61-
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022
61+
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022, 2023, 2024
6262
6363
Revisions:
6464
1.00: Initial Release
@@ -210,8 +210,8 @@ namespace olc
210210
pge->DrawPartialDecal(vScale * vBoom[y * spr.Sprite()->width + x].first * 2.0f, spr.Decal(), olc::vf2d(x, y), { 1, 1 }, vScale * 2.0f, olc::PixelF(1.0f, 1.0f, 1.0f, std::min(1.0f, std::max(4.0f - fParticleTime, 0.0f))));
211211
}
212212

213-
olc::vi2d vSize = pge->GetTextSizeProp("Copyright OneLoneCoder.com 2022");
214-
pge->DrawStringPropDecal(olc::vf2d(float(pge->ScreenWidth()/2) - vSize.x/2, float(pge->ScreenHeight()) - vSize.y * 3.0f), "Copyright OneLoneCoder.com 2022", olc::PixelF(1.0f, 1.0f, 1.0f, 0.5f), olc::vf2d(1.0, 2.0f));
213+
olc::vi2d vSize = pge->GetTextSizeProp("Copyright OneLoneCoder.com 2024");
214+
pge->DrawStringPropDecal(olc::vf2d(float(pge->ScreenWidth()/2) - vSize.x/2, float(pge->ScreenHeight()) - vSize.y * 3.0f), "Copyright OneLoneCoder.com 2023", olc::PixelF(1.0f, 1.0f, 1.0f, 0.5f), olc::vf2d(1.0, 2.0f));
215215
return true;
216216
}
217217

extensions/olcPGEX_TransformedView.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
+-------------------------------------------------------------+
55
| OneLoneCoder Pixel Game Engine Extension |
6-
| Transformed View v1.08 |
6+
| Transformed View v1.09 |
77
+-------------------------------------------------------------+
88
99
NOTE: UNDER ACTIVE DEVELOPMENT - THERE ARE BUGS/GLITCHES
@@ -18,7 +18,7 @@
1818
License (OLC-3)
1919
~~~~~~~~~~~~~~~
2020
21-
Copyright 2018 - 2022 OneLoneCoder.com
21+
Copyright 2018 - 2024 OneLoneCoder.com
2222
2323
Redistribution and use in source and binary forms, with or without
2424
modification, are permitted provided that the following conditions
@@ -59,7 +59,7 @@
5959
6060
Author
6161
~~~~~~
62-
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022
62+
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022, 2023, 2024
6363
6464
Revisions:
6565
1.00: Initial Release
@@ -74,6 +74,10 @@
7474
1.07: +DrawRectDecal()
7575
+GetPGE()
7676
1.08: +DrawPolygonDecal() with tint overload, akin to PGE
77+
1.09: +SetScaleExtents() - Sets range that world scale can exist within
78+
+EnableScaleClamp() - Applies a range that scaling is clamped to
79+
These are both useful for having zoom clamped between a min and max
80+
without weird panning artefacts occuring
7781
*/
7882

7983
#pragma once
@@ -116,6 +120,9 @@ namespace olc
116120
virtual bool IsPointVisible(const olc::vf2d& vPos) const;
117121
virtual bool IsRectVisible(const olc::vf2d& vPos, const olc::vf2d& vSize) const;
118122
virtual void HandlePanAndZoom(const int nMouseButton = 2, const float fZoomRate = 0.1f, const bool bPan = true, const bool bZoom = true);
123+
void SetScaleExtents(const olc::vf2d& vScaleMin, const olc::vf2d& vScaleMax);
124+
void EnableScaleClamp(const bool bEnable);
125+
119126
protected:
120127
olc::vf2d m_vWorldOffset = { 0.0f, 0.0f };
121128
olc::vf2d m_vWorldScale = { 1.0f, 1.0f };
@@ -124,6 +131,9 @@ namespace olc
124131
bool m_bPanning = false;
125132
olc::vf2d m_vStartPan = { 0.0f, 0.0f };
126133
olc::vi2d m_vViewArea;
134+
bool m_bZoomClamp = false;
135+
olc::vf2d m_vMaxScale = { 0.0f, 0.0f };
136+
olc::vf2d m_vMinScale = { 0.0f, 0.0f };
127137

128138
public: // Hopefully, these should look familiar!
129139
// Plots a single point
@@ -253,6 +263,7 @@ namespace olc
253263
void TransformedView::SetWorldScale(const olc::vf2d& vScale)
254264
{
255265
m_vWorldScale = vScale;
266+
if (m_bZoomClamp) m_vWorldScale = m_vWorldScale.clamp(m_vMinScale, m_vMaxScale);
256267
}
257268

258269
void TransformedView::SetViewArea(const olc::vi2d& vViewArea)
@@ -275,10 +286,22 @@ namespace olc
275286
return GetWorldBR() - GetWorldTL();
276287
}
277288

289+
void TransformedView::SetScaleExtents(const olc::vf2d& vScaleMin, const olc::vf2d& vScaleMax)
290+
{
291+
m_vMaxScale = vScaleMax;
292+
m_vMinScale = vScaleMin;
293+
}
294+
295+
void TransformedView::EnableScaleClamp(const bool bEnable)
296+
{
297+
m_bZoomClamp = bEnable;
298+
}
299+
278300
void TransformedView::ZoomAtScreenPos(const float fDeltaZoom, const olc::vi2d& vPos)
279301
{
280302
olc::vf2d vOffsetBeforeZoom = ScreenToWorld(vPos);
281303
m_vWorldScale *= fDeltaZoom;
304+
if (m_bZoomClamp) m_vWorldScale = m_vWorldScale.clamp(m_vMinScale, m_vMaxScale);
282305
olc::vf2d vOffsetAfterZoom = ScreenToWorld(vPos);
283306
m_vWorldOffset += vOffsetBeforeZoom - vOffsetAfterZoom;
284307
}
@@ -287,6 +310,7 @@ namespace olc
287310
{
288311
olc::vf2d vOffsetBeforeZoom = ScreenToWorld(vPos);
289312
m_vWorldScale = { fZoom, fZoom };
313+
if (m_bZoomClamp) m_vWorldScale = m_vWorldScale.clamp(m_vMinScale, m_vMaxScale);
290314
olc::vf2d vOffsetAfterZoom = ScreenToWorld(vPos);
291315
m_vWorldOffset += vOffsetBeforeZoom - vOffsetAfterZoom;
292316
}

olcPixelGameEngine.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
olcPixelGameEngine.h
44
55
+-------------------------------------------------------------+
6-
| OneLoneCoder Pixel Game Engine v2.23 |
6+
| OneLoneCoder Pixel Game Engine v2.24 |
77
| "What do you need? Pixels... Lots of Pixels..." - javidx9 |
88
+-------------------------------------------------------------+
99
@@ -193,11 +193,11 @@
193193
Special thanks to my Patreons too - I wont name you on here, but I've
194194
certainly enjoyed my tea and flapjacks :D
195195
196-
196+
- In Memory of SaladinAkara 25.06.2023 -
197197
198198
Author
199199
~~~~~~
200-
David Barr, aka javidx9, (c) OneLoneCoder 2018, 2019, 2020, 2021, 2022
200+
David Barr, aka javidx9, (c) OneLoneCoder 2018, 2019, 2020, 2021, 2022, 2023, 2024
201201
*/
202202
#pragma endregion
203203

@@ -318,6 +318,7 @@
318318
2.22: = Fix typo on dragged file buffers for unicode builds
319319
2.23: Fixed Emscripten host sizing errors - Thanks Moros
320320
Fixed v2d_generic.clamp() function
321+
2.24: Fix FillTexturedTriangle() to remove const-ref
321322
322323
!! Apple Platforms will not see these updates immediately - Sorry, I dont have a mac to test... !!
323324
!! Volunteers willing to help appreciated, though PRs are manually integrated with credit !!
@@ -397,7 +398,7 @@ int main()
397398
#include <cstring>
398399
#pragma endregion
399400

400-
#define PGE_VER 223
401+
#define PGE_VER 224
401402

402403
// O------------------------------------------------------------------------------O
403404
// | COMPILER CONFIGURATION ODDITIES |
@@ -1086,7 +1087,7 @@ namespace olc
10861087
void FillTriangle(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, Pixel p = olc::WHITE);
10871088
void FillTriangle(const olc::vi2d& pos1, const olc::vi2d& pos2, const olc::vi2d& pos3, Pixel p = olc::WHITE);
10881089
// Fill a textured and coloured triangle
1089-
void FillTexturedTriangle(const std::vector<olc::vf2d>& vPoints, std::vector<olc::vf2d> vTex, std::vector<olc::Pixel> vColour, olc::Sprite* sprTex);
1090+
void FillTexturedTriangle(std::vector<olc::vf2d> vPoints, std::vector<olc::vf2d> vTex, std::vector<olc::Pixel> vColour, olc::Sprite* sprTex);
10901091
void FillTexturedPolygon(const std::vector<olc::vf2d>& vPoints, const std::vector<olc::vf2d>& vTex, const std::vector<olc::Pixel>& vColour, olc::Sprite* sprTex, olc::DecalStructure structure = olc::DecalStructure::LIST);
10911092
// Draws an entire sprite at location (x,y)
10921093
void DrawSprite(int32_t x, int32_t y, Sprite* sprite, uint32_t scale = 1, uint8_t flip = olc::Sprite::NONE);
@@ -2187,8 +2188,8 @@ namespace olc
21872188
auto rol = [&](void) { pattern = (pattern << 1) | (pattern >> 31); return pattern & 1; };
21882189

21892190
olc::vi2d p1(x1, y1), p2(x2, y2);
2190-
//if (!ClipLineToScreen(p1, p2))
2191-
// return;
2191+
if (!ClipLineToScreen(p1, p2))
2192+
return;
21922193
x1 = p1.x; y1 = p1.y;
21932194
x2 = p2.x; y2 = p2.y;
21942195

@@ -2580,7 +2581,7 @@ namespace olc
25802581
}
25812582
}
25822583

2583-
void PixelGameEngine::FillTexturedTriangle(const std::vector<olc::vf2d>& vPoints, std::vector<olc::vf2d> vTex, std::vector<olc::Pixel> vColour, olc::Sprite* sprTex)
2584+
void PixelGameEngine::FillTexturedTriangle(std::vector<olc::vf2d> vPoints, std::vector<olc::vf2d> vTex, std::vector<olc::Pixel> vColour, olc::Sprite* sprTex)
25842585
{
25852586
olc::vi2d p1 = vPoints[0];
25862587
olc::vi2d p2 = vPoints[1];
@@ -2996,7 +2997,7 @@ namespace olc
29962997
di.pos[i] = { (pos[i].x * vInvScreenSize.x) * 2.0f - 1.0f, ((pos[i].y * vInvScreenSize.y) * 2.0f - 1.0f) * -1.0f };
29972998
di.uv[i] = uv[i];
29982999
di.tint[i] = tint;
2999-
di.w[i] = 1.0f;
3000+
di.w[i] = depth[i];
30003001
}
30013002
di.mode = nDecalMode;
30023003
di.structure = nDecalStructure;

utilities/olcUTIL_Animate2D.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
OneLoneCoder - Animate2D v1.00
2+
OneLoneCoder - Animate2D v1.01
33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
Handles animated Sprites efficiently
55
66
77
License (OLC-3)
88
~~~~~~~~~~~~~~~
99
10-
Copyright 2018 - 2022 OneLoneCoder.com
10+
Copyright 2018 - 2024 OneLoneCoder.com
1111
1212
Redistribution and use in source and binary forms, with or without
1313
modification, are permitted provided that the following conditions
@@ -48,14 +48,19 @@
4848
4949
Author
5050
~~~~~~
51-
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022
51+
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020, 2021, 2022, 2023, 2024
5252
53+
54+
Versions
55+
~~~~~~~~
56+
1.01 +PingPong Style Animation
5357
*/
5458

5559
#pragma once
5660

5761
#include "olcPixelGameEngine.h"
5862
#include "utilities/olcUTIL_Geometry2D.h"
63+
#include <unordered_map>
5964

6065
namespace olc::utils::Animate2D
6166
{
@@ -141,7 +146,11 @@ namespace olc::utils::Animate2D
141146
return std::clamp(size_t(fTime * m_fFrameRate), size_t(0), m_vFrames.size() - 1);
142147
break;
143148
case Style::PingPong:
144-
// TODO
149+
{
150+
// Thanks @sigonasr2 (discord)
151+
size_t frame = size_t(m_fFrameRate * fTime) % (m_vFrames.size() * 2 - 1);
152+
return frame >= m_vFrames.size() ? m_vFrames.size() - frame % m_vFrames.size() - 1 : frame;
153+
}
145154
break;
146155
case Style::Reverse:
147156
return (m_vFrames.size() - 1) - (size_t(fTime * m_fFrameRate) % m_vFrames.size());

0 commit comments

Comments
 (0)