Michael Kuchnik / Mbed 2 deprecated uLCD_Multiscreen

Dependencies:   4DGL-uLCD-SE mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uLCD_Multiscreen.cpp Source File

uLCD_Multiscreen.cpp

00001 #include "uLCD_Multiscreen.h"
00002 #include "mbed.h"
00003 uLCD_Multiscreen::uLCD_Multiscreen(vector<uLCD_4DGL*> screens) : virtualScreen(screens, 128, 128 * screens.size())
00004 {
00005     printf("Multiscreen Booting.");
00006 }
00007 
00008 void uLCD_Multiscreen::unfilledRectangle(int x, int y, int w, int h, int color)
00009 {
00010     for(int i = x; i <= x + w; i++) {
00011         virtualScreen.setPixel(i, y, color);
00012     }
00013     for(int i = x; i <= x + w; i++) {
00014         virtualScreen.setPixel(i, y + h, color);
00015     }
00016     
00017     for(int i = y; i <= y + h; i++) {
00018         virtualScreen.setPixel(x, i, color);
00019     }
00020     for(int i = y; i <= y + h; i++) {
00021         virtualScreen.setPixel(x + w, i, color);
00022     }
00023 
00024 }
00025 
00026 void uLCD_Multiscreen::drawLine(int x1, int y1, int  x2, int  y2, int color)
00027 {
00028     int delta_x(x2 - x1);
00029     // if x1 == x2, then it does not matter what we set here
00030     signed char const ix((delta_x > 0) - (delta_x < 0));
00031     delta_x = std::abs(delta_x) << 1;
00032  
00033     int delta_y(y2 - y1);
00034     // if y1 == y2, then it does not matter what we set here
00035     signed char const iy((delta_y > 0) - (delta_y < 0));
00036     delta_y = std::abs(delta_y) << 1;
00037  
00038     virtualScreen.setPixel(x1, y1, color);
00039  
00040     if (delta_x >= delta_y)
00041     {
00042         // error may go below zero
00043         int error(delta_y - (delta_x >> 1));
00044  
00045         while (x1 != x2)
00046         {
00047             if ((error >= 0) && (error || (ix > 0)))
00048             {
00049                 error -= delta_x;
00050                 y1 += iy;
00051             }
00052             // else do nothing
00053  
00054             error += delta_y;
00055             x1 += ix;
00056  
00057             virtualScreen.setPixel(x1, y1, color);
00058         }
00059     }
00060     else
00061     {
00062         // error may go below zero
00063         int error(delta_x - (delta_y >> 1));
00064  
00065         while (y1 != y2)
00066         {
00067             if ((error >= 0) && (error || (iy > 0)))
00068             {
00069                 error -= delta_y;
00070                 x1 += ix;
00071             }
00072             // else do nothing
00073  
00074             error += delta_x;
00075             y1 += iy;
00076  
00077             virtualScreen.setPixel(x1, y1, color);
00078         }
00079     }
00080 }
00081 
00082 void uLCD_Multiscreen::unfilledCircle(int x0, int y0, int radius, int color)
00083 {
00084     int x = radius;
00085   int y = 0;
00086   int radiusError = 1-x;
00087  
00088   while(x >= y)
00089   {
00090     virtualScreen.setPixel(x + x0, y + y0, color);
00091     virtualScreen.setPixel(y + x0, x + y0, color);
00092     virtualScreen.setPixel(-x + x0, y + y0, color);
00093     virtualScreen.setPixel(-y + x0, x + y0, color);
00094     virtualScreen.setPixel(-x + x0, -y + y0, color);
00095     virtualScreen.setPixel(-y + x0, -x + y0, color);
00096     virtualScreen.setPixel(x + x0, -y + y0, color);
00097     virtualScreen.setPixel(y + x0, -x + y0, color);
00098     y++;
00099     if (radiusError<0)
00100     {
00101       radiusError += 2 * y + 1;
00102     }
00103     else
00104     {
00105       x--;
00106       radiusError += 2 * (y - x) + 1;
00107     }
00108   }
00109 }
00110 
00111 void uLCD_Multiscreen::cls() {
00112     virtualScreen.clearScreen();
00113 }
00114 
00115 
00116 void uLCD_Multiscreen::changeBackground(int color) {
00117     virtualScreen.background_color(color);
00118 }
00119 void uLCD_Multiscreen::setBaudRate(int rate) {
00120     virtualScreen.setBaudRate(rate);
00121 }