summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-03-07 21:46:19 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2020-04-09 16:44:42 +0200
commitd521dd29b038472aa1d2269def96fdf6663cf1b0 (patch)
tree77bcf64f657b3a099b1579700695925618d7b748 /plugingui
parentcf49b305a0c9e10a8b08ac626019f1502c5f12ee (diff)
WIP: Experimental highlight stretching.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/drumkittab.cc30
-rw-r--r--plugingui/knob.cc2
-rw-r--r--plugingui/painter.cc73
-rw-r--r--plugingui/painter.h24
4 files changed, 114 insertions, 15 deletions
diff --git a/plugingui/drumkittab.cc b/plugingui/drumkittab.cc
index 701fcff..7be0562 100644
--- a/plugingui/drumkittab.cc
+++ b/plugingui/drumkittab.cc
@@ -80,7 +80,7 @@ void DrumkitTab::resize(std::size_t width, std::size_t height)
*drumkit_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
}
velocity_label.move(10, height-velocity_label.height()-5);
@@ -101,7 +101,7 @@ void DrumkitTab::buttonEvent(ButtonEvent* buttonEvent)
*map_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
shows_overlay = true;
redraw();
return;
@@ -115,7 +115,7 @@ void DrumkitTab::buttonEvent(ButtonEvent* buttonEvent)
*drumkit_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
highlightInstrument(current_index);
@@ -145,14 +145,14 @@ void DrumkitTab::buttonEvent(ButtonEvent* buttonEvent)
*drumkit_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
if(shows_overlay)
{
painter.drawImageStretched(drumkit_image_x, drumkit_image_y,
*map_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
}
highlightInstrument(current_index);
redraw();
@@ -189,7 +189,7 @@ void DrumkitTab::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent)
*drumkit_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
if(shows_overlay)
{
@@ -197,7 +197,7 @@ void DrumkitTab::mouseMoveEvent(MouseMoveEvent* mouseMoveEvent)
*map_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
}
highlightInstrument(index);
@@ -215,7 +215,7 @@ void DrumkitTab::mouseLeaveEvent()
*drumkit_image,
drumkit_image->width() * drumkit_scale,
drumkit_image->height() * drumkit_scale,
- Filter::Linear);
+ Filter::Nearest);
shows_overlay = false;
redraw();
@@ -250,9 +250,17 @@ void DrumkitTab::highlightInstrument(int index)
Painter painter(*this);
auto const& colour = colours[index];
//Colour colour(1.0f, 1.0f, 0.0f);
- auto const& positions = colour_index_to_positions[index];
- painter.draw(positions.begin(), positions.end(),
- drumkit_image_x, drumkit_image_y, colour, drumkit_scale);
+ //auto const& positions = colour_index_to_positions[index];
+// painter.draw(positions.begin(), positions.end(),
+// drumkit_image_x, drumkit_image_y, colour, drumkit_scale);
+
+ painter.drawRestrictedImageStretched(drumkit_image_x, drumkit_image_y,
+ colour,
+ *map_image,
+ drumkit_image->width() * drumkit_scale,
+ drumkit_image->height() * drumkit_scale,
+ Filter::Nearest);
+
shows_instrument_overlay = true;
}
else
diff --git a/plugingui/knob.cc b/plugingui/knob.cc
index 25200a7..d61abac 100644
--- a/plugingui/knob.cc
+++ b/plugingui/knob.cc
@@ -204,7 +204,7 @@ void Knob::repaintEvent(RepaintEvent* repaintEvent)
sprintf(buf, "%.2f", current_value * range + minimum);
}
p.drawText(center_x - font.textWidth(buf) / 2 + 1,
- center_y + font.textHeight(buf) / 2 + 1, font, buf);
+ center_y + font.textHeight(buf) / 2 + 1, font, buf);
}
// Make it start from 20% and stop at 80%
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index ba1e621..cc7c66e 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -452,7 +452,7 @@ void Painter::drawRestrictedImage(int x0, int y0,
assert(x0 + x < pixbuf.width);
assert(y0 + y < pixbuf.height);
- if(c == restriction_colour)
+ if(c == restriction_colour && c.alpha() > 0)
{
pixbuf.setPixel(x0 + x, y0 + y, c);
}
@@ -460,6 +460,77 @@ void Painter::drawRestrictedImage(int x0, int y0,
}
}
+void Painter::drawRestrictedImageStretched(int x0, int y0,
+ const Colour& restriction_colour,
+ const Drawable& image,
+ int width, int height, Filter filter)
+{
+ float fw = image.width();
+ float fh = image.height();
+
+ // Make sure we don't try to draw outside the pixbuf.
+ if(width > (int)(pixbuf.width - x0))
+ {
+ width = pixbuf.width - x0;
+ }
+
+ if(height > (int)(pixbuf.height - y0))
+ {
+ height = pixbuf.height - y0;
+ }
+
+ if((width < 1) || (height < 1))
+ {
+ return;
+ }
+
+ switch(filter)
+ {
+ case Filter::Nearest:
+ for(int y = -1 * std::min(0, y0); y < height; ++y)
+ {
+ for(int x = -1 * std::min(0, x0); x < width; ++x)
+ {
+ int lx = ((float)x / (float)width) * fw;
+ int ly = ((float)y / (float)height) * fh;
+ auto& c = image.getPixel(lx, ly);
+ if(c == restriction_colour && c.alpha() > 0)
+ {
+ pixbuf.addPixel(x0 + x, y0 + y, restriction_colour);
+ }
+ }
+ }
+ break;
+
+ case Filter::Linear:
+ for(int y = -1 * std::min(0, y0); y < height; ++y)
+ {
+ for(int x = -1 * std::min(0, x0); x < width; ++x)
+ {
+ float lx = ((float)x / (float)width) * fw;
+ float ly = ((float)y / (float)height) * fh;
+ float px = lx - std::floor(lx);
+ float py = ly - std::floor(ly);
+ //printf("px: %f, py: %f\n", px, py);
+ // 1,1 2,1
+ // 1,2 2,2
+ auto c11 = image.getPixel(std::floor(lx), std::floor(ly));
+ auto c12 = image.getPixel(std::floor(lx), std::ceil(ly));
+ auto c21 = image.getPixel(std::ceil(lx), std::floor(ly));
+ auto c22 = image.getPixel(std::ceil(lx), std::ceil(ly));
+ auto c1 = c11 * (1 - px) + c21 * px;
+ auto c2 = c12 * (1 - px) + c22 * px;
+ auto c = c1 * (1 - py) + c2 * py;
+ if(c == restriction_colour && c.alpha() > 0)
+ {
+ pixbuf.addPixel(x0 + x, y0 + y, restriction_colour);
+ }
+ }
+ }
+ break;
+ }
+}
+
void Painter::drawImageStretched(int x0, int y0, const Drawable& image,
int width, int height, Filter filter)
{
diff --git a/plugingui/painter.h b/plugingui/painter.h
index 3bdbe2d..a1ea6f1 100644
--- a/plugingui/painter.h
+++ b/plugingui/painter.h
@@ -27,6 +27,7 @@
#pragma once
#include <string>
+#include <cmath>
#include "colour.h"
#include "pixelbuffer.h"
@@ -64,6 +65,10 @@ public:
void drawImage(int x, int y, const Drawable& image);
void drawRestrictedImage(int x0, int y0, const Colour& restriction_colour,
const Drawable& image);
+ void drawRestrictedImageStretched(int x0, int y0,
+ const Colour& restriction_colour,
+ const Drawable& image,
+ int width, int height, Filter filter);
void drawImageStretched(int x, int y, const Drawable& image,
int width, int height,
Filter filter = Filter::Nearest);
@@ -101,9 +106,24 @@ private:
template<typename Iterator>
void Painter::draw(Iterator begin, Iterator end, int x_offset, int y_offset, Colour const& colour, double scale)
{
- for (auto it = begin; it != end; ++it)
+ if(scale > 1)
{
- pixbuf.addPixel(x_offset + it->x * scale, y_offset + it->y * scale, colour);
+ auto tmp = this->colour;
+ setColour(colour);
+ for (auto it = begin; it != end; ++it)
+ {
+ drawFilledCircle(x_offset + it->x * scale, y_offset + it->y * scale,
+ std::ceil(scale));
+ }
+ setColour(tmp);
+ }
+ else
+ {
+ for (auto it = begin; it != end; ++it)
+ {
+ pixbuf.addPixel(x_offset + it->x * scale, y_offset + it->y * scale,
+ colour);
+ }
}
}