Skip to content

Commit

Permalink
Added RgbHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSaw committed Apr 20, 2021
1 parent 34f2dbc commit 779c042
Show file tree
Hide file tree
Showing 24 changed files with 422 additions and 216 deletions.
10 changes: 5 additions & 5 deletions examples/avr/display/dogm128/benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ main()
while (!timer.execute())
{
// rectangle in left side of screen
display.setColor(Color::black());
display.setColor(modm::color::RgbHtml::Black());
display.drawRectangle(Point(0, 0), 62, 62);

// rounded rectangle around text area
Expand All @@ -176,14 +176,14 @@ main()
display.drawCircle(Point(31, 31), 31);

// clear previous spinner position
display.setColor(Color::white());
display.setColor(modm::color::RgbHtml::White());
display.fillRectangle(Point(87, 40), 16, 16);

static uint8_t loops = 0;
display.setColor(Color::black());
display.setColor(modm::color::RgbHtml::Black());
drawSpinner(Point(95, 48), loops++);

display.setColor(Color::white());
display.setColor(modm::color::RgbHtml::White());
display.setCursor(Point(25, 40));
display << ++iter;
display.update();
Expand All @@ -192,7 +192,7 @@ main()
// print number of iterations in one second
display.clear();
display.setCursor(Point(80, 10));
display.setColor(Color::white());
display.setColor(modm::color::RgbHtml::White());
display << "FPS=" << iter;
}
}
4 changes: 2 additions & 2 deletions examples/avr/display/dogm128/draw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ main()

display.fillRectangle(Point(10, 10), 20, 20);
display.fillCircle(Point(45, 40), 23);
display.setColor(Color::white());
display.setColor(modm::color::RgbHtml::White());
display.fillRectangle(Point(20, 20), 20, 20);
display.fillCircle(Point(55, 50), 8);

display.setColor(Color::black());
display.setColor(modm::color::RgbHtml::Black());
display.drawLine(Point(0, 0), Point(127, 63));

display.update();
Expand Down
3 changes: 2 additions & 1 deletion examples/blue_pill_f103/graphics/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ main()
tft.initialize();
tft.enableBacklight(true);
LedGreen::set();
tft.setColor(modm::glcd::Color::black());
tft.setColor(modm::color::RgbHtml::Black());

int16_t w = tft.getWidth();
int16_t h = tft.getHeight();
tft.drawLine({0,0}, {w, h});
Expand Down
16 changes: 8 additions & 8 deletions examples/nucleo_l452re/graphics_touch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ main()

LedGreen::set();

tftController.setColor(modm::glcd::Color::black());
tftController.setBackgroundColor(modm::glcd::Color::red());
tftController.setColor(modm::color::RgbHtml::Black());
tftController.setBackgroundColor(modm::color::RgbHtml::Red());
tftController.clear();

tftController.setFont(modm::font::ArcadeClassic);
tftController.setColor(modm::glcd::Color::white());
tftController.setColor(modm::color::RgbHtml::White());
tftController.setCursor(10,12);
tftController << "(10,10)";
tftController.setCursor(150,202);
Expand All @@ -101,7 +101,7 @@ main()
tftController.drawLine(145, 200, 155, 200);
tftController.drawLine(150, 195, 150, 205);

tftController.setColor(modm::glcd::Color::black());
tftController.setColor(modm::color::RgbHtml::Black());
tftController.setFont(modm::font::Ubuntu_36);

int16_t X = 0;
Expand All @@ -113,19 +113,19 @@ main()
LedGreen::set();

std::tie(X, Y, Z) = RF_CALL_BLOCKING(touchController.getRawValues());
tftController.setColor(modm::glcd::Color::red());
tftController.setColor(modm::color::RgbHtml::Red());
tftController.fillRectangle({30, 50}, 90, 115);
tftController.setColor(modm::glcd::Color::black());
tftController.setColor(modm::color::RgbHtml::Black());
tftController.setCursor(0, 50);
tftController << "X=" << X;
tftController.setCursor(0, 90);
tftController << "Y=" << Y;
tftController.setCursor(0, 130);
tftController << "Z=" << Z;

tftController.setColor(modm::glcd::Color::red());
tftController.setColor(modm::color::RgbHtml::Red());
tftController.fillRectangle({30, 220}, 120, 35);
tftController.setColor(modm::glcd::Color::black());
tftController.setColor(modm::color::RgbHtml::Black());
if(RF_CALL_BLOCKING(touchController.isTouched())) {
std::tie(X, Y) = RF_CALL_BLOCKING(touchController.getTouchPosition());
tftController.setCursor(5, 220);
Expand Down
2 changes: 1 addition & 1 deletion examples/nucleo_l452re/lvgl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void my_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t *
{area->x1, area->y1},
(area->x2 - area->x1 +1),
(area->y2 - area->y1 + 1),
(modm::glcd::Color*)color_p);
(modm::color::Rgb565*)color_p);
lv_disp_flush_ready(disp_drv);
}

Expand Down
36 changes: 18 additions & 18 deletions examples/stm32_f4ve/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

