Skip to content

Commit 2a8aab9

Browse files
author
Kirk
committed
moved rect calls to Width, Height, not end point
1 parent 302c55b commit 2a8aab9

File tree

8 files changed

+61
-57
lines changed

8 files changed

+61
-57
lines changed

examples/Example-01_Hello/Example-01_Hello.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void setup()
118118
// Do a simple test - fill a rectangle on the screen and then print hello!
119119

120120
// fill a rectangle on the screen that has a 4 pixel board
121-
myOLED.rectangleFill(4, 4, myOLED.getWidth()-4, myOLED.getHeight()-4);
121+
myOLED.rectangleFill(4, 4, myOLED.getWidth()-8, myOLED.getHeight()-8);
122122

123123
String hello = "hello"; // our message
124124

examples/Example-02_Shapes/Example-02_Shapes.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void line_test_vert(void){
192192
// Simple - draw a rectangle test
193193
void rect_test(void){
194194

195-
myOLED.rectangle(4, 4, width-4, height-4);
195+
myOLED.rectangle(4, 4, width-8, height-8);
196196

197197
}
198198

@@ -213,11 +213,11 @@ void rect_test_move(void){
213213
for(int i = 0; i < steps; i++){
214214

215215
// Draw the rectangle and send it to device
216-
myOLED.rectangle(x, y, x+side, y+side);
216+
myOLED.rectangle(x, y, side, side);
217217
myOLED.display(); // sends erased rect and new rect pixels to device
218218

219219
// Erase the that rect, increment and loop
220-
myOLED.rectangle(x, y, x+side, y+side, 0);
220+
myOLED.rectangle(x, y, side, side, 0);
221221

222222
x += xinc;
223223
y += yinc;
@@ -233,12 +233,12 @@ void rect_test_move(void){
233233

234234
void rect_fill_test(void){
235235

236-
myOLED.rectangleFill(4, 4, width/2-4, height-4);
236+
myOLED.rectangleFill(4, 4, width/2-8, height-8);
237237

238-
myOLED.rectangleFill(width/2+4, 4, width-4, height-4);
238+
myOLED.rectangleFill(width/2+4, 4, width/2-8, height-8);
239239

240240
myOLED.setDrawMode(grROPXOR); // xor
241-
myOLED.rectangleFill(width/4, 8, width - width/4, height-8);
241+
myOLED.rectangleFill(width/4, 8, width/2, height-16);
242242
myOLED.setDrawMode(grROPCopy); // back to copy op (default)
243243
}
244244

examples/Example-08_Multi/Example-08_Multi.ino

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
//
6161
// The default is Micro OLED
6262

63-
//#define MICRO
63+
#define MICRO
6464
//#define NARROW
65-
#define TRANSPARENT
65+
//#define TRANSPARENT
6666

6767
//////////////////////////////////////////////////////////////////////////////////////////
6868

@@ -201,10 +201,10 @@ void shapeExample()
201201
myOLED.erase();
202202

203203
// Draw an outline of the screen:
204-
myOLED.rectangle(0, 0, width-1, height-1);
204+
myOLED.rectangle(0, 0, width-1, height);
205205

206206
// Draw the center line
207-
myOLED.rectangleFill( width/ 2 - 1, 0, width/2 + 1, height-1);
207+
myOLED.rectangleFill( width/ 2 - 1, 0, 2, height);
208208

209209
bool firstLoop = true;
210210

@@ -214,10 +214,10 @@ void shapeExample()
214214

215215
// Erase the old ball. In XOR mode, so just draw old values again!
216216
// Draw the Paddles:
217-
myOLED.rectangleFill(paddle0_X, paddle0_Y, paddle0_X+paddleW, paddle0_Y+paddleH);
218-
myOLED.rectangleFill(paddle1_X, paddle1_Y, paddle1_X+paddleW, paddle1_Y+paddleH);
217+
myOLED.rectangleFill(paddle0_X, paddle0_Y, paddleW, paddleH);
218+
myOLED.rectangleFill(paddle1_X, paddle1_Y, paddleW, paddleH);
219219
// Draw the ball: - use rect - xor and circle fails b/c of circle algorithm overdraws
220-
myOLED.rectangleFill(ball_X, ball_Y, ball_X+ball_rad, ball_Y+ball_rad);
220+
myOLED.rectangleFill(ball_X, ball_Y, ball_rad, ball_rad);
221221
}
222222
// Increment ball's position
223223
ball_X += ballVelocityX;
@@ -265,11 +265,11 @@ void shapeExample()
265265
paddle1Velocity = -paddle1Velocity;
266266

267267
// Draw the Paddles:
268-
myOLED.rectangleFill(paddle0_X, paddle0_Y, paddle0_X+paddleW, paddle0_Y+paddleH);
269-
myOLED.rectangleFill(paddle1_X, paddle1_Y, paddle1_X+paddleW, paddle1_Y+paddleH);
268+
myOLED.rectangleFill(paddle0_X, paddle0_Y, paddleW, paddleH);
269+
myOLED.rectangleFill(paddle1_X, paddle1_Y, paddleW, paddleH);
270270

271271
// Draw the ball:
272-
myOLED.rectangleFill(ball_X, ball_Y, ball_X+ball_rad, ball_Y+ball_rad);
272+
myOLED.rectangleFill(ball_X, ball_Y, ball_rad, ball_rad);
273273

274274
// Actually draw everything on the screen:
275275
myOLED.display();

src/SparkFun_Qwiic_OLED.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,12 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
474474
// --------- -----------------------------
475475
// x0 The start X coordinate of the rectangle - upper left corner
476476
// y0 The start Y coordinate of the rectangle - upper left corner
477-
// x1 The end X coordinate of the rectangle - lower right corner
478-
// y1 The end Y coordinate of the rectangle - lower right corner
477+
// width The width of the rectangle
478+
// height The height of the rectangle
479479
// clr optional The color value to draw the rectangle. This defaults to white (1).
480480

481-
void rectangle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr=COLOR_WHITE){
482-
_device.rectangle(x0, y0, x1, y1, clr);
481+
void rectangle(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr=COLOR_WHITE){
482+
_device.rectangle(x0, y0, width, height, clr);
483483
}
484484

485485
///////////////////////////////////////////////////////////////////////
@@ -491,12 +491,12 @@ class QwiicOLEDBaseClass : public Print { // NOTE: implementing Arduino Print
491491
// --------- -----------------------------
492492
// x0 The start X coordinate of the rectangle - upper left corner
493493
// y0 The start Y coordinate of the rectangle - upper left corner
494-
// x1 The end X coordinate of the rectangle - lower right corner
495-
// y1 The end Y coordinate of the rectangle - lower right corner
494+
// width The width of the rectangle
495+
// height The height of the rectangle
496496
// clr optional The color value to draw the filled rectangle. This defaults to white (1).
497497

498-
void rectangleFill(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr=COLOR_WHITE){
499-
_device.rectangle_fill(x0, y0, x1, y1, clr);
498+
void rectangleFill(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr=COLOR_WHITE){
499+
_device.rectangle_fill(x0, y0, width, height, clr);
500500
}
501501

502502
///////////////////////////////////////////////////////////////////////

src/qwiic_grbuffer.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -312,28 +312,22 @@ void QwGrBufferDevice::draw_line(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
312312
//
313313
// Draw a rectangle on screen.
314314

315-
void QwGrBufferDevice::rectangle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){
315+
void QwGrBufferDevice::rectangle(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){
316316

317317
// Is this a line?
318-
if(x0 == x1 || y0 == y1){
318+
if(width <=1 || height <=1){
319319
// this is a line
320-
line(x0, y0, x1, y1);
320+
line(x0, y0, x0+width-1, y0+height-1);
321321
return;
322322
}
323323

324-
// Sanity check
325-
if(x0 > x1 || y0 > y1){
326-
swap_int(x0, x1);
327-
swap_int(y0, y1);
328-
}
329-
330324
// bounds check
331325
if(x0 >= _viewport.width || y0 >= _viewport.height)
332326
return; // not on screen
333327

334328
// Send to drawing routine.
335329

336-
(*_idraw.draw_rect)(this, x0, y0, x1, y1, clr);
330+
(*_idraw.draw_rect)(this, x0, y0, width, height, clr);
337331

338332
}
339333

@@ -342,11 +336,14 @@ void QwGrBufferDevice::rectangle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
342336
//
343337
// Does the actual drawing/logic
344338

345-
void QwGrBufferDevice::draw_rect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){
339+
void QwGrBufferDevice::draw_rect(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){
346340

347341

348342
// A rect is really just a series of vert and horz lines
349343

344+
uint8_t x1 = x0 + width-1;
345+
uint8_t y1 = y0 + height-1;
346+
350347
(*_idraw.draw_line_horz)(this, x0, y0, x1, y0, clr);
351348
(*_idraw.draw_line_horz)(this, x0, y1, x1, y1, clr);
352349

@@ -364,37 +361,34 @@ void QwGrBufferDevice::draw_rect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
364361
////////////////////////////////////////////////////////////////////////////////////////
365362
// rectangle_fill()
366363

367-
void QwGrBufferDevice::rectangle_fill(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){
364+
void QwGrBufferDevice::rectangle_fill(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){
368365

369366

370-
if(x0 == x1 || y0 == y1){
367+
// Is this a line?
368+
if(width <=1 || height <=1){
371369
// this is a line
372-
line(x0, y0, x1, y1);
370+
line(x0, y0, x0+width-1, y0+height-1);
373371
return;
374372
}
375-
376-
// Sanity check
377-
if(x0 > x1 || y0 > y1){
378-
swap_int(x0, x1);
379-
swap_int(y0, y1);
380-
}
381-
382373
// bounds check
383374
if(x0 >= _viewport.width || y0 >= _viewport.height)
384375
return; // not on screen
385376

386377
// Send to drawing routine.
387378

388-
(*_idraw.draw_rect_filled)(this, x0, y0, x1, y1, clr);
379+
(*_idraw.draw_rect_filled)(this, x0, y0, width, height, clr);
389380

390381
}
391382
////////////////////////////////////////////////////////////////////////////////////////
392383
// draw_rect_fill()
393384
//
394385
// Does the actual drawing/logic
395386

396-
void QwGrBufferDevice::draw_rect_filled(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){
387+
void QwGrBufferDevice::draw_rect_filled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){
388+
397389

390+
uint8_t x1 = x0 + width-1;
391+
uint8_t y1 = y0 + height-1;
398392

399393
// Just draw vertical lines
400394
for(int i=x0; i <= x1; i++)

src/qwiic_grbuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class _QwIDraw{
104104
virtual void draw_line_vert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){}
105105

106106
// Rectangles
107-
virtual void draw_rect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){}
108-
virtual void draw_rect_filled(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr){}
107+
virtual void draw_rect(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){}
108+
virtual void draw_rect_filled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){}
109109

110110
//Circles
111111
virtual void draw_circle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t clr){}

src/qwiic_grssd1306.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@ bool QwGrSSD1306::init(void){
238238
if(!this->QwGrBufferDevice::init())
239239
return false; // something isn't right
240240

241-
// At this point, the main device interface is filled in. This classes draw_line_vert()
242-
// can also draw filled rects, so hack the device table to have draw_rect_filled points
243-
// to this classes draw_line_vert(), which should be the method in the draw_line_vert entry
244-
// of the draw interface.
245-
246-
_idraw.draw_rect_filled = _idraw.draw_line_vert;
247-
248241
// Start the device setup - sending commands to device. See command defs in header, and
249242
// device datasheet
250243
send_dev_command(kCmdDisplayOff);
@@ -679,7 +672,21 @@ void QwGrSSD1306::draw_line_vert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
679672
}
680673

681674
}
675+
////////////////////////////////////////////////////////////////////////////////////////
676+
// draw_rect_fill()
677+
//
678+
// Does the actual drawing/logic
679+
680+
void QwGrSSD1306::draw_rect_filled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr){
682681

682+
683+
uint8_t x1 = x0 + width-1;
684+
uint8_t y1 = y0 + height-1;
685+
686+
// just call vert line
687+
draw_line_vert(x0, y0, x1, y1, clr);
688+
689+
}
683690
////////////////////////////////////////////////////////////////////////////////////
684691
// draw_bitmap()
685692
//

src/qwiic_grssd1306.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ class QwGrSSD1306 : public QwGrBufferDevice {
215215
void draw_line_horz(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr);
216216
void draw_line_vert(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t clr);
217217

218+
// fast rect fill
219+
void draw_rect_filled(uint8_t x0, uint8_t y0, uint8_t width, uint8_t height, uint8_t clr);
220+
218221
// >> Fast Bitmap <<
219222
void draw_bitmap(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
220223
uint8_t *pBitmap, uint8_t bmp_width, uint8_t bmp_height );

0 commit comments

Comments
 (0)