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 e3814e9
Show file tree
Hide file tree
Showing 21 changed files with 304 additions and 137 deletions.
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
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"
27 changes: 14 additions & 13 deletions src/modm/ui/color/brightness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,43 @@ class BrightnessT
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))
{}
// template<typename _T>
// constexpr BrightnessT(RgbT<_T> rgb) : value((0.2125 * red) + (0.7154 * green) + (0.0721 * 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))
{}
// template<typename _T>
// constexpr BrightnessT(HsvT<_T> hsv) : Brightness(RgbT<T>(hsv))
// {}

/**
* 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;
// }
};

/// @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
8 changes: 1 addition & 7 deletions src/modm/ui/color/rgb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "brightness.hpp"
#include "rgb565.hpp"

using namespace modm::platform;

namespace modm
{
namespace color
Expand Down Expand Up @@ -148,11 +146,7 @@ class RgbT
blue *= scalar;
}

constexpr bool
operator==(const RgbT<T>& other) const
{
return (red == other.red and green == other.green and blue == other.blue);
}
constexpr bool operator==(const RgbT<T> &other) const = default;

private:
template<typename _T>
Expand Down
14 changes: 5 additions & 9 deletions src/modm/ui/color/rgb565.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,11 @@ class Rgb565
/**
* Convertion function to plain color
*/
inline operator uint16_t() const {
return color;
};

inline bool
operator==(const Rgb565 &other) const
{
return (color == other.color);
}
// inline operator uint16_t() const {
// return color;
// };

constexpr bool operator==(const Rgb565 &other) const = default;
};
} // namespace color

Expand Down
Loading

0 comments on commit e3814e9

Please sign in to comment.