#include <modm/ui/gui.hpp>


#include "touchscreen_calibrator.hpp"

#include "images/bluetooth_12x16.hpp"

using namespace modm::color;


// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -166,13 +168,13 @@ initTouchscreen()
static void
drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.setColor(RgbHtml::Red());
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
display.drawLine(center.x + 2, center.y, center.x + 15, center.y);
display.drawLine(center.x, center.y - 15, center.x, center.y - 2);
display.drawLine(center.x, center.y + 2, center.x, center.y + 15);

display.setColor(modm::glcd::Color::white());
display.setColor(RgbHtml::White());
display.drawLine(center.x - 15, center.y + 15, center.x - 7, center.y + 15);
display.drawLine(center.x - 15, center.y + 7, center.x - 15, center.y + 15);

Expand All @@ -198,7 +200,7 @@ calibrateTouchscreen(modm::GraphicDisplay& display, modm::glcd::Point *fixed_sam
{
display.clear();

display.setColor(modm::glcd::Color::yellow());
display.setColor(modm::color::RgbHtml::Yellow());
display.setCursor(50, 5);
display << "Touch crosshair to calibrate";

Expand Down Expand Up @@ -385,20 +387,18 @@ test_callback(const modm::gui::InputEvent& ev, modm::gui::Widget* w, void* data)
Board::LedGreen2::toggle();
}


modm::glcd::Color colors[modm::gui::Color::PALETTE_SIZE] {
modm::glcd::Color::black(),
modm::glcd::Color::white(),
modm::glcd::Color::gray(),
modm::glcd::Color::red(),
modm::glcd::Color::green(),
modm::glcd::Color::blue(),
modm::glcd::Color::blue(), // BORDER
modm::glcd::Color::red(), // TEXT
modm::glcd::Color::black(), // BACKGROUND
modm::glcd::Color::red(), // ACTIVATED
modm::glcd::Color::blue(), // DEACTIVATED

modm::color::Rgb565 colors[modm::gui::Color::PALETTE_SIZE] {
RgbHtml::Black(),
RgbHtml::White(),
RgbHtml::Gray(),
RgbHtml::Red(),
RgbHtml::Green(),
RgbHtml::Blue(),
RgbHtml::Blue(), // BORDER
RgbHtml::Red(), // TEXT
RgbHtml::Black(), // BACKGROUND
RgbHtml::Red(), // ACTIVATED
RgbHtml::Blue(), // DEACTIVATED
};
modm::gui::ColorPalette colorpalette{colors};
/*
Expand Down Expand Up @@ -444,7 +444,7 @@ main()
* manipulate the color palette
*/

colorpalette.setColor(modm::gui::Color::TEXT, modm::glcd::Color::yellow());
colorpalette.setColor(modm::gui::Color::TEXT, RgbHtml::Yellow());


/*
Expand Down
2 changes: 1 addition & 1 deletion examples/stm32f469_discovery/touchscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LineDrawer : public modm::pt::Protothread
touch(touchData),
display{Board::getDisplay()},
px{-1, -1}, py{-1, -1},
c{Color::white(), Color::white()}
c{modm::color::RgbHtml::White(), modm::color::RgbHtml::White()}
{}

bool
Expand Down
30 changes: 15 additions & 15 deletions examples/stm32f4_discovery/open407v-d/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ initTouchscreen()
static void
drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.setColor(modm::color::RgbHtml::Red());
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
display.drawLine(center.x + 2, center.y, center.x + 15, center.y);
display.drawLine(center.x, center.y - 15, center.x, center.y - 2);
display.drawLine(center.x, center.y + 2, center.x, center.y + 15);

display.setColor(modm::glcd::Color::white());
display.setColor(modm::color::RgbHtml::White());
display.drawLine(center.x - 15, center.y + 15, center.x - 7, center.y + 15);
display.drawLine(center.x - 15, center.y + 7, center.x - 15, center.y + 15);

Expand All @@ -206,7 +206,7 @@ calibrateTouchscreen(modm::GraphicDisplay& display, modm::glcd::Point *fixed_sam
{
display.clear();

display.setColor(modm::glcd::Color::yellow());
display.setColor(modm::color::RgbHtml::Yellow());
display.setCursor(50, 5);
display << "Touch crosshair to calibrate";

Expand Down Expand Up @@ -394,17 +394,17 @@ test_callback(const modm::gui::InputEvent& ev, modm::gui::Widget* w, void* data)


//modm::gui::ColorPalette colorpalette[modm::gui::Color::PALETTE_SIZE] = {
// modm::glcd::Color::black(),
// modm::glcd::Color::white(),
// modm::glcd::Color::gray(),
// modm::glcd::Color::red(),
// modm::glcd::Color::green(),
// modm::glcd::Color::blue(),
// modm::glcd::Color::blue(), // BORDER
// modm::glcd::Color::red(), // TEXT
// modm::glcd::Color::black(), // BACKGROUND
// modm::glcd::Color::red(), // ACTIVATED
// modm::glcd::Color::blue(), // DEACTIVATED
// modm::color::RgbHtml::Black(),
// modm::color::RgbHtml::White(),
// modm::color::RgbHtml::Gray(),
// modm::color::RgbHtml::Red(),
// modm::color::RgbHtml::Green(),
// modm::color::RgbHtml::Blue(),
// modm::color::RgbHtml::Blue(), // BORDER
// modm::color::RgbHtml::Red(), // TEXT
// modm::color::RgbHtml::Black(), // BACKGROUND
// modm::color::RgbHtml::Red(), // ACTIVATED
// modm::color::RgbHtml::Blue(), // DEACTIVATED
//
//};

Expand Down Expand Up @@ -437,7 +437,7 @@ main()
* manipulate the color palette
*/

// colorpalette[modm::gui::Color::TEXT] = modm::glcd::Color::yellow();
// colorpalette[modm::gui::Color::TEXT] = modm::color::RgbHtml::Yellow();


/*
Expand Down
8 changes: 4 additions & 4 deletions examples/stm32f4_discovery/open407v-d/touchscreen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ initTouchscreen()
static void
drawCross(modm::GraphicDisplay& display, modm::glcd::Point center)
{
display.setColor(modm::glcd::Color::red());
display.setColor(modm::color::RgbHtml::Red());
display.drawLine(center.x - 15, center.y, center.x - 2, center.y);
display.drawLine(center.x + 2, center.y, center.x + 15, center.y);
display.drawLine(center.x, center.y - 15, center.x, center.y - 2);
display.drawLine(center.x, center.y + 2, center.x, center.y + 15);

display.setColor(modm::glcd::Color::white());
display.setColor(modm::color::RgbHtml::White());
display.drawLine(center.x - 15, center.y + 15, center.x - 7, center.y + 15);
display.drawLine(center.x - 15, center.y + 7, center.x - 15, center.y + 15);

Expand All @@ -162,7 +162,7 @@ calibrateTouchscreen(modm::GraphicDisplay& display)
{
display.clear();

display.setColor(modm::glcd::Color::yellow());
display.setColor(modm::color::RgbHtml::Yellow());
display.setCursor(50, 5);
display << "Touch crosshair to calibrate";

Expand Down Expand Up @@ -205,7 +205,7 @@ main()

calibrateTouchscreen(tft);

tft.setColor(modm::glcd::Color::lime());
tft.setColor(modm::color::Rgb565::lime());

while (true)
{
Expand Down
2 changes: 2 additions & 0 deletions src/modm/ui/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
#include "color/rgb.hpp"
#include "color/hsv.hpp"
#include "color/brightness.hpp"

#include "color/rgb565.hpp"
#include "color/rgbhtml.hpp"
26 changes: 15 additions & 11 deletions src/modm/ui/color/brightness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,51 @@ class Rgb565;
template<typename T = uint8_t>
class BrightnessT
{
public:
T value{0};

public:
constexpr BrightnessT() = default;

constexpr BrightnessT(T scale) : value(scale) {}
constexpr BrightnessT(T value) : value(value)
{}

/**
* Convertion Constructor for RGB Color
*
* \param rgb RGB Color
*/
template<typename _T>
constexpr BrightnessT(RgbT<_T> rgb) : value((0.2125 * red) + (0.7154 * green) + (0.0721 * blue))
constexpr BrightnessT(RgbT<_T> rgb)
: value((0.2125 * float(rgb.red)) + (0.7154 * float(rgb.green)) + (0.0721 * float(rgb.blue)))
{}

/**
* Convertion Constructor for HSV Color
*
* \param hsv HSV Color
*/
// OPTIMIZE think, i can cutoff the floats precision
template<typename _T>
constexpr BrightnessT(HsvT<_T> hsv) : Brightness(RgbT<T>(hsv))
constexpr BrightnessT(HsvT<_T> hsv) : value(hsv.value)
{}

/**
* Convertion Constructor for RGB565 Color
*
* \param rgb565 RGB565 Color
*/
constexpr BrightnessT(RGb565 rgb565)
: BrightnessT(RgbT<uint8_t>(rgb565) {}
constexpr BrightnessT(Rgb565 rgb565) : BrightnessT(RgbT<uint8_t>(rgb565))
{}

/**
* Convertion function to plain value
*/
inline operator T() const {
return value;
};
}
// inline operator T() const {
// return value;
// }

constexpr bool operator==(const BrightnessT<T> &other) const = default;
};

/// @ingroup modm_ui_color
using Brightness = BrightnessT<>;

Expand Down
6 changes: 1 addition & 5 deletions src/modm/ui/color/hsv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ class HsvT
*/
constexpr HsvT(const Rgb565& rgb565) : HsvT(RgbT<uint8_t>(rgb565)) {}

constexpr bool
operator==(const HsvT<T>& other) const
{
return (hue == other.hue and saturation == other.saturation and value == other.value);
}
constexpr bool operator==(const HsvT<T> &other) const = default;

private:
template<typename _T>
Expand Down
Loading

0 comments on commit 779c042

Please sign in to comment.