mirror of
https://github.com/geekammo/MicroView-Arduino-Library.git
synced 2026-02-26 06:21:23 +01:00
Changed widget base class variables from private to protected
Base variables are now accessed directly by child widgets instead of using methods
This commit is contained in:
@@ -1362,8 +1362,8 @@ int MicroView::readSerial(void)
|
||||
The MicroViewWidget class is the parent class for child widget like MicroViewSlider and MicroViewGauge.
|
||||
*/
|
||||
MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_t max) {
|
||||
x=newx;
|
||||
y=newy;
|
||||
posX=newx;
|
||||
posY=newy;
|
||||
value=min;
|
||||
valLen=getInt16PrintLen(value);
|
||||
minValue=min;
|
||||
@@ -1372,16 +1372,16 @@ MicroViewWidget::MicroViewWidget(uint8_t newx, uint8_t newy, int16_t min, int16_
|
||||
}
|
||||
|
||||
/** \brief Get widget x position. */
|
||||
uint8_t MicroViewWidget::getX() { return x; }
|
||||
uint8_t MicroViewWidget::getX() { return posX; }
|
||||
|
||||
/** \brief Get widget y position. */
|
||||
uint8_t MicroViewWidget::getY() { return y; }
|
||||
uint8_t MicroViewWidget::getY() { return posY; }
|
||||
|
||||
/** \brief Set widget x position. */
|
||||
void MicroViewWidget::setX(uint8_t newx) { x = newx; }
|
||||
void MicroViewWidget::setX(uint8_t newx) { posX = newx; }
|
||||
|
||||
/** \brief Set widget y position. */
|
||||
void MicroViewWidget::setY(uint8_t newy) { y = newy; }
|
||||
void MicroViewWidget::setY(uint8_t newy) { posY = newy; }
|
||||
|
||||
/** \brief Get minimum value.
|
||||
|
||||
@@ -1492,7 +1492,7 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_
|
||||
style=0;
|
||||
totalTicks=30;
|
||||
noValDraw=false;
|
||||
prevValue=getMinValue();
|
||||
prevValue=minValue;
|
||||
needFirstDraw=true;
|
||||
drawFace();
|
||||
draw();
|
||||
@@ -1525,7 +1525,7 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_
|
||||
break;
|
||||
}
|
||||
|
||||
prevValue=getMinValue();
|
||||
prevValue=minValue;
|
||||
needFirstDraw=true;
|
||||
drawFace();
|
||||
draw();
|
||||
@@ -1536,32 +1536,30 @@ MicroViewSlider::MicroViewSlider(uint8_t newx, uint8_t newy, int16_t min, int16_
|
||||
Draw image/diagram representing the widget's face.
|
||||
*/
|
||||
void MicroViewSlider::drawFace() {
|
||||
uint8_t offsetX, offsetY, endOffset;
|
||||
offsetX=getX();
|
||||
offsetY=getY();
|
||||
uint8_t endOffset;
|
||||
|
||||
//Horizontal styles, style 0 or 1
|
||||
if (style==0 || style==1) {
|
||||
endOffset = offsetX + totalTicks + 2;
|
||||
endOffset = posX + totalTicks + 2;
|
||||
// Draw minor ticks
|
||||
for (uint8_t i=offsetX+1; i<endOffset; i+=2) {
|
||||
uView.lineV(i, offsetY+5, 3);
|
||||
for (uint8_t i=posX+1; i<endOffset; i+=2) {
|
||||
uView.lineV(i, posY+5, 3);
|
||||
}
|
||||
// Draw extensions for major ticks
|
||||
for (uint8_t i=offsetX+1; i<endOffset; i+=10) {
|
||||
uView.lineV(i, offsetY+3, 2);
|
||||
for (uint8_t i=posX+1; i<endOffset; i+=10) {
|
||||
uView.lineV(i, posY+3, 2);
|
||||
}
|
||||
}
|
||||
//Vertical styles, style 2 or 3
|
||||
else {
|
||||
endOffset = offsetY + totalTicks + 2;
|
||||
endOffset = posY + totalTicks + 2;
|
||||
// Draw minor ticks
|
||||
for (uint8_t i=offsetY+1; i<=endOffset; i+=2) {
|
||||
uView.lineH(offsetX, i, 3);
|
||||
for (uint8_t i=posY+1; i<=endOffset; i+=2) {
|
||||
uView.lineH(posX, i, 3);
|
||||
}
|
||||
// Draw extensions for major ticks
|
||||
for (uint8_t i=offsetY+1; i<=endOffset; i+=10) {
|
||||
uView.lineH(offsetX+3, i, 2);
|
||||
for (uint8_t i=posY+1; i<=endOffset; i+=10) {
|
||||
uView.lineH(posX+3, i, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1578,28 +1576,25 @@ void MicroViewSlider::draw() {
|
||||
needFirstDraw=false;
|
||||
}
|
||||
else {
|
||||
prevValue=getValue();
|
||||
prevValue=value;
|
||||
// Draw current pointer
|
||||
drawPointer();
|
||||
}
|
||||
|
||||
// Draw numeric value if required
|
||||
if (!noValDraw) {
|
||||
uint8_t offsetX = getX();
|
||||
uint8_t offsetY = getY();
|
||||
|
||||
switch(style) {
|
||||
case 0:
|
||||
uView.setCursor(offsetX+totalTicks+4, offsetY+1);
|
||||
uView.setCursor(posX+totalTicks+4, posY+1);
|
||||
break;
|
||||
case 1:
|
||||
uView.setCursor(offsetX, offsetY+10);
|
||||
uView.setCursor(posX, posY+10);
|
||||
break;
|
||||
case 2:
|
||||
uView.setCursor(offsetX+1, offsetY+totalTicks+4);
|
||||
uView.setCursor(posX+1, posY+totalTicks+4);
|
||||
break;
|
||||
default:
|
||||
uView.setCursor(offsetX+9, offsetY);
|
||||
uView.setCursor(posX+9, posY);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1610,18 +1605,16 @@ void MicroViewSlider::draw() {
|
||||
// Use XOR mode to erase or draw the pointer for prevValue
|
||||
void MicroViewSlider::drawPointer() {
|
||||
uint8_t tickPosition;
|
||||
uint8_t offsetX = getX();
|
||||
uint8_t offsetY = getY();
|
||||
|
||||
if (style==0 || style==1) { // Horizontal
|
||||
tickPosition = ((float)(uint16_t)(prevValue-getMinValue())/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineH(offsetX+tickPosition,offsetY, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+1+tickPosition,offsetY+1, WHITE, XOR);
|
||||
tickPosition = ((float)(uint16_t)(prevValue-minValue)/(float)(uint16_t)(maxValue-minValue))*totalTicks;
|
||||
uView.lineH(posX+tickPosition, posY, 3, WHITE, XOR);
|
||||
uView.pixel(posX+1+tickPosition, posY+1, WHITE, XOR);
|
||||
}
|
||||
else { // Vertical
|
||||
tickPosition = ((float)(uint16_t)(getMaxValue()-prevValue)/(float)(uint16_t)(getMaxValue()-getMinValue()))*totalTicks;
|
||||
uView.lineV(offsetX+7, offsetY+tickPosition, 3, WHITE, XOR);
|
||||
uView.pixel(offsetX+6, offsetY+1+tickPosition, WHITE, XOR);
|
||||
tickPosition = ((float)(uint16_t)(maxValue-prevValue)/(float)(uint16_t)(maxValue-minValue))*totalTicks;
|
||||
uView.lineV(posX+7, posY+tickPosition, 3, WHITE, XOR);
|
||||
uView.pixel(posX+6, posY+1+tickPosition, WHITE, XOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1641,7 +1634,7 @@ MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t
|
||||
style=0;
|
||||
radius=15;
|
||||
noValDraw=false;
|
||||
prevValue=getMinValue();
|
||||
prevValue=minValue;
|
||||
needFirstDraw=true;
|
||||
drawFace();
|
||||
draw();
|
||||
@@ -1663,7 +1656,7 @@ MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t
|
||||
style=1;
|
||||
radius=23;
|
||||
}
|
||||
prevValue=getMinValue();
|
||||
prevValue=minValue;
|
||||
needFirstDraw=true;
|
||||
drawFace();
|
||||
draw();
|
||||
@@ -1674,12 +1667,9 @@ MicroViewGauge::MicroViewGauge(uint8_t newx, uint8_t newy, int16_t min, int16_t
|
||||
Draw image/diagram representing the widget's face.
|
||||
*/
|
||||
void MicroViewGauge::drawFace() {
|
||||
uint8_t offsetX, offsetY;
|
||||
float degreeSec, fromSecX, fromSecY, toSecX, toSecY;
|
||||
offsetX=getX();
|
||||
offsetY=getY();
|
||||
|
||||
uView.circle(offsetX,offsetY,radius);
|
||||
uView.circle(posX, posY, radius);
|
||||
|
||||
for (int i=150;i<=390;i+=30) { // Major tick from 150 degree to 390 degree
|
||||
degreeSec=i*(PI/180);
|
||||
@@ -1687,7 +1677,7 @@ void MicroViewGauge::drawFace() {
|
||||
fromSecY = sin(degreeSec) * (radius / 1.5);
|
||||
toSecX = cos(degreeSec) * radius;
|
||||
toSecY = sin(degreeSec) * radius;
|
||||
uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY);
|
||||
uView.line(1+posX+fromSecX, 1+posY+fromSecY, 1+posX+toSecX, 1+posY+toSecY);
|
||||
}
|
||||
|
||||
if (radius>15) {
|
||||
@@ -1697,7 +1687,7 @@ void MicroViewGauge::drawFace() {
|
||||
fromSecY = sin(degreeSec) * (radius / 1.3);
|
||||
toSecX = cos(degreeSec) * radius;
|
||||
toSecY = sin(degreeSec) * radius;
|
||||
uView.line(1+offsetX+fromSecX,1+offsetY+fromSecY,1+offsetX+toSecX,1+offsetY+toSecY);
|
||||
uView.line(1+posX+fromSecX, 1+posY+fromSecY, 1+posX+toSecX, 1+posY+toSecY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1714,20 +1704,19 @@ void MicroViewGauge::draw() {
|
||||
needFirstDraw=false;
|
||||
}
|
||||
else {
|
||||
prevValue=getValue();
|
||||
prevValue=value;
|
||||
// Draw current pointer
|
||||
drawPointer();
|
||||
}
|
||||
|
||||
// Draw numeric value if required
|
||||
if (!noValDraw) {
|
||||
uint8_t offsetY = getY();
|
||||
uint8_t offsetX = getX() - (getMaxValLen() * 3 - 1); // Offset left of centre to print the value
|
||||
uint8_t offsetX = posX - (maxValLen * 3 - 1); // Offset left of centre to print the value
|
||||
|
||||
if (style > 0)
|
||||
uView.setCursor(offsetX, offsetY+10);
|
||||
uView.setCursor(offsetX, posY+10);
|
||||
else
|
||||
uView.setCursor(offsetX, offsetY+11);
|
||||
uView.setCursor(offsetX, posY+11);
|
||||
|
||||
drawNumValue(prevValue);
|
||||
}
|
||||
@@ -1735,19 +1724,15 @@ void MicroViewGauge::draw() {
|
||||
|
||||
// Use XOR mode to erase or draw the pointer for prevValue
|
||||
void MicroViewGauge::drawPointer() {
|
||||
uint8_t offsetX, offsetY;
|
||||
float degreeSec, toSecX, toSecY;
|
||||
|
||||
offsetX = getX();
|
||||
offsetY = getY();
|
||||
|
||||
// total 240 degree in the widget with 150 degree starting point
|
||||
degreeSec = (((float)(uint16_t)(prevValue-getMinValue()) / (float)(uint16_t)(getMaxValue()-getMinValue())
|
||||
degreeSec = (((float)(uint16_t)(prevValue-minValue) / (float)(uint16_t)(maxValue-minValue)
|
||||
* 240) + 150) * (PI / 180);
|
||||
|
||||
toSecX = cos(degreeSec) * (radius / 1.2);
|
||||
toSecY = sin(degreeSec) * (radius / 1.2);
|
||||
uView.line(offsetX,offsetY,1+offsetX+toSecX,1+offsetY+toSecY, WHITE,XOR);
|
||||
uView.line(posX, posY, 1+posX+toSecX, 1+posY+toSecY, WHITE, XOR);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user