Skip to content

Commit

Permalink
Fixup VectorJuice for auto-scaling
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Aug 14, 2021
1 parent e59b4cb commit 81f91ec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dpf
34 changes: 17 additions & 17 deletions plugins/VectorJuice/VectorJuiceUI.cpp
Expand Up @@ -42,7 +42,7 @@ VectorJuiceUI::VectorJuiceUI()
fCanvasArea.setSize(368-24, 368-24);

// background
fImgBackground = Image(VectorJuiceArtwork::backgroundData, VectorJuiceArtwork::backgroundWidth, VectorJuiceArtwork::backgroundHeight, GL_BGR);
fImgBackground = Image(VectorJuiceArtwork::backgroundData, VectorJuiceArtwork::backgroundWidth, VectorJuiceArtwork::backgroundHeight, kImageFormatBGR);

//roundlet
fImgRoundlet = Image(VectorJuiceArtwork::roundletData, VectorJuiceArtwork::roundletWidth, VectorJuiceArtwork::roundletHeight);
Expand All @@ -54,7 +54,7 @@ VectorJuiceUI::VectorJuiceUI()
fImgSubOrbit = Image(VectorJuiceArtwork::subOrbitData, VectorJuiceArtwork::subOrbitWidth, VectorJuiceArtwork::subOrbitHeight);

// about
Image aboutImage(VectorJuiceArtwork::aboutData, VectorJuiceArtwork::aboutWidth, VectorJuiceArtwork::aboutHeight, GL_BGR);
Image aboutImage(VectorJuiceArtwork::aboutData, VectorJuiceArtwork::aboutWidth, VectorJuiceArtwork::aboutHeight, kImageFormatBGR);
fAboutWindow.setImage(aboutImage);

// about button
Expand Down Expand Up @@ -344,12 +344,12 @@ void VectorJuiceUI::onDisplay()
fImgBackground.draw(context);

// get x, y mapped to XY area
int x = fCanvasArea.getX() + paramX*fCanvasArea.getWidth() - fImgRoundlet.getWidth()/2;
int y = fCanvasArea.getY() + paramY*fCanvasArea.getHeight() - fImgRoundlet.getHeight()/2;
int nOrbitX = fCanvasArea.getX()+((orbitX)*fCanvasArea.getWidth())-15;
int nOrbitY = fCanvasArea.getY()+((orbitY)*fCanvasArea.getWidth())-15;
int nSubOrbitX = fCanvasArea.getX()+(subOrbitX*fCanvasArea.getWidth())-15;
int nSubOrbitY = fCanvasArea.getY()+(subOrbitY*fCanvasArea.getWidth())-14;
const int x = fCanvasArea.getX() + paramX*fCanvasArea.getWidth() - fImgRoundlet.getWidth()/2;
const int y = fCanvasArea.getY() + paramY*fCanvasArea.getHeight() - fImgRoundlet.getHeight()/2;
const int nOrbitX = fCanvasArea.getX()+((orbitX)*fCanvasArea.getWidth())-15;
const int nOrbitY = fCanvasArea.getY()+((orbitY)*fCanvasArea.getWidth())-15;
const int nSubOrbitX = fCanvasArea.getX()+(subOrbitX*fCanvasArea.getWidth())-15;
const int nSubOrbitY = fCanvasArea.getY()+(subOrbitY*fCanvasArea.getWidth())-14;

//draw lines, just for fun
glEnable(GL_BLEND);
Expand All @@ -365,13 +365,10 @@ void VectorJuiceUI::onDisplay()
glVertex2i(nSubOrbitX+15, nSubOrbitY+14);
glEnd();

// reset color
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

// draw roundlet and orbits
fImgRoundlet.drawAt(x, y);
fImgOrbit.drawAt(nOrbitX, nOrbitY);
fImgSubOrbit.drawAt(nSubOrbitX, nSubOrbitY);
fImgRoundlet.drawAt(context, x, y);
fImgOrbit.drawAt(context, nOrbitX, nOrbitY);
fImgSubOrbit.drawAt(context, nSubOrbitX, nSubOrbitY);
}

bool VectorJuiceUI::onMouse(const MouseEvent& ev)
Expand All @@ -381,7 +378,9 @@ bool VectorJuiceUI::onMouse(const MouseEvent& ev)

if (ev.press)
{
if (! fCanvasArea.contains(ev.pos))
const double scaling = getWidth() / static_cast<double>(VectorJuiceArtwork::backgroundWidth);

if (! fCanvasArea.containsAfterScaling(ev.pos, scaling))
return false;

fDragging = true;
Expand All @@ -404,6 +403,7 @@ bool VectorJuiceUI::onMotion(const MotionEvent& ev)
if (! fDragging)
return false;

const double scaling = getWidth() / static_cast<double>(VectorJuiceArtwork::backgroundWidth);
const int x = ev.pos.getX();
const int y = ev.pos.getY();

Expand All @@ -422,8 +422,8 @@ bool VectorJuiceUI::onMotion(const MotionEvent& ev)
float newX = paramX;
float newY = paramY;

newX -= float(movedX)/fCanvasArea.getWidth();
newY -= float(movedY)/fCanvasArea.getHeight();
newX -= float(movedX)/fCanvasArea.getWidth()/scaling;
newY -= float(movedY)/fCanvasArea.getHeight()/scaling;

if (newX < 0.0f)
newX = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion plugins/VectorJuice/VectorJuiceUI.hpp
Expand Up @@ -88,7 +88,7 @@ class VectorJuiceUI : public UI,
bool fDragValid;
int fLastX;
int fLastY;
DGL_NAMESPACE::Rectangle<int> fCanvasArea;
DGL_NAMESPACE::Rectangle<double> fCanvasArea;
float orbitX, orbitY, subOrbitX, subOrbitY;
};

Expand Down

0 comments on commit 81f91ec

Please sign in to comment.