mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 01:35:34 +00:00
Float to string
This commit is contained in:
parent
1509e8a327
commit
c9a10c9b2e
@ -110,21 +110,21 @@ void ADDroplet::Draw() {
|
|||||||
10,
|
10,
|
||||||
Font_6x8,
|
Font_6x8,
|
||||||
"A: " +
|
"A: " +
|
||||||
std::to_string(static_cast<uint32_t>(1000*ad[0].GetAttack())) +
|
FloatToString(ad[0].GetAttack(), 2) +
|
||||||
"ms");
|
"s");
|
||||||
WriteString(Patch(),
|
WriteString(Patch(),
|
||||||
GetScreenMin(),
|
GetScreenMin(),
|
||||||
20,
|
20,
|
||||||
Font_6x8,
|
Font_6x8,
|
||||||
"D: " +
|
"D: " +
|
||||||
std::to_string(static_cast<uint32_t>(1000*ad[0].GetDecay())) +
|
FloatToString(ad[0].GetDecay(), 2) +
|
||||||
"ms");
|
"s");
|
||||||
WriteString(Patch(),
|
WriteString(Patch(),
|
||||||
GetScreenMin(),
|
GetScreenMin(),
|
||||||
30,
|
30,
|
||||||
Font_6x8,
|
Font_6x8,
|
||||||
"C: " +
|
"C: " +
|
||||||
std::to_string(static_cast<uint32_t>(1000*ad[0].GetCurve())));
|
FloatToString(ad[0].GetCurve(), 2));
|
||||||
if(GetState() == DropletState::kFull) {
|
if(GetState() == DropletState::kFull) {
|
||||||
int mid = (GetScreenMax() - GetScreenMin())/2;
|
int mid = (GetScreenMax() - GetScreenMin())/2;
|
||||||
WriteString(Patch(),
|
WriteString(Patch(),
|
||||||
@ -132,21 +132,21 @@ void ADDroplet::Draw() {
|
|||||||
10,
|
10,
|
||||||
Font_6x8,
|
Font_6x8,
|
||||||
"A: " +
|
"A: " +
|
||||||
std::to_string(static_cast<uint32_t>(1000*ad[1].GetAttack())) +
|
FloatToString(ad[1].GetAttack(), 2) +
|
||||||
"ms");
|
"s");
|
||||||
WriteString(Patch(),
|
WriteString(Patch(),
|
||||||
mid,
|
mid,
|
||||||
20,
|
20,
|
||||||
Font_6x8,
|
Font_6x8,
|
||||||
"D: " +
|
"D: " +
|
||||||
std::to_string(static_cast<uint32_t>(1000*ad[1].GetDecay())) +
|
FloatToString(ad[1].GetDecay(), 2) +
|
||||||
"ms");
|
"s");
|
||||||
WriteString(Patch(),
|
WriteString(Patch(),
|
||||||
mid,
|
mid,
|
||||||
30,
|
30,
|
||||||
Font_6x8,
|
Font_6x8,
|
||||||
"C: " +
|
"C: " +
|
||||||
std::to_string(static_cast<uint32_t>(1000*ad[1].GetCurve())));
|
FloatToString(ad[1].GetCurve(), 2));
|
||||||
}
|
}
|
||||||
DrawName("AD");
|
DrawName("AD");
|
||||||
}
|
}
|
||||||
|
18
src/util.cpp
18
src/util.cpp
@ -115,3 +115,21 @@ std::string WaveToString(uint8_t wf) {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string FloatToString(float num, int places) {
|
||||||
|
std::string sign = "";
|
||||||
|
int integral = static_cast<int>(num);
|
||||||
|
int fractional = static_cast<int>((abs(num) - abs(integral))
|
||||||
|
* pow(10, places));
|
||||||
|
if (num < 0.0f && num > -1.0f) {
|
||||||
|
sign = "-";
|
||||||
|
}
|
||||||
|
return sign + std::to_string(integral) + "." + std::to_string(fractional);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "daisy_patch.h"
|
#include "daisy_patch.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
using namespace daisy;
|
using namespace daisy;
|
||||||
using namespace daisysp;
|
using namespace daisysp;
|
||||||
@ -138,4 +139,12 @@ void WriteDoubleCentered(DaisyPatch* patch,
|
|||||||
*/
|
*/
|
||||||
std::string WaveToString(uint8_t wf);
|
std::string WaveToString(uint8_t wf);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converts float to formatted string.
|
||||||
|
*
|
||||||
|
* @param input number
|
||||||
|
* @param number of decimal places
|
||||||
|
*/
|
||||||
|
std::string FloatToString(float num, int places);
|
||||||
|
|
||||||
#endif // CASCADE_UTIL_H_
|
#endif // CASCADE_UTIL_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user