Files
ESP8266lib/ext/lcd/ui/UI.h
kazu 5cb02880b3 many updates..
new sensors.. display.. led.. drawing.. stuff..
2019-01-17 23:12:01 +01:00

102 lines
12 KiB
C++

#ifndef UI_H
#define UI_H
#include <cstdint>
#include "../Draw.h"
#include "../../../Debug.h"
class Setter;
extern Setter setter;
//uint8_t f1_data[] = {84,18,71,192,137,130,0,0,32,135,28,7,250,156,207,113,0,0,112,124,156,199,121,190,207,137,130,162,32,40,114,30,231,113,190,40,10,138,162,239,226,8,16,64,0,64,0,7,4,65,65,0,0,0,0,0,0,0,0,0,0,0,172,1,84,146,170,32,74,164,2,0,160,200,162,8,11,34,40,138,0,0,136,130,162,40,138,130,32,138,130,162,32,40,138,162,40,138,136,40,10,138,34,40,130,20,32,64,0,64,128,0,4,0,65,0,0,0,0,0,32,0,0,0,0,0,34,74,84,191,162,36,40,200,33,0,160,168,32,136,10,2,40,138,10,129,128,178,162,40,136,130,32,136,130,146,96,44,138,162,40,10,136,40,74,138,34,40,130,34,0,206,227,120,142,224,61,65,81,55,143,243,120,153,243,68,81,80,20,125,34,74,4,146,66,34,32,168,34,0,144,140,16,72,122,2,36,138,128,60,65,170,162,40,136,130,32,136,130,138,160,106,138,162,40,10,136,40,74,82,20,36,132,0,0,81,20,69,209,19,69,65,73,73,81,20,69,69,36,68,81,80,20,65,34,74,4,18,7,193,33,136,248,240,144,138,8,38,130,30,194,241,64,0,34,170,162,39,136,142,35,251,130,134,32,169,138,158,232,113,136,40,74,34,8,34,132,0,0,80,20,68,145,16,69,65,69,73,81,20,69,67,32,68,81,146,18,33,33,76,4,18,138,36,34,8,32,0,144,137,4,232,131,34,33,130,128,60,33,170,190,40,136,130,32,138,130,138,32,40,139,130,168,128,136,40,74,82,8,33,132,0,0,94,20,68,159,16,69,65,67,73,81,20,69,129,35,68,81,18,17,17,34,74,4,63,74,42,34,8,32,0,136,136,2,8,130,162,32,130,0,129,32,114,162,40,136,130,32,138,130,146,32,40,138,130,42,129,136,40,74,138,136,32,136,0,0,81,20,68,129,16,69,65,69,73,81,20,69,1,36,68,81,146,18,9,34,74,0,146,10,42,66,4,0,0,136,136,130,8,138,162,32,138,0,0,0,2,162,40,138,130,32,138,138,162,32,40,138,130,36,138,136,72,73,138,136,32,136,0,0,81,20,69,145,224,69,65,73,65,81,20,69,65,36,68,74,82,228,5,34,74,4,18,7,196,131,2,0,2,10,135,62,7,114,156,192,113,10,0,32,124,162,199,121,190,192,139,114,162,47,40,114,2,43,114,8,135,176,137,136,239,232,0,0,222,227,120,142,0,69,65,81,65,145,243,120,129,195,57,132,77,4,125,172,73,};
//uint16_t f1_offsets[] = {0,1,3,7,14,20,28,34,36,40,44,50,56,59,64,66,70,76,80,86,92,98,104,110,116,122,128,130,133,137,142,146,152,160,166,172,178,184,190,196,202,208,210,216,222,228,236,242,248,254,260,266,272,278,284,290,298,304,310,316,320,324,328,334,340,343,349,355,361,367,373,379,385,391,393,399,405,407,415,421,427,433,439,445,451,457,463,469,477,483,489,495,500,502,507,};
//FontWrap fnt_f1(512,9,f1_data,f1_offsets);
//uint8_t f1_data[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,128,0,128,20,0,0,0,0,0,0,0,0,0,0,0,0,0,240,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,53,0,2,229,155,6,162,138,0,128,156,227,251,162,239,251,190,15,8,226,11,250,158,239,249,190,47,250,184,40,136,162,239,249,158,239,139,162,40,138,190,4,34,0,124,207,247,124,223,23,125,92,20,124,223,247,125,223,247,69,81,21,69,159,36,0,130,175,88,18,34,135,0,64,34,2,130,162,32,128,162,168,228,4,234,138,162,32,10,130,32,34,160,36,216,166,40,138,162,128,136,162,72,137,144,8,82,0,64,81,16,69,65,16,17,80,18,84,81,20,69,65,64,68,81,165,68,136,36,0,2,229,35,62,162,239,227,32,34,226,227,190,239,131,190,15,2,136,171,250,190,32,58,142,238,35,160,35,168,170,232,171,190,143,136,162,138,248,136,16,138,0,124,95,16,125,71,247,17,208,17,84,81,244,85,193,71,68,81,69,124,196,100,0,128,143,210,18,34,135,0,16,34,34,128,32,40,130,34,8,228,4,232,139,162,32,10,130,40,34,160,36,136,178,40,72,18,136,136,148,77,33,132,32,2,0,68,81,16,5,65,20,17,80,18,84,81,20,36,1,68,68,74,165,64,130,36,0,2,229,203,62,162,138,8,10,156,239,251,160,231,131,190,175,8,130,8,136,158,239,249,130,47,250,158,232,139,162,47,184,162,143,248,136,40,34,190,64,2,0,124,207,247,124,193,23,125,79,244,85,209,23,92,193,71,124,196,23,125,159,36,0,0,128,0,0,20,0,8,0,0,0,0,0,0,0,0,128,0,0,240,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,3,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,49,0,};
//uint16_t f1_offsets[] = {0,1,3,7,13,19,25,31,33,36,39,45,51,53,57,59,65,71,77,83,89,95,101,107,113,119,125,127,129,133,137,141,147,155,161,167,173,179,185,191,197,203,209,215,221,227,233,239,245,251,257,263,269,275,281,287,293,299,305,311,314,320,323,329,335,338,344,350,356,362,368,374,380,386,392,398,404,410,416,422,428,434,440,446,452,458,464,470,476,482,488,494,498,500,};
//FontWrap fnt_f1(512,9,f1_data,f1_offsets);
//static uint8_t f1_data[] = {40,0,4,0,0,130,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,10,158,16,132,130,42,0,0,64,140,56,142,228,49,15,195,0,16,32,48,0,140,195,57,239,113,210,129,36,33,52,113,56,140,195,249,164,72,80,36,242,137,0,2,4,4,0,1,12,16,36,4,1,0,0,0,0,16,0,0,0,0,48,26,0,2,10,69,9,138,130,8,0,0,32,210,64,144,36,8,136,36,1,8,64,72,0,146,36,72,33,8,146,128,36,97,54,137,72,146,36,32,164,72,144,34,2,9,1,2,12,4,0,1,2,16,0,36,1,0,0,0,0,16,0,0,0,0,16,18,0,130,63,133,4,132,130,0,2,0,16,146,64,144,36,8,136,36,1,196,135,64,60,146,36,72,33,8,146,128,20,161,85,137,72,146,36,32,164,72,146,66,129,8,2,2,192,28,199,25,135,113,36,20,253,112,204,193,53,183,148,130,34,233,17,18,0,2,10,14,194,10,130,0,2,30,8,146,48,12,231,56,4,195,73,2,0,33,66,158,35,72,231,105,158,128,12,33,84,137,56,146,195,32,36,133,10,65,65,8,4,2,0,165,32,37,66,146,36,12,37,145,82,34,141,144,148,146,20,9,9,34,0,130,63,20,9,17,130,128,15,0,4,146,8,16,4,73,132,4,1,196,135,16,89,146,36,72,33,72,146,144,20,33,84,137,8,146,4,33,36,133,138,130,32,8,8,2,192,165,32,29,66,146,36,20,37,145,82,34,5,147,148,146,8,201,16,18,0,2,10,148,20,17,130,0,66,0,2,146,8,16,4,73,132,4,65,8,64,0,85,146,36,72,33,72,146,144,36,33,148,137,8,146,4,33,36,133,138,130,16,8,16,2,32,165,32,5,66,146,36,36,37,145,82,34,5,148,164,146,20,41,16,18,0,2,10,79,136,14,130,0,66,64,1,140,120,14,228,48,4,195,72,16,32,16,57,146,195,57,47,48,210,97,36,47,148,113,8,140,228,32,24,130,77,132,240,9,32,226,193,29,199,25,130,147,36,36,37,145,204,193,133,35,71,108,34,238,49,26,0,0,0,4,0,0,130,0,32,0,0,0,0,0,0,0,0,0,32,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,8,0,2,0,0,0,0,0,2,32,0,0,0,64,0,1,0,0,0,0,8,0,0,0,2,0,0,0,0,68,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,2,0,0,0,0,128,1,16,0,0,0,64,0,1,0,0,0,0,6,0,0,0,};
//static uint16_t f1_offsets[] = {0,1,3,7,15,22,30,38,41,45,49,55,61,65,70,72,80,86,90,96,102,108,114,120,126,132,138,141,144,150,156,162,168,176,182,188,194,200,205,210,216,222,227,233,239,245,252,259,266,272,278,284,290,297,303,310,318,325,332,339,343,351,355,356,362,365,370,375,380,386,391,397,403,409,412,417,423,426,435,441,446,452,458,463,468,471,476,481,489,495,501,507,512,515,};
//static FontWrap fnt_f1(528,10,f1_data,f1_offsets);
//static uint8_t f1_data[] = {42,202,49,130,17,133,0,0,228,144,227,32,158,243,57,14,0,0,224,224,3,225,195,121,124,31,71,40,20,10,130,66,28,15,199,199,243,133,130,33,36,20,228,91,140,0,4,8,0,8,32,32,40,33,0,0,0,0,0,2,0,0,0,0,128,10,42,170,74,65,146,200,1,0,20,89,20,49,66,132,68,17,0,0,16,25,132,34,38,138,4,129,72,40,20,9,198,70,34,145,72,40,68,132,130,81,68,34,2,73,72,1,8,8,0,8,16,32,0,33,0,0,0,0,0,2,0,0,0,0,64,18,170,175,72,65,82,144,16,0,18,21,4,41,65,128,68,81,65,64,0,201,138,34,22,8,5,65,80,40,148,8,198,74,65,81,80,40,64,132,68,82,66,34,130,136,72,1,192,105,28,203,57,171,41,169,158,199,105,172,114,39,138,34,138,162,79,18,2,197,177,128,65,80,17,0,18,17,228,40,207,67,56,17,56,159,131,164,139,226,23,8,125,79,192,47,212,8,170,74,65,81,208,199,64,132,68,82,130,65,129,136,40,2,32,154,162,44,146,108,42,165,165,40,154,178,137,34,138,82,82,34,68,18,2,133,130,70,65,16,124,0,18,17,2,37,80,68,68,30,4,0,68,148,201,38,22,8,5,65,92,40,180,8,170,82,65,79,80,2,67,132,40,138,130,129,64,136,8,0,192,139,130,232,147,40,42,163,164,40,138,162,48,34,82,84,33,20,34,34,130,143,66,41,70,16,16,28,18,17,1,125,80,36,68,16,56,159,67,148,201,39,22,8,5,65,80,168,20,9,170,82,65,65,86,4,68,132,40,138,66,130,64,136,8,0,32,138,130,40,144,40,42,165,164,40,138,162,64,34,82,84,33,20,66,18,128,162,66,41,66,16,16,0,17,145,16,33,81,36,68,17,64,64,0,148,37,40,38,138,4,129,72,168,20,9,146,98,34,129,72,36,68,132,16,4,65,130,32,8,9,0,32,155,162,44,146,44,42,165,164,40,154,178,136,34,35,136,80,8,65,18,130,194,33,198,69,16,0,65,225,208,231,32,142,35,56,78,1,0,64,228,35,232,195,121,124,1,71,40,19,250,146,66,28,1,87,200,67,120,16,4,33,132,240,11,9,0,192,106,28,203,17,43,42,169,164,200,105,172,112,198,34,136,136,136,79,18,0,128,0,0,128,8,0,1,0,0,0,0,0,0,0,0,1,0,0,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,0,0,0,0,0,0,8,32,0,0,0,8,32,0,0,0,0,0,8,64,18,0,0,0,0,0,5,0,1,0,0,0,0,0,0,0,0,1,0,0,240,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,12,248,1,0,0,0,128,7,16,0,0,0,8,32,0,0,0,0,0,4,128,10,};
//static uint16_t f1_offsets[] = {0,1,3,7,13,19,29,36,38,42,46,50,56,58,62,64,68,74,78,84,90,96,102,108,114,120,126,128,130,136,142,148,154,165,173,180,187,194,200,206,214,221,223,228,235,241,249,256,264,270,278,285,292,298,305,313,325,332,340,347,350,354,357,363,370,373,379,385,391,397,403,407,413,419,421,424,429,431,439,445,451,457,463,467,473,477,483,489,499,505,511,517,521,523,};
//static FontWrap fnt_f1(528,10,f1_data,f1_offsets);
static uint8_t f1_data[] = {0,0,5,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,137,159,16,35,155,10,0,0,144,179,231,65,62,231,115,28,0,1,193,241,113,30,231,249,62,39,58,40,10,66,145,243,56,30,231,139,162,160,40,250,46,224,4,16,32,0,32,128,1,65,10,1,0,0,0,0,64,0,0,0,0,0,204,102,0,170,95,69,137,164,32,7,0,0,72,36,8,98,130,0,138,34,128,0,34,10,138,162,40,10,130,40,18,40,9,102,81,20,69,162,136,136,162,160,40,130,66,128,10,32,32,0,32,64,0,1,8,1,0,0,0,0,64,0,0,0,0,0,34,137,0,2,73,133,132,164,160,138,0,0,68,38,8,82,130,0,137,162,77,0,4,234,138,162,32,10,130,32,18,168,8,90,83,20,69,162,128,136,162,36,37,66,130,128,0,0,231,113,60,231,120,79,74,253,60,206,227,53,239,69,81,82,20,125,34,136,0,2,137,15,130,131,32,130,0,0,66,37,199,73,158,7,113,188,45,124,8,169,250,158,32,122,158,238,19,104,8,66,85,20,69,34,135,136,162,36,66,33,2,129,0,0,40,138,162,72,68,81,42,37,69,81,20,141,64,68,81,146,18,33,33,8,1,130,31,21,73,138,32,224,195,3,193,164,0,250,160,136,136,32,64,0,132,232,139,162,32,10,130,40,18,168,8,66,89,244,68,30,136,136,20,21,133,16,2,130,0,0,47,10,162,79,68,81,26,37,69,81,20,5,71,68,74,18,17,17,66,132,0,0,9,149,84,132,32,128,24,152,64,164,0,66,160,136,136,160,141,124,2,8,136,162,40,10,130,40,146,40,9,66,81,20,100,146,136,136,20,149,136,8,2,132,0,128,40,138,162,64,68,81,42,37,69,81,20,5,72,68,74,146,18,9,130,130,0,2,192,79,136,11,27,128,24,88,128,163,239,65,30,71,112,156,13,1,129,240,137,30,231,249,2,39,58,39,250,66,145,19,120,34,135,112,8,138,136,248,14,232,224,7,239,113,60,79,120,81,74,37,69,206,227,133,135,57,132,77,228,125,12,97,0,0,0,5,0,0,0,0,16,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,2,0,0,64,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0,1,0,0,64,0,1,0,0,0,0,224,0,0,0,0,};
static uint16_t f1_offsets[] = {0,1,3,7,14,22,30,37,39,43,47,53,59,62,67,70,78,84,87,93,99,105,111,117,123,129,135,138,141,146,152,157,163,171,177,183,189,195,201,207,213,219,223,229,235,241,248,254,260,266,273,279,285,291,297,303,311,317,323,329,333,341,345,349,356,359,365,371,377,383,389,394,400,406,408,411,416,418,426,432,438,444,450,455,461,466,472,478,486,492,498,504,509,517,};
static FontWrap fnt_f1(528,10,f1_data,f1_offsets);
#include "UIElement.h"
#include "UIStructs.h"
#include "UIPainter.h"
#undef min
#undef max
#include <vector>
class UI {
UIPainter p;
UIElement root;
UIElement* eFocused = nullptr;
UIElement* eDown = nullptr;
Color cBackground = Color::fromRGB(180,240,180);
public:
UI() {
root.setRect(0,0,240,320);
root.setVisible(true);
p.setFG(cBackground);
p.fillRect(root.getRect());
}
void add(UIElement* e) {
root.addChild(e);
}
void onTouch(const uint16_t x, const uint16_t y) {
if (eDown) {
const uint16_t x1 = x - eDown->getRect().x; // (x,y) relative to elements top-left
const uint16_t y1 = y - eDown->getRect().y;
eDown->onTouch(x1, y1);
} else {
ESP_LOGI("UI", "root_onTouch(%d, %d)", x,y );
eDown = root._onTouch(x,y);
}
}
void onTouchDone() {
if (eDown) {
eDown->onTouchUp();
eDown = nullptr;
}
}
void draw() {
//debugMod1("UI", "draw %zu elements", elements.size());
// for (UIElement* e : elements) {
// e->_draw(p);
// }
root._draw(p);
}
};
#endif // UI_H