Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

include/SGL.h

Committer:
messi1
Date:
2015-11-17
Revision:
10:ef7440718431
Parent:
8:ff74bd4d94d6
Child:
11:162aa3e801df

File content as of revision 10:ef7440718431:

/*
* SGL.h
* A library for Seeed Graphical library
*  
* Copyright (c) 2014 seeed technology inc. 
* Author        :   lawliet.zou(lawliet.zou@gmail.com)
* Create Time   :   Jun 06, 2014
* Change Log    :   
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef _SGL_H_ //Seeed Graphics Library
#define _SGL_H_

#include <stdint.h>

#define FONT_SPACE 6
#define FONT_X 8
#define FONT_Y 8

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

typedef const unsigned char** FontType;

class SGL {
 
public:
    SGL(uint8_t width, uint8_t height);
    virtual void drawPixel(uint8_t x, uint8_t y, uint16_t color) = 0; // implemented by subclass
    virtual void drawLine(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint16_t color);
    virtual void drawVLine(uint8_t x, uint8_t y, uint8_t length,uint16_t color);
    virtual void drawHLine(uint8_t x, uint8_t y, uint8_t length, uint16_t color);
    virtual void drawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color);
    virtual void fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color);
    virtual void drawCircle(uint8_t x, uint8_t y, uint8_t r, uint16_t color);
    virtual void fillCircle(uint8_t x, uint8_t y, uint8_t r, uint16_t color);
    virtual void drawTraingle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color);
    virtual void fillTraingle(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color);    
    
    // The zoom factor works at the moment only with integer values. Float values will create bad fonts 
    virtual void drawChar(uint8_t ascii, uint8_t x, uint8_t y, float zoom, uint16_t color);
    virtual void drawString(const char *string, uint8_t x, uint8_t y, float zoom, uint16_t color, uint8_t fontSpace=6);
    
    virtual void drawBitMap(uint8_t x, uint8_t y, const uint8_t *bitmap, uint8_t width, uint8_t height, uint16_t color);
    virtual void fillScreen(uint16_t color);
    virtual void setFont(FontType font, uint8_t width, uint8_t height, uint8_t start, uint8_t stop);
    
private:
    void swap(uint8_t* a, uint8_t* b){ 
        uint8_t t = *a; *a = *b; *b = t; 
    };
    
    uint8_t _width;
    uint8_t _height;
    FontType _currentFont;
    uint8_t _fontWidth;
    uint8_t _fontHeight;
    uint8_t _fontStart;
    uint8_t _fontStop;
};

#endif