Dessiner cercles
This commit is contained in:
parent
8e1108d534
commit
f2aae2a502
|
@ -38,6 +38,10 @@ public:
|
|||
bool wintabAvailable = false;
|
||||
PACKET pkt = { 0 };
|
||||
UINT maxPressure = 1;
|
||||
float extX;
|
||||
float extY;
|
||||
float extZ;
|
||||
float extP;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -66,16 +70,21 @@ private:
|
|||
ctx.lcInExtX = TabletX.axMax;
|
||||
ctx.lcOutOrgX = TabletX.axMin;
|
||||
ctx.lcOutExtX = TabletX.axMax;
|
||||
extX = TabletX.axMax;
|
||||
|
||||
ctx.lcInOrgY = TabletY.axMin;
|
||||
ctx.lcInExtY = TabletY.axMax;
|
||||
ctx.lcOutOrgY = TabletY.axMin;
|
||||
ctx.lcOutExtY = TabletY.axMax;
|
||||
extY = TabletY.axMax;
|
||||
|
||||
ctx.lcInOrgZ = TabletZ.axMin;
|
||||
ctx.lcInExtZ = TabletZ.axMax;
|
||||
ctx.lcOutOrgZ = TabletZ.axMin;
|
||||
ctx.lcOutExtZ = TabletZ.axMax;
|
||||
extZ = TabletZ.axMax;
|
||||
|
||||
extP = TabletPressure.axMax;
|
||||
|
||||
hctx = gpWTOpenA(hwnd, &ctx, FALSE);
|
||||
|
||||
|
|
|
@ -5,183 +5,234 @@ START_NAMESPACE_DISTRHO
|
|||
|
||||
class TabUI : public UI
|
||||
{
|
||||
static const uint kInitialWidth = 405;
|
||||
static const uint kInitialHeight = 256;
|
||||
static const uint kInitialWidth = 405;
|
||||
static const uint kInitialHeight = 256;
|
||||
|
||||
public:
|
||||
TabUI()
|
||||
: UI(kInitialWidth, kInitialHeight),
|
||||
fSampleRate(getSampleRate()),
|
||||
fResizable(isResizable()),
|
||||
fScale(1.0f),
|
||||
fScaleFactor(getScaleFactor()),
|
||||
tab(reinterpret_cast<HWND>(getWindow().getNativeWindowHandle()))
|
||||
{
|
||||
std::memset(fParameters, 0, sizeof(float) * kParameterCount);
|
||||
std::memset(fStrBuf, 0, sizeof(char) * (0xff + 1));
|
||||
TabUI()
|
||||
: UI(kInitialWidth, kInitialHeight),
|
||||
fSampleRate(getSampleRate()),
|
||||
fResizable(isResizable()),
|
||||
fScale(1.0f),
|
||||
fScaleFactor(getScaleFactor()),
|
||||
tab(reinterpret_cast<HWND>(getWindow().getNativeWindowHandle()))
|
||||
{
|
||||
std::memset(fParameters, 0, sizeof(float) * kParameterCount);
|
||||
std::memset(fStrBuf, 0, sizeof(char) * (0xff + 1));
|
||||
|
||||
#ifdef DGL_NO_SHARED_RESOURCES
|
||||
createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
|
||||
createFontFromFile("sans", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf");
|
||||
#else
|
||||
loadSharedResources();
|
||||
loadSharedResources();
|
||||
#endif
|
||||
|
||||
setGeometryConstraints(kInitialWidth, kInitialHeight, true);
|
||||
}
|
||||
|
||||
setGeometryConstraints(kInitialWidth, kInitialHeight, true);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void parameterChanged(uint32_t index, float value) override
|
||||
{
|
||||
void parameterChanged(uint32_t index, float value) override
|
||||
{
|
||||
|
||||
fParameters[index] = value;
|
||||
fParameters[index] = value;
|
||||
|
||||
//Lire donnés de la tablet
|
||||
tab.NewPacket();
|
||||
fParameters[kParameterTabletX] = static_cast<float>(tab.pkt.pkX);
|
||||
fParameters[kParameterTabletY] = static_cast<float>(tab.pkt.pkY);
|
||||
fParameters[kParameterTabletZ] = static_cast<float>(tab.pkt.pkZ);
|
||||
fParameters[kParameterTabletPressure] = static_cast<float>(tab.pkt.pkNormalPressure);
|
||||
//Lire donnés de la tablet
|
||||
tab.NewPacket();
|
||||
|
||||
float x = 1000.0f * static_cast<float>(tab.pkt.pkX) / tab.extX;
|
||||
float y = 1000.0f * static_cast<float>(tab.pkt.pkY) / tab.extY;
|
||||
float z = 1000.0f * static_cast<float>(tab.pkt.pkZ) / tab.extZ;
|
||||
float p = 1000.0f * static_cast<float>(tab.pkt.pkNormalPressure) / tab.extP;
|
||||
|
||||
fParameters[kParameterTabletX] = x;
|
||||
fParameters[kParameterTabletY] = y;
|
||||
fParameters[kParameterTabletZ] = z;
|
||||
fParameters[kParameterTabletPressure] = p;
|
||||
|
||||
|
||||
repaint();
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
void sampleRateChanged(double newSampleRate) override
|
||||
{
|
||||
fSampleRate = newSampleRate;
|
||||
repaint();
|
||||
}
|
||||
void sampleRateChanged(double newSampleRate) override
|
||||
{
|
||||
fSampleRate = newSampleRate;
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
void onNanoDisplay() override
|
||||
{
|
||||
const float lineHeight = 20 * fScale;
|
||||
void onNanoDisplay() override
|
||||
{
|
||||
drawCircle(
|
||||
fParameters[kParameterTabletX],
|
||||
fParameters[kParameterTabletY],
|
||||
fParameters[kParameterTabletZ],
|
||||
fParameters[kParameterTabletPressure]
|
||||
);
|
||||
|
||||
fontSize(15.0f * fScale);
|
||||
textLineHeight(lineHeight);
|
||||
const float lineHeight = 20 * fScale;
|
||||
|
||||
fontSize(15.0f * fScale);
|
||||
textLineHeight(lineHeight);
|
||||
|
||||
|
||||
|
||||
float x = 0.0f * fScale;
|
||||
float y = 15.0f * fScale;
|
||||
float x = 0.0f * fScale;
|
||||
float y = 15.0f * fScale;
|
||||
|
||||
if (!tab.wintabAvailable) {
|
||||
drawLeft(x, y, "Failed to connect to tablet.");
|
||||
return;
|
||||
}
|
||||
if (!tab.wintabAvailable) {
|
||||
drawLeft(x, y, "Failed to connect to tablet.");
|
||||
return;
|
||||
}
|
||||
|
||||
drawLeft(x, y, "x:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletX]));
|
||||
y += lineHeight;
|
||||
drawLeft(x, y, "x:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletX]));
|
||||
y += lineHeight;
|
||||
|
||||
drawLeft(x, y, "y:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletY]));
|
||||
y += lineHeight;
|
||||
drawLeft(x, y, "y:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletY]));
|
||||
y += lineHeight;
|
||||
|
||||
drawLeft(x, y, "z:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletZ]));
|
||||
y += lineHeight;
|
||||
drawLeft(x, y, "z:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletZ]));
|
||||
y += lineHeight;
|
||||
|
||||
drawLeft(x, y, "p:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletPressure]));
|
||||
y += lineHeight;
|
||||
}
|
||||
drawLeft(x, y, "p:");
|
||||
drawRight(x, y, getTextBufFloat(fParameters[kParameterTabletPressure]));
|
||||
y += lineHeight;
|
||||
|
||||
void onResize(const ResizeEvent& ev) override
|
||||
{
|
||||
fScale = static_cast<float>(ev.size.getHeight()) / static_cast<float>(kInitialHeight);
|
||||
}
|
||||
|
||||
UI::onResize(ev);
|
||||
}
|
||||
void drawCircle(float x, float y, float z, float p) {
|
||||
|
||||
void uiScaleFactorChanged(const double scaleFactor) override
|
||||
{
|
||||
fScaleFactor = scaleFactor;
|
||||
}
|
||||
static constexpr float circleRadius = 25.f;
|
||||
x *= getWidth() * 0.001f;
|
||||
y = (1000.f - y) * getHeight() * 0.001f;
|
||||
z = 1.f - z * 0.001f;
|
||||
p *= 0.001f;
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
beginPath();
|
||||
strokeColor(1.f, 1.f, 1.f, 0.5f);
|
||||
moveTo(x - z * circleRadius, y);
|
||||
lineTo(x + z * circleRadius, y);
|
||||
stroke();
|
||||
closePath();
|
||||
|
||||
beginPath();
|
||||
strokeColor(1.f, 1.f, 1.f, 0.5f);
|
||||
moveTo(x , y - z * circleRadius);
|
||||
lineTo(x , y + z * circleRadius);
|
||||
stroke();
|
||||
closePath();
|
||||
|
||||
beginPath();
|
||||
fillColor(1.f, 1.f, 1.f, p);
|
||||
strokeColor(255, 255, 255, 255);
|
||||
circle(x, y, circleRadius);
|
||||
fill();
|
||||
stroke();
|
||||
closePath();
|
||||
|
||||
beginPath();
|
||||
strokeColor(1.f, 1.f, 1.f, z);
|
||||
circle(x, y, z * circleRadius);
|
||||
stroke();
|
||||
closePath();
|
||||
}
|
||||
|
||||
void onResize(const ResizeEvent& ev) override
|
||||
{
|
||||
fScale = static_cast<float>(ev.size.getHeight()) / static_cast<float>(kInitialHeight);
|
||||
|
||||
UI::onResize(ev);
|
||||
}
|
||||
|
||||
void uiScaleFactorChanged(const double scaleFactor) override
|
||||
{
|
||||
fScaleFactor = scaleFactor;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
// Parameters
|
||||
float fParameters[kParameterCount];
|
||||
double fSampleRate;
|
||||
// Parameters
|
||||
float fParameters[kParameterCount];
|
||||
double fSampleRate;
|
||||
|
||||
// UI stuff
|
||||
bool fResizable;
|
||||
float fScale; // our internal scaling
|
||||
double fScaleFactor; // host reported scale factor
|
||||
// UI stuff
|
||||
bool fResizable;
|
||||
float fScale; // our internal scaling
|
||||
double fScaleFactor; // host reported scale factor
|
||||
|
||||
// Tablet context handler
|
||||
Tablet tab;
|
||||
// Tablet context handler
|
||||
Tablet tab;
|
||||
|
||||
// temp buf for text
|
||||
char fStrBuf[0xff + 1];
|
||||
// temp buf for text
|
||||
char fStrBuf[0xff + 1];
|
||||
|
||||
// helpers for putting text into fStrBuf and returning it
|
||||
const char* getTextBufInt(const int value)
|
||||
{
|
||||
std::snprintf(fStrBuf, 0xff, "%i", value);
|
||||
return fStrBuf;
|
||||
}
|
||||
// helpers for putting text into fStrBuf and returning it
|
||||
const char* getTextBufInt(const int value)
|
||||
{
|
||||
std::snprintf(fStrBuf, 0xff, "%i", value);
|
||||
return fStrBuf;
|
||||
}
|
||||
|
||||
const char* getTextBufFloat(const float value)
|
||||
{
|
||||
std::snprintf(fStrBuf, 0xff, "%.1f", value);
|
||||
return fStrBuf;
|
||||
}
|
||||
const char* getTextBufFloat(const float value)
|
||||
{
|
||||
std::snprintf(fStrBuf, 0xff, "%.1f", value);
|
||||
return fStrBuf;
|
||||
}
|
||||
|
||||
const char* getTextBufFloatExtra(const float value)
|
||||
{
|
||||
std::snprintf(fStrBuf, 0xff, "%.2f", value + 0.001f);
|
||||
return fStrBuf;
|
||||
}
|
||||
const char* getTextBufFloatExtra(const float value)
|
||||
{
|
||||
std::snprintf(fStrBuf, 0xff, "%.2f", value + 0.001f);
|
||||
return fStrBuf;
|
||||
}
|
||||
|
||||
const char* getTextBufTime(const uint64_t frame)
|
||||
{
|
||||
const uint32_t time = frame / uint64_t(fSampleRate);
|
||||
const uint32_t secs = time % 60;
|
||||
const uint32_t mins = (time / 60) % 60;
|
||||
const uint32_t hrs = (time / 3600) % 60;
|
||||
std::snprintf(fStrBuf, 0xff, "%02i:%02i:%02i", hrs, mins, secs);
|
||||
return fStrBuf;
|
||||
}
|
||||
const char* getTextBufTime(const uint64_t frame)
|
||||
{
|
||||
const uint32_t time = frame / uint64_t(fSampleRate);
|
||||
const uint32_t secs = time % 60;
|
||||
const uint32_t mins = (time / 60) % 60;
|
||||
const uint32_t hrs = (time / 3600) % 60;
|
||||
std::snprintf(fStrBuf, 0xff, "%02i:%02i:%02i", hrs, mins, secs);
|
||||
return fStrBuf;
|
||||
}
|
||||
|
||||
// helpers for drawing text
|
||||
void drawLeft(float x, const float y, const char* const text, const int offset = 0)
|
||||
{
|
||||
const float width = (100.0f + offset) * fScale;
|
||||
x += offset * fScale;
|
||||
beginPath();
|
||||
fillColor(200, 200, 200);
|
||||
textAlign(ALIGN_RIGHT | ALIGN_TOP);
|
||||
textBox(x, y, width, text);
|
||||
closePath();
|
||||
}
|
||||
// helpers for drawing text
|
||||
void drawLeft(float x, const float y, const char* const text, const int offset = 0)
|
||||
{
|
||||
const float width = (100.0f + offset) * fScale;
|
||||
x += offset * fScale;
|
||||
beginPath();
|
||||
fillColor(200, 200, 200);
|
||||
textAlign(ALIGN_RIGHT | ALIGN_TOP);
|
||||
textBox(x, y, width, text);
|
||||
closePath();
|
||||
}
|
||||
|
||||
void drawRight(float x, const float y, const char* const text, const int offset = 0)
|
||||
{
|
||||
const float width = (100.0f + offset) * fScale;
|
||||
x += offset * fScale;
|
||||
beginPath();
|
||||
fillColor(255, 255, 255);
|
||||
textAlign(ALIGN_LEFT | ALIGN_TOP);
|
||||
textBox(x + (105 * fScale), y, width, text);
|
||||
closePath();
|
||||
}
|
||||
void drawRight(float x, const float y, const char* const text, const int offset = 0)
|
||||
{
|
||||
const float width = (100.0f + offset) * fScale;
|
||||
x += offset * fScale;
|
||||
beginPath();
|
||||
fillColor(255, 255, 255);
|
||||
textAlign(ALIGN_LEFT | ALIGN_TOP);
|
||||
textBox(x + (105 * fScale), y, width, text);
|
||||
closePath();
|
||||
}
|
||||
|
||||
/**
|
||||
Set our UI class as non-copyable and add a leak detector just in case.
|
||||
*/
|
||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabUI)
|
||||
/**
|
||||
Set our UI class as non-copyable and add a leak detector just in case.
|
||||
*/
|
||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabUI)
|
||||
};
|
||||
|
||||
|
||||
|
||||
UI* createUI()
|
||||
{
|
||||
return new TabUI();
|
||||
return new TabUI();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue