#include "display_buttons.h" void c_onScreenButton::begin(uint16_t xpos, uint16_t ypos, uint16_t width, uint16_t height, uint16_t radius) { log_d("element: %s", _name.c_str()); _xpos = xpos; _width = width; _ypos = ypos; _radius = radius; _height = height; if (_location == LocBottom) { _yTpos = getDisplay()->getDisplayHeight() - (CONTROLSLINE_H / 2) + (getDisplay()->getMaxCharHeight() / 2); _xTpos = _xpos + (_width / 2) - (getStringWidth(_name, FONT8) / 2); log_d(":Calc_pos (pos=bottom, x=%d, y=%d, w=%d, h=%d, xT=%d, yT=%d)", _xpos, _ypos, _width, _height, _xTpos, _yTpos); } if (_location == LocRight) { _yTpos = _ypos + (INDICATORHEIGHT / 2) - 2 + (getDisplay()->getMaxCharHeight() / 2); // + getDisplay()->getDisplayHeight() - 2; _xTpos = _xpos + (_width / 2) - (getStringWidth(_name, FONT8) / 2); log_d(":Calc_pos (pos=right, x=%d, y=%d, w=%d, h=%d, xT=%d, yT=%d)", _xpos, _ypos, _width, _height, _xTpos, _yTpos); } if (_physButton.isValid()) { log_d("init pyhsButton(%d)", _index); _physButton.begin(); } log_d(":OK | "); } void c_onScreenButton::drawButton() { getDisplay()->setFont(FONT8); // log_d("drawbutton:%s(x=%u, y=%u, w=%u, h=%u)\n", _name.c_str(), _xpos, _ypos, _width, _height); if (!_visible) { // hide button return; } getDisplay()->setDrawColor(0); getDisplay()->drawBox(_xpos, _ypos, _width, _height); getDisplay()->setDrawColor(1); uint16_t yTpos_pressed = !getState() ? _yTpos : (_yTpos + 1); //check if we need to display something else String label = (_useAltName ? _altName : _name); if (getDisplayState()) { getDisplay()->drawRBox(_xpos, _ypos, _width, _height, _radius); getDisplay()->setDrawColor(0); getDisplay()->drawStr(_xTpos, yTpos_pressed, label.c_str()); } else { getDisplay()->setDrawColor(1); getDisplay()->drawRFrame(_xpos, _ypos, _width, _height, _radius); getDisplay()->drawStr(_xTpos, yTpos_pressed, label.c_str()); } getDisplay()->setDrawColor(1); } void c_onScreenButton::handle() { if (_physButton.isValid()) { _physButton.read(); _pressed = _physButton.pressedFor(100); if (_pressed) { if(_actionFn != NULL && (actionHandled == false)) { _actionFn(); actionHandled = true; } } else if (_physButton.releasedFor(500)) { actionHandled = false; } _state = _pressed; } else if (_stateFn != NULL) { _state = _stateFn(); _displayState = _state; } log_d("item(%s)=%d",_name.c_str(), _state); }