From 6791244f22fc0e22b4f56454e200daa706720868 Mon Sep 17 00:00:00 2001 From: stubbfelnewpc Date: Fri, 1 May 2020 21:22:26 +0200 Subject: [PATCH] init --- .gitignore | 89 ++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 63 ++++++++++++++++++++++++++++ StackPanel.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++ StackPanel.hpp | 32 +++++++++++++++ StackPanel_t.hpp | 41 +++++++++++++++++++ myink.ino | 66 ++++++++++++++++++++++++++++++ 6 files changed, 386 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 StackPanel.cpp create mode 100644 StackPanel.hpp create mode 100644 StackPanel_t.hpp create mode 100644 myink.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3937108 --- /dev/null +++ b/.gitignore @@ -0,0 +1,89 @@ + +# Created by https://www.gitignore.io/api/c,c++,visualstudiocode +# Edit at https://www.gitignore.io/?templates=c,c++,visualstudiocode + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/c,c++,visualstudiocode diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4a6b32b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,63 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "numeric": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "cstddef": "cpp", + "bit": "cpp", + "map": "cpp", + "set": "cpp", + "algorithm": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "optional": "cpp", + "random": "cpp", + "string": "cpp", + "string_view": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/StackPanel.cpp b/StackPanel.cpp new file mode 100644 index 0000000..4884b70 --- /dev/null +++ b/StackPanel.cpp @@ -0,0 +1,95 @@ +#include "StackPanel.hpp" +#include +#include + +//using namespace myink::ui; + +void draw_background(const PositionalProperties & positionals, const Color & background_color); +void draw_border(const PositionalProperties positionals, const Color & color, const LineWidth & border_line_width); +PositionalProperties move_down(const PositionalProperties & i, const PositionalProperties & p); +PositionalProperties move_right(const PositionalProperties & i, const PositionalProperties & p); + +StackPanel::StackPanel(const PositionalProperties & p, const StackPanelStyleProperties & s, const DrawItemCallBackList & i, const MoveToNextItem & m) : positionals(p), style(s), itmes(i), move(m) +{ +} + +StackPanel::~StackPanel() +{ +} + +void StackPanel::draw() const +{ + auto border_line_width = style.border_line_width; + auto margin = style.margin; + auto padding = style.padding; + auto inner_gap = border_line_width + padding; + auto gap = inner_gap + margin; + if (itmes.size == 0) { + PositionalProperties outer = { + positionals.left, + positionals.top, + positionals.width + 2 * (gap), + positionals.height + 2 * (gap) + }; + draw_background(outer, style.background_color); + return; + } + + PositionalProperties inner = { + positionals.left + gap, + positionals.top + gap, + 0, + 0 + }; + + for(auto i = 0; i < itmes.size; i++) { + auto callback = itmes.callbacks[i]; + auto last = callback(inner); + inner = move(inner, last); + } + + if (border_line_width < 1) + { + return; + } + + PositionalProperties border_positionals = { + positionals.left + padding, + positionals.top + padding, + inner.width + (2 * margin) + border_line_width, + inner.height + (2 * margin) + border_line_width + }; + + draw_border(border_positionals, style.border_line_color, border_line_width); +} + +PositionalProperties StackPanel::move_down(const PositionalProperties & i, const PositionalProperties & p) +{ + return { + i.left, + i.top + p.height, + p.width > i.width ? p.width : i.width, + i.height + p.height + }; +} + +PositionalProperties StackPanel::move_right(const PositionalProperties & i, const PositionalProperties & p) +{ + return { + i.left + p.width, + i.top, + i.width + p.width, + p.height > i.height ? p.height : i.height + }; +} + +void draw_background(const PositionalProperties & positionals, const Color & background_color) +{ + Paint_ClearWindows(positionals.left, positionals.top, positionals.left + positionals.width, positionals.top + positionals.height, background_color); +} + +void draw_border(const PositionalProperties p, const Color & color, const LineWidth & border_line_width) +{ + auto border_line_width_pixel = border_line_width > 8 ? DOT_PIXEL::DOT_PIXEL_8X8 : DOT_PIXEL(border_line_width); + Paint_DrawRectangle(p.left, p.top, p.left + p.width, p.top + p.height, color, border_line_width_pixel, DRAW_FILL_EMPTY); +} diff --git a/StackPanel.hpp b/StackPanel.hpp new file mode 100644 index 0000000..f802d59 --- /dev/null +++ b/StackPanel.hpp @@ -0,0 +1,32 @@ +#ifndef STACK_PANEL_H +#define STACK_PANEL_H + +#include "StackPanel_t.hpp" + +//namespace myink { namespace ui { + +class StackPanel +{ + +private: + const PositionalProperties & positionals; + const StackPanelStyleProperties & style; + const DrawItemCallBackList & itmes; + const MoveToNextItem & move; + +public: + StackPanel(const PositionalProperties & positionals, const StackPanelStyleProperties & style, const DrawItemCallBackList & itmes, const MoveToNextItem & move); + ~StackPanel(); + + void draw() const; + static PositionalProperties move_down(const PositionalProperties & i, const PositionalProperties & p); + static PositionalProperties move_right(const PositionalProperties & i, const PositionalProperties & p); +}; + + + + +//}} + + +#endif \ No newline at end of file diff --git a/StackPanel_t.hpp b/StackPanel_t.hpp new file mode 100644 index 0000000..4d28f75 --- /dev/null +++ b/StackPanel_t.hpp @@ -0,0 +1,41 @@ +#ifndef STACK_PANEL_T_H +#define STACK_PANEL_T_H + +#include + +//namespace myink { namespace ui { + class StackPanel; + typedef StackPanel * StackPanelPtr; + typedef struct PositionalProperties_t + { + size_t left; + size_t top; + size_t width; + size_t height; + } PositionalProperties, *PositionalPropertiesPtr; + + typedef size_t Color; + typedef size_t LineWidth; + typedef size_t Margin; + typedef size_t Padding; + typedef PositionalProperties(*DrawItemCallBack)(const PositionalProperties &); + typedef struct DrawItemCallBackList_t + { + size_t size; + DrawItemCallBack * callbacks; + } DrawItemCallBackList, *DrawItemCallBackListPtr; + + typedef PositionalProperties (*MoveToNextItem)(const PositionalProperties &, const PositionalProperties & ); + + typedef struct StackPanelStyleProperties_t + { + Color background_color; + LineWidth border_line_width; + Color border_line_color; + Margin margin; + Padding padding; + } StackPanelStyleProperties, *StackPanelStylePropertiesPtr; + +//}} + +#endif \ No newline at end of file diff --git a/myink.ino b/myink.ino new file mode 100644 index 0000000..2f63b26 --- /dev/null +++ b/myink.ino @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include + +#include "StackPanel.hpp" + + PAINT_TIME show_time = {2020, 04, 27, 22, 42, 5}; + UBYTE *BlackImage; + sFONT * font = &Font8; + +void setup() { + // put your setup code here, to run once: + DEV_Module_Init(); + EPD_7IN5_V2_Init(); + + /* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */ + UWORD Imagesize = ((EPD_7IN5_V2_WIDTH % 8 == 0) ? (EPD_7IN5_V2_WIDTH / 8 ) : (EPD_7IN5_V2_WIDTH / 8 + 1)) * EPD_7IN5_V2_HEIGHT; + if ((BlackImage = (UBYTE *)malloc(Imagesize / 2)) == NULL) { + printf("Failed to apply for black memory...\r\n"); + while (1); + } + + Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH , EPD_7IN5_V2_HEIGHT / 2, 90, WHITE); + Paint_SelectImage(BlackImage); + Paint_Clear(WHITE); +} + +void loop() { + // put your main code here, to run repeatedly: + DEV_Delay_ms(2000); + + show_time.Sec = show_time.Sec + 1; + Paint_DrawTime(100, 10, &show_time, &Font24, WHITE, BLACK); + DrawItemCallBack itmes[] = { + [](const PositionalProperties & p) -> PositionalProperties { + Paint_DrawString_EN(p.left, p.top, "Hallo Miri :)", font, WHITE, BLACK); + return { p.left, p.top, 13 * font->Width, font->Height}; + }, + [](const PositionalProperties & p) -> PositionalProperties { + Paint_DrawString_EN(p.left, p.top, "Hallo Felix", font, WHITE, BLACK); + return { p.left, p.top, 13 * font->Width, font->Height}; + } + }; + StackPanel( + {50, 200 ,200, 50}, + {WHITE, 1, BLACK, 2, 4}, + {2, itmes}, + StackPanel::move_right + ).draw(); + + EPD_7IN5_V2_SendHalfImage(0, BlackImage); + font = &Font24; + + StackPanel( + {0, 400 ,200, 50}, + {WHITE, 2, BLACK, 4, 8}, + {2, itmes}, + StackPanel::move_down + ).draw(); + + EPD_7IN5_V2_SendHalfImage(1, BlackImage); + EPD_7IN5_V2_TurnOnDisplay(); + EPD_7IN5_V2_Sleep(); +}