summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/listboxbasic.cc13
-rw-r--r--plugingui/pixelbuffer.cc36
-rw-r--r--plugingui/pixelbuffer.h2
3 files changed, 37 insertions, 14 deletions
diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc
index 25cf00d..3d903a4 100644
--- a/plugingui/listboxbasic.cc
+++ b/plugingui/listboxbasic.cc
@@ -84,16 +84,13 @@ void GUI::ListBoxBasic::addItem(std::string name, std::string value)
void GUI::ListBoxBasic::addItems(std::vector<GUI::ListBoxBasic::Item> &is)
{
+ DEBUG(list, "addItems %d\n", is.size());
std::vector<GUI::ListBoxBasic::Item>::iterator i = is.begin();
while(i != is.end()) {
items.push_back(*i);
i++;
}
- int numitems = height() / (font.textHeight() + padding);
- scroll.setRange(numitems);
- scroll.setMaximum(items.size());
-
// sort
for(int x = 0; x < (int)items.size() - 1; x++) {
for(int y = 0; y < (int)items.size() - 1; y++) {
@@ -110,6 +107,10 @@ void GUI::ListBoxBasic::addItems(std::vector<GUI::ListBoxBasic::Item> &is)
}
if(selected == -1) setSelection((int)items.size() - 1);
+
+ int numitems = height() / (font.textHeight() + padding);
+ scroll.setRange(numitems);
+ scroll.setMaximum(items.size());
}
void GUI::ListBoxBasic::clear()
@@ -161,6 +162,7 @@ void GUI::ListBoxBasic::registerValueChangeHandler(void (*handler)(void *),
void GUI::ListBoxBasic::repaintEvent(GUI::RepaintEvent *e)
{
+ DEBUG(list, "repaint\n");
GUI::Painter p(this);
p.clear();
@@ -175,7 +177,8 @@ void GUI::ListBoxBasic::repaintEvent(GUI::RepaintEvent *e)
int yoffset = padding / 2;
int skip = scroll.value();
- for(int idx = skip; idx < (int)items.size(); idx++) {
+ int numitems = height() / (font.textHeight() + padding) + 1;
+ for(int idx = skip; idx < (int)items.size() && idx < skip + numitems; idx++) {
GUI::ListBoxBasic::Item *i = &items[idx];
if(idx == selected) {
p.setColour(GUI::Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 0.5));
diff --git a/plugingui/pixelbuffer.cc b/plugingui/pixelbuffer.cc
index a593f9e..2a6bf6f 100644
--- a/plugingui/pixelbuffer.cc
+++ b/plugingui/pixelbuffer.cc
@@ -34,6 +34,11 @@ GUI::PixelBuffer::PixelBuffer(size_t width, size_t height)
realloc(width, height);
}
+GUI::PixelBuffer::~PixelBuffer()
+{
+ if(buf) free(buf);
+}
+
void GUI::PixelBuffer::realloc(size_t width, size_t height)
{
if(buf) free(buf);
@@ -42,14 +47,6 @@ void GUI::PixelBuffer::realloc(size_t width, size_t height)
this->height = height;
}
-// http://en.wikipedia.org/wiki/Alpha_compositing
-static void getAlpha(unsigned char _a, unsigned char _b, float &a, float &b)
-{
- a = _a / 255.0;
- b = _b / 255.0;
- b *= (1-a);
-}
-
#define PX(k) (x + y * width) * 3 + k
void GUI::PixelBuffer::setPixel(size_t x, size_t y,
unsigned char red,
@@ -58,7 +55,7 @@ void GUI::PixelBuffer::setPixel(size_t x, size_t y,
unsigned char alpha)
{
if(x >= width || y >= height) return;
-
+ /*
float a,b;
getAlpha(alpha, 255, a, b);
@@ -68,6 +65,14 @@ void GUI::PixelBuffer::setPixel(size_t x, size_t y,
buf[PX(1)] /= (a + b);
buf[PX(2)] = (unsigned char)((float)blue * a + (float)buf[PX(2)] * b);
buf[PX(2)] /= (a + b);
+ */
+ unsigned int a = alpha;
+ unsigned int b = 255 - alpha;
+
+ buf[PX(0)] = (unsigned char)(((int)red * a + (int)buf[PX(0)] * b) / 255);
+ buf[PX(1)] = (unsigned char)(((int)green * a + (int)buf[PX(1)] * b) / 255);
+ buf[PX(2)] = (unsigned char)(((int)blue * a + (int)buf[PX(2)] * b) / 255);
+
}
static int idx = 0;
@@ -79,6 +84,11 @@ GUI::PixelBufferAlpha::PixelBufferAlpha(size_t width, size_t height)
realloc(width, height);
}
+GUI::PixelBufferAlpha::~PixelBufferAlpha()
+{
+ if(buf) free(buf);
+}
+
void GUI::PixelBufferAlpha::realloc(size_t width, size_t height)
{
if(buf) free(buf);
@@ -103,6 +113,14 @@ void GUI::PixelBufferAlpha::setPixel(size_t x, size_t y,
buf[PX(3)] = alpha;
}
+// http://en.wikipedia.org/wiki/Alpha_compositing
+static void getAlpha(unsigned char _a, unsigned char _b, float &a, float &b)
+{
+ a = _a / 255.0;
+ b = _b / 255.0;
+ b *= (1-a);
+}
+
void GUI::PixelBufferAlpha::addPixel(size_t x, size_t y,
unsigned char red,
unsigned char green,
diff --git a/plugingui/pixelbuffer.h b/plugingui/pixelbuffer.h
index 2b73503..2785eb1 100644
--- a/plugingui/pixelbuffer.h
+++ b/plugingui/pixelbuffer.h
@@ -36,6 +36,7 @@ namespace GUI {
class PixelBuffer {
public:
PixelBuffer(size_t width, size_t height);
+ ~PixelBuffer();
void realloc(size_t width, size_t height);
@@ -53,6 +54,7 @@ public:
class PixelBufferAlpha {
public:
PixelBufferAlpha(size_t width, size_t height);
+ ~PixelBufferAlpha();
int idx;
size_t x, y;