From 21554166b294470ac593a1a90c82d1b4fe75c61e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 9 Jun 2018 09:45:03 +0200 Subject: Add ctor for creating colours from four unsigned char values. --- plugingui/colour.cc | 4 ++++ plugingui/colour.h | 6 +++++- plugingui/combobox.cc | 2 +- plugingui/image.cc | 11 +++++------ plugingui/knob.cc | 2 +- plugingui/lineedit.cc | 2 +- plugingui/listboxbasic.cc | 6 +++--- plugingui/scrollbar.cc | 2 +- plugingui/textedit.cc | 4 ++-- 9 files changed, 23 insertions(+), 16 deletions(-) (limited to 'plugingui') diff --git a/plugingui/colour.cc b/plugingui/colour.cc index d8cd8e9..dff1a82 100644 --- a/plugingui/colour.cc +++ b/plugingui/colour.cc @@ -54,6 +54,10 @@ Colour::Colour(float r, float g, float b, float a) data[3] = a; } +Colour::Colour(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) + : Colour(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f) +{} + Colour::Colour(Colour&& other) { if(data) diff --git a/plugingui/colour.h b/plugingui/colour.h index 0e85bc6..26f424c 100644 --- a/plugingui/colour.h +++ b/plugingui/colour.h @@ -26,13 +26,17 @@ */ #pragma once -namespace GUI { +#include + +namespace GUI +{ class Colour { public: Colour(); Colour(float grey, float alpha = 1.0f); Colour(float red, float green, float blue, float alpha = 1.0f); + Colour(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a); Colour(Colour&& other); Colour(const Colour& other); ~Colour(); diff --git a/plugingui/combobox.cc b/plugingui/combobox.cc index 6716fb1..aa2058e 100644 --- a/plugingui/combobox.cc +++ b/plugingui/combobox.cc @@ -111,7 +111,7 @@ void ComboBox::repaintEvent(RepaintEvent* repaintEvent) box.setSize(w, h); p.drawImage(0, 0, box); - p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0/255.0f, 1.0f)); p.drawText(BORDER - 4 + 3, height()/2+5 + 1 + 1, font, _text); // p.setColour(Colour(1, 1, 1)); diff --git a/plugingui/image.cc b/plugingui/image.cc index 3770fae..fc28d11 100644 --- a/plugingui/image.cc +++ b/plugingui/image.cc @@ -119,10 +119,10 @@ void Image::setError() void Image::load(const char* data, size_t size) { unsigned int iw{0}, ih{0}; - unsigned char* char_image_data{nullptr}; - unsigned int res = lodepng_decode32((unsigned char**)&char_image_data, + std::uint8_t* char_image_data{nullptr}; + unsigned int res = lodepng_decode32((std::uint8_t**)&char_image_data, &iw, &ih, - (const unsigned char*)data, size); + (const std::uint8_t*)data, size); if(res != 0) { @@ -142,9 +142,8 @@ void Image::load(const char* data, size_t size) { for(std::size_t x = 0; x < _width; ++x) { - unsigned char* ptr = &char_image_data[(x + y * _width) * 4]; - image_data.emplace_back(Colour{ptr[0] / 255.0f, ptr[1] / 255.0f, - ptr[2] / 255.0f, ptr[3] / 255.0f}); + std::uint8_t* ptr = &char_image_data[(x + y * _width) * 4]; + image_data.emplace_back(Colour{ptr[0], ptr[1], ptr[2], ptr[3]}); } } diff --git a/plugingui/knob.cc b/plugingui/knob.cc index 8e60056..aaf9735 100644 --- a/plugingui/knob.cc +++ b/plugingui/knob.cc @@ -214,7 +214,7 @@ void Knob::repaintEvent(RepaintEvent* repaintEvent) double to_y = cos((-1 * padval + 1) * 2 * M_PI) * radius * 0.8; // Draw "fat" line by drawing 9 lines with moved start/ending points. - p.setColour(Colour(1, 0, 0, 1)); + p.setColour(Colour(1.0f, 0.0f, 0.0f, 1.0f)); for(int _x = -1; _x < 2; _x++) { for(int _y = -1; _y < 2; _y++) diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc index 5dd8bc5..14cc234 100644 --- a/plugingui/lineedit.cc +++ b/plugingui/lineedit.cc @@ -212,7 +212,7 @@ void LineEdit::repaintEvent(RepaintEvent *repaintEvent) box.setSize(w, h); p.drawImage(0, 0, box); - p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0f/255.0f, 1.0f)); switch(walkstate) { case WalkLeft: diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc index 90e5b1a..b2637eb 100644 --- a/plugingui/listboxbasic.cc +++ b/plugingui/listboxbasic.cc @@ -153,7 +153,7 @@ void ListBoxBasic::repaintEvent(RepaintEvent* repaintEvent) p.drawImageStretched(0, 0, bg_img, w, h); - p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0f/255.0f, 1.0f)); int yoffset = padding / 2; int skip = scroll.value(); @@ -164,7 +164,7 @@ void ListBoxBasic::repaintEvent(RepaintEvent* repaintEvent) auto& item = items[idx]; if(idx == selected) { - p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 0.5)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0f/255.0f, 0.5f)); p.drawFilledRectangle(0, yoffset - (padding / 2), width() - 1, @@ -179,7 +179,7 @@ void ListBoxBasic::repaintEvent(RepaintEvent* repaintEvent) yoffset + (font.textHeight() + 1)); } - p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0f/255.0f, 1.0f)); p.drawText(2, yoffset + font.textHeight(), font, item.name); yoffset += font.textHeight() + padding; diff --git a/plugingui/scrollbar.cc b/plugingui/scrollbar.cc index d7edd8f..9a17d1d 100644 --- a/plugingui/scrollbar.cc +++ b/plugingui/scrollbar.cc @@ -124,7 +124,7 @@ void ScrollBar::repaintEvent(RepaintEvent* repaintEvent) p.drawImageStretched(0, 0, bg_img, width(), height()); - p.setColour(Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0f/255.0f, 1.0f)); if(!maxValue) { return; diff --git a/plugingui/textedit.cc b/plugingui/textedit.cc index fd2f891..b6945de 100644 --- a/plugingui/textedit.cc +++ b/plugingui/textedit.cc @@ -135,7 +135,7 @@ void TextEdit::preprocessText() void TextEdit::repaintEvent(RepaintEvent* repaintEvent) { - if(needs_preprocessing) + if(needs_preprocessing) { preprocessText(); } @@ -153,7 +153,7 @@ void TextEdit::repaintEvent(RepaintEvent* repaintEvent) box.setSize(width(), height()); p.drawImage(0, 0, box); - p.setColour(Colour(183.0 / 255.0, 219.0 / 255.0, 255.0 / 255.0, 1)); + p.setColour(Colour(183.0f/255.0f, 219.0f/255.0f, 255.0f/255.0f, 1.0f)); int ypos = font.textHeight() + y_border; -- cgit v1.2.3