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