Ejemplo n.º 1
0
// used to do circles and roundrects!
void Adafruit_GFX::fillCircleHelper(int16 x0, int16 y0, int16 r,
				    uint8 cornername, int16 delta, uint32 color) {

  int16 f     = 1 - r;
  int16 ddF_x = 1;
  int16 ddF_y = -2 * r;
  int16 x     = 0;
  int16 y     = r;

  while (x<y) {
    if (f >= 0) {
      y--;
      ddF_y += 2;
      f     += ddF_y;
    }
    x++;
    ddF_x += 2;
    f     += ddF_x;

    if (cornername & 0x1) {
      drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
    }
    if (cornername & 0x2) {
      drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
    }
  }
}
Ejemplo n.º 2
0
void FramebufferGFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color) {
  // From Adafruit library
  int16_t f     = 1 - r;
  int16_t ddF_x = 1;
  int16_t ddF_y = -2 * r;
  int16_t x     = 0;
  int16_t y     = r;

  while (x<y) {
    if (f >= 0) {
      y--;
      ddF_y += 2;
      f     += ddF_y;
    }
    x++;
    ddF_x += 2;
    f     += ddF_x;

    if (cornername & 0x1) {
      drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
    }
    if (cornername & 0x2) {
      drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
    }
  }  
}
Ejemplo n.º 3
0
// Rounded rectangles
void FramebufferGFX::drawRoundRect(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t r, uint16_t color) {
  // From Adafruit library (modified)
  int16_t w = x1 - x0;
  int16_t h = y1 - y0;
  int16_t x = x0;
  int16_t y = y0;
  if (x0 > x1) {
    x = x1;
    w = -w;
  }
  if (y0 > y1) {
    y = y1;
    h = -h;
  }
  
  // smarter version
  drawFastHLine(x+r  , y    , w-2*r, color); // Top
  drawFastHLine(x+r  , y+h-1, w-2*r, color); // Bottom
  drawFastVLine(x    , y+r  , h-2*r, color); // Left
  drawFastVLine(x+w-1, y+r  , h-2*r, color); // Right
  // draw four corners
  drawCircleHelper(x+r    , y+r    , r, 1, color);
  drawCircleHelper(x+w-r-1, y+r    , r, 2, color);
  drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
  drawCircleHelper(x+r    , y+h-r-1, r, 8, color);  
}
Ejemplo n.º 4
0
// Used to do circles and roundrects
ICACHE_FLASH_ATTR void Adafruit_GFX_AS::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
		uint8_t cornername, int16_t delta, uint16_t color) {

	int16_t f     = 1 - r;
	int16_t ddF_x = 1;
	int16_t ddF_y = -2 * r;
	int16_t x     = 0;
	int16_t y     = r;

	while (x<y) {
		if (f >= 0) {
			y--;
			ddF_y += 2;
			f     += ddF_y;
		}
		x++;
		ddF_x += 2;
		f     += ddF_x;

		if (cornername & 0x1) {
			drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
			drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
		}
		if (cornername & 0x2) {
			drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
			drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
		}
	}
}
Ejemplo n.º 5
0
// used to do circles and roundrects!
void GOFi2cOLED::fillCircleHelper(uint8_t x0, uint8_t y0, uint8_t r,
				    uint8_t cornername, int16_t delta, uint8_t color) {

  int16_t f     = 1 - r;
  int16_t ddF_x = 1;
  int16_t ddF_y = -2 * r;
  int16_t x     = 0;
  int16_t y     = r;

  while (x<y) {
    if (f >= 0) {
      y--;
      ddF_y += 2;
      f     += ddF_y;
    }
    x++;
    ddF_x += 2;
    f     += ddF_x;

    if (cornername & 0x1) {
      drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
    }
    if (cornername & 0x2) {
      drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
    }
  }
}
Ejemplo n.º 6
0
// Draw a rectangle
void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h,
 uint16_t color) {
  drawFastHLine(x, y, w, color);
  drawFastHLine(x, y+h-1, w, color);
  drawFastVLine(x, y, h, color);
  drawFastVLine(x+w-1, y, h, color);
}
Ejemplo n.º 7
0
// draw a rectangle
void Adafruit_GFX::drawRect(int16 x, int16 y, 
			    int16 w, int16 h, 
			    uint32 color) {
  drawFastHLine(x, y, w, color);
  drawFastHLine(x, y+h-1, w, color);
  drawFastVLine(x, y, h, color);
  drawFastVLine(x+w-1, y, h, color);
}
Ejemplo n.º 8
0
// draw a rectangle
void GOFi2cOLED::drawRect(uint8_t x, uint8_t y, 
			    uint8_t w, uint8_t h, 
			    uint8_t color) {
  drawFastHLine(x, y, w, color);
  drawFastHLine(x, y+h-1, w, color);
  drawFastVLine(x, y, h, color);
  drawFastVLine(x+w-1, y, h, color);
}
Ejemplo n.º 9
0
void Arduboy::drawRect
(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t color)
{
  drawFastHLine(x, y, w, color);
  drawFastHLine(x, y+h-1, w, color);
  drawFastVLine(x, y, h, color);
  drawFastVLine(x+w-1, y, h, color);
}
void SmartMatrix::drawRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  uint16_t radius, const rgb24& outlineColor) {
    if (x1 < x0)
        SWAPint(x1, x0);

    if (y1 < y0)
        SWAPint(y1, y0);

    // decrease large radius that would break shape
    if(radius > (x1-x0)/2)
        radius = (x1-x0)/2;
    if(radius > (y1-y0)/2)
        radius = (y1-y0)/2;

    int a = radius, b = 0;
    int radiusError = 1 - a;

    // draw straight part of outline
    drawFastHLine(x0 + radius, x1 - radius, y0, outlineColor);
    drawFastHLine(x0 + radius, x1 - radius, y1, outlineColor);
    drawFastVLine(x0, y0 + radius, y1 - radius, outlineColor);
    drawFastVLine(x1, y0 + radius, y1 - radius, outlineColor);

    // convert coordinates to point at center of rounded sections
    x0 += radius;
    x1 -= radius;
    y0 += radius;
    y1 -= radius;

    while (a >= b)
    {
        // this pair sweeps from far left towards right
        drawPixel(-a + x0, -b + y0, outlineColor);
        drawPixel(-a + x0, b + y1, outlineColor);

        // this pair sweeps from far right towards left
        drawPixel(a + x1, -b + y0, outlineColor);
        drawPixel(a + x1, b + y1, outlineColor);

        // this pair sweeps from very top towards bottom
        drawPixel(-b + x0, -a + y0, outlineColor);
        drawPixel(b + x1, -a + y0, outlineColor);

        // this pair sweeps from bottom up
        drawPixel(-b + x0, a + y1, outlineColor);
        drawPixel(b + x1, a + y1, outlineColor);

        b++;
        if (radiusError < 0) {
            radiusError += 2 * b + 1;
        } else {
            a--;
            radiusError += 2 * (b - a + 1);
        }
    }
}
Ejemplo n.º 11
0
// draw a rounded rectangle!
void GOFi2cOLED::drawRoundRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t r, uint8_t color) {
  // smarter version
  drawFastHLine(x+r  , y    , w-2*r, color); // Top
  drawFastHLine(x+r  , y+h-1, w-2*r, color); // Bottom
  drawFastVLine(  x    , y+r  , h-2*r, color); // Left
  drawFastVLine(  x+w-1, y+r  , h-2*r, color); // Right
  // draw four corners
  drawCircleHelper(x+r    , y+r    , r, 1, color);
  drawCircleHelper(x+w-r-1, y+r    , r, 2, color);
  drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
  drawCircleHelper(x+r    , y+h-r-1, r, 8, color);
}
Ejemplo n.º 12
0
// Draw a rounded rectangle
void Adafruit_GFX_AS::drawRoundRect(int16_t x, int16_t y, int16_t w,
		int16_t h, int16_t r, uint16_t color) {
	// smarter version
	drawFastHLine(x+r  , y    , w-2*r, color); // Top
	drawFastHLine(x+r  , y+h-1, w-2*r, color); // Bottom
	drawFastVLine(x    , y+r  , h-2*r, color); // Left
	drawFastVLine(x+w-1, y+r  , h-2*r, color); // Right
	// draw four corners
	drawCircleHelper(x+r    , y+r    , r, 1, color);
	drawCircleHelper(x+w-r-1, y+r    , r, 2, color);
	drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
	drawCircleHelper(x+r    , y+h-r-1, r, 8, color);
}
Ejemplo n.º 13
0
void Adafruit_GFX_AS::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
		uint16_t color) {
	// Update in subclasses if desired!
	for (int16_t i=x; i<x+w; i++) {
		drawFastVLine(i, y, h, color);
	}
}
Ejemplo n.º 14
0
void Adafruit_GFX::fillRect(int16 x, int16 y, int16 w, int16 h, 
			    uint32 color) {
  // stupidest version - update in subclasses if desired!
  for (int16 i=x; i<x+w; i++) {
    drawFastVLine(i, y, h, color); 
  }
}
Ejemplo n.º 15
0
void GOFi2cOLED::fillRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, 
			    uint8_t color) {
  // stupidest version - update in subclasses if desired!
  for (uint8_t i=x; i<x+w; i++) {
    drawFastVLine(i, y, h, color); 
  }
}
Ejemplo n.º 16
0
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
{
  // stupidest version - update in subclasses if desired!
  for (int16_t i=x; i<x+w; i++)
	{
    drawFastVLine(i, y, h, color);
  }
}
Ejemplo n.º 17
0
void Arduboy::fillCircleHelper
(
 int16_t x0,
 int16_t y0,
 int16_t r,
 uint8_t cornername,
 int16_t delta,
 uint8_t color
)
{
  // used to do circles and roundrects!
  int16_t f = 1 - r;
  int16_t ddF_x = 1;
  int16_t ddF_y = -2 * r;
  int16_t x = 0;
  int16_t y = r;

  while (x < y)
  {
    if (f >= 0)
    {
      y--;
      ddF_y += 2;
      f += ddF_y;
    }

    x++;
    ddF_x += 2;
    f += ddF_x;

    if (cornername & 0x1)
    {
      drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
    }

    if (cornername & 0x2)
    {
      drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
      drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
    }
  }
}
Ejemplo n.º 18
0
// Rectangles
void FramebufferGFX::drawRect(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) {
  int16_t w = x1 - x0;
  int16_t h = y1 - y0;
  int16_t x = x0;
  int16_t y = y0;
  if (x0 > x1) {
    x = x1;
    w = -w;
  }
  if (y0 > y1) {
    y = y1;
    h = -h;
  }
  
  // (x, y) is lower corner
  drawFastHLine(x, y, w, color);             // top
  drawFastHLine(x, y + h, w, color);         // bottom  
  drawFastVLine(x, y, h, color);             // left 
  drawFastVLine(x + w, y, h, color);         // right  
}
Ejemplo n.º 19
0
//*****************************************************************************
void testfastlines(unsigned int color1, unsigned int color2) {
  unsigned int x;
  unsigned int y;

  fillScreen(BLACK);
  for (y = 0; y < height() - 1; y += 8) {
    drawFastHLine(0, y, width() - 1, color1);
  }
  delay(100);
  for (x = 0; x < width() - 1; x += 8) {
    drawFastVLine(x, 0, height() - 1, color2);
  }
  delay(100);
}
Ejemplo n.º 20
0
size_t screenkeys::write(uint8_t c){
	if (_cursor_x > _width || _cursor_y > _height) return 1;
	struct FontHeader header;
	memcpy_P(&header, _font, sizeof(FontHeader));
	//char too high.
	if (_cursor_y+header.height < 0) return 1;
	if (_cursor_x > 0) drawLine(_cursor_x - 1,_cursor_y,_cursor_x - 1,(_cursor_y + header.height) - 1, _background);
		if(c == '\n') { // Newline
			_cursor_y = _cursor_y - header.height - 1;
		} else if (c == '\r') {	
		} else {
			//write char and get his heigh!
			int charWide = drawChar(_cursor_x, _cursor_y, c, _foreground, _background);
			if (charWide > 0) {//char writed, erase following to avoid garbage
				#if defined(_PRECLN)
				drawFastVLine(_cursor_x + charWide, _cursor_y, _cursor_y + header.height-1, _background);
				#endif
			}
		}
	return 1;
}
Ejemplo n.º 21
0
void screenkeys::fillRect(uint8_t x,uint8_t y,uint8_t w,uint8_t h,bool color) {
	uint8_t i;
	for (i=x; i<x+w; i++) {
		drawFastVLine(i, y, h, color);
	}
}
void SmartMatrix::drawRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, const rgb24& color) {
    drawFastHLine(x0, x1, y0, color);
    drawFastHLine(x0, x1, y1, color);
    drawFastVLine(x0, y0, y1, color);
    drawFastVLine(x1, y0, y1, color);
}
void SmartMatrix::fillRoundRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
  uint16_t radius, const rgb24& outlineColor, const rgb24& fillColor) {
    if (x1 < x0)
        SWAPint(x1, x0);

    if (y1 < y0)
        SWAPint(y1, y0);

    // decrease large radius that would break shape
    if(radius > (x1-x0)/2)
        radius = (x1-x0)/2;
    if(radius > (y1-y0)/2)
        radius = (y1-y0)/2;

    int a = radius, b = 0;
    int radiusError = 1 - a;

    if (radius == 0) {
        fillRectangle(x0, y0, x1, y1, outlineColor, fillColor);
    }

    // draw straight part of outline
    drawFastHLine(x0 + radius, x1 - radius, y0, outlineColor);
    drawFastHLine(x0 + radius, x1 - radius, y1, outlineColor);
    drawFastVLine(x0, y0 + radius, y1 - radius, outlineColor);
    drawFastVLine(x1, y0 + radius, y1 - radius, outlineColor);

    // convert coordinates to point at center of rounded sections
    x0 += radius;
    x1 -= radius;
    y0 += radius;
    y1 -= radius;

    // only draw one line per row/column, skipping the sides
    bool hlineDrawn = true;
    bool vlineDrawn = true;

    while (a >= b)
    {
        // this pair sweeps from far left towards right
        drawPixel(-a + x0, -b + y0, outlineColor);
        drawPixel(-a + x0, b + y1, outlineColor);

        // this pair sweeps from far right towards left
        drawPixel(a + x1, -b + y0, outlineColor);
        drawPixel(a + x1, b + y1, outlineColor);

        if (!vlineDrawn) {
            drawFastVLine(-a + x0, (-b + 1) + y0, (b - 1) + y1, fillColor);
            drawFastVLine(a + x1, (-b + 1) + y0, (b - 1) + y1, fillColor);
            vlineDrawn = true;
        }

        // this pair sweeps from very top towards bottom
        drawPixel(-b + x0, -a + y0, outlineColor);
        drawPixel(b + x1, -a + y0, outlineColor);

        // this pair sweeps from bottom up
        drawPixel(-b + x0, a + y1, outlineColor);
        drawPixel(b + x1, a + y1, outlineColor);

        if (!hlineDrawn) {
            drawFastHLine((-b + 1) + x0, (b - 1) + x1, -a + y0, fillColor);
            drawFastHLine((-b + 1) + x0, (b - 1) + x1, a + y1, fillColor);
            hlineDrawn = true;
        }

        b++;
        if (radiusError < 0) {
            radiusError += 2 * b + 1;
        } else {
            a--;
            hlineDrawn = false;
            vlineDrawn = false;
            radiusError += 2 * (b - a + 1);
        }
    }

    // draw rectangle in center
    fillRectangle(x0 - a, y0 - a, x1 + a, y1 + a, fillColor);
}
Ejemplo n.º 24
0
void Adafruit_GFX::fillCircle(int16 x0, int16 y0, int16 r, 
			      uint32 color) {
  drawFastVLine(x0, y0-r, 2*r+1, color);
  fillCircleHelper(x0, y0, r, 3, 0, color);
}
Ejemplo n.º 25
0
uint8_t screenkeys::drawChar(uint8_t x,uint8_t y, unsigned char c,bool colour,bool _background){
	if (x >= _width || y >= _height) {
		return 0;
	}
	struct FontHeader header;
	memcpy_P(&header, (void*)_font, sizeof(FontHeader));
	if (c == ' ') {//write an empty
		uint8_t charWide = charWidth(' ');
		fillRect(x,y-1,x + charWide,y + header.height,_background);
		return charWide;
	}
	//char out of range!
	if (c < header.firstChar || c >= (header.firstChar + header.charCount)) {
		return 0;
	}
	uint8_t width = 0;
	uint16_t index = 0;
	//how many bytes it's a col?
	uint8_t bytes = (header.height + 7) / 8;
	//calculate char
	c -= header.firstChar;
	// Fixed Width or Variabile?
	if (header.size == 0) {//fixed width
		width = header.fixedWidth;
		//questo calcola quanto è grande l'indice intero di tutti i bits del font
		//lenght of index of all font-bits
		index = sizeof(FontHeader) + (c*(bytes * width));
	} else {
		// variable width font, read width data, to get the index
		for (uint8_t i = 0; i < c; i++) {
			index += pgm_read_byte(this->_font + sizeof(FontHeader) + i);
		}
		index = index * bytes + sizeof(FontHeader) + header.charCount;
		width = pgm_read_byte(this->_font + sizeof(FontHeader) + c);
	}
	//char is inside screen?
	if (x < -width || y < -header.height) return 0;
	//to prevent garbage
	#if defined(_PRECLN)
	drawFastVLine(x>0?x:0,y>0?y:0,(y+header.height)>(_height-1)?(_height-1):(y+header.height)-1,_background);
	#endif
	for (int16_t ox = 0; ox < width; ox++) {
		if (ox+x >= _width) break;
		int16_t oy = 0;
		for (int8_t byte_y = bytes-1; byte_y >= 0; byte_y--) {
			uint8_t data = pgm_read_byte(this->_font + index + ox + (byte_y * width));
			int8_t start_bit;
			int8_t end_bit;
			if (bytes == 1) {
				start_bit = header.height-1;
				end_bit = 0;
			} else {
				start_bit = 7;
				end_bit = (byte_y < (bytes-1)) ? 0: 7-((header.height-1)%8);
			}
			for(int8_t bit_y = start_bit; bit_y >= end_bit; bit_y--) {
				if ((oy + y) < _height && (ox + x) >= 0 && (oy + y) >= 0) {
					 //drawPixel(x+ox,y+(((header.height-1)-bit_y)-(byte_y*(1+start_bit-end_bit))), (data & 1<<bit_y) ? colour : _background);
					 drawPixel(x+ox,y+(((header.height-1)-bit_y)-(byte_y*(1+start_bit-end_bit))),(data & (1 << bit_y)) ? colour : _background);
				}
				oy++;
				if (oy == header.height) break;
			}
		}
		_cursor_x++;//cursor
	}
	_cursor_x++;//cursor
	return width;
}
Ejemplo n.º 26
0
void FramebufferGFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) {
  // From Adafruit library
  drawFastVLine(x0, y0-r, 2*r+1, color);
  fillCircleHelper(x0, y0, r, 3, 0, color);  
}
Ejemplo n.º 27
0
void Arduboy::fillCircle(int16_t x0, int16_t y0, int16_t r, uint8_t color)
{
  drawFastVLine(x0, y0-r, 2*r+1, color);
  fillCircleHelper(x0, y0, r, 3, 0, color);
}
Ejemplo n.º 28
0
ICACHE_FLASH_ATTR void Adafruit_GFX_AS::fillCircle(int16_t x0, int16_t y0, int16_t r,
		uint16_t color) {
	drawFastVLine(x0, y0-r, 2*r+1, color);
	fillCircleHelper(x0, y0, r, 3, 0, color);
}
Ejemplo n.º 29
0
void GOFi2cOLED::fillCircle(uint8_t x0, uint8_t y0, uint8_t r, 
			      uint8_t color) {
  drawFastVLine(x0, y0-r, 2*r+1, color);
  fillCircleHelper(x0, y0, r, 3, 0, color);
}
Ejemplo n.º 30
0
void screenkeys::fillCircle(uint8_t x0, uint8_t y0, uint16_t r,bool color) {
	drawFastVLine(x0, y0-r, 2*r+1, color);
	fillCircleHelper(x0, y0, r, 3, 0, color);
}