iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_cursor.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_cursor.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 6 | |
iforce2d | 0:972874f31c98 | 7 | Copyright (c) 2011, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 8 | All rights reserved. |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 11 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 14 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 17 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 18 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 19 | |
iforce2d | 0:972874f31c98 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 33 | |
iforce2d | 0:972874f31c98 | 34 | |
iforce2d | 0:972874f31c98 | 35 | */ |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 38 | |
iforce2d | 0:972874f31c98 | 39 | void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font) |
iforce2d | 0:972874f31c98 | 40 | { |
iforce2d | 0:972874f31c98 | 41 | u8g->cursor_font = cursor_font; |
iforce2d | 0:972874f31c98 | 42 | } |
iforce2d | 0:972874f31c98 | 43 | |
iforce2d | 0:972874f31c98 | 44 | void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 45 | { |
iforce2d | 0:972874f31c98 | 46 | u8g->cursor_encoding = encoding; |
iforce2d | 0:972874f31c98 | 47 | } |
iforce2d | 0:972874f31c98 | 48 | |
iforce2d | 0:972874f31c98 | 49 | void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg) |
iforce2d | 0:972874f31c98 | 50 | { |
iforce2d | 0:972874f31c98 | 51 | u8g->cursor_bg_color = bg; |
iforce2d | 0:972874f31c98 | 52 | u8g->cursor_fg_color = fg; |
iforce2d | 0:972874f31c98 | 53 | } |
iforce2d | 0:972874f31c98 | 54 | |
iforce2d | 0:972874f31c98 | 55 | void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y) |
iforce2d | 0:972874f31c98 | 56 | { |
iforce2d | 0:972874f31c98 | 57 | u8g->cursor_x = cursor_x; |
iforce2d | 0:972874f31c98 | 58 | u8g->cursor_y = cursor_y; |
iforce2d | 0:972874f31c98 | 59 | } |
iforce2d | 0:972874f31c98 | 60 | |
iforce2d | 0:972874f31c98 | 61 | void u8g_EnableCursor(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 62 | { |
iforce2d | 0:972874f31c98 | 63 | u8g->cursor_fn = u8g_DrawCursor; |
iforce2d | 0:972874f31c98 | 64 | } |
iforce2d | 0:972874f31c98 | 65 | |
iforce2d | 0:972874f31c98 | 66 | void u8g_DisableCursor(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 67 | { |
iforce2d | 0:972874f31c98 | 68 | u8g->cursor_fn = (u8g_draw_cursor_fn)0; |
iforce2d | 0:972874f31c98 | 69 | } |
iforce2d | 0:972874f31c98 | 70 | |
iforce2d | 0:972874f31c98 | 71 | void u8g_DrawCursor(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 72 | { |
iforce2d | 0:972874f31c98 | 73 | const u8g_pgm_uint8_t *font; |
iforce2d | 0:972874f31c98 | 74 | uint8_t color; |
iforce2d | 0:972874f31c98 | 75 | uint8_t encoding = u8g->cursor_encoding; |
iforce2d | 0:972874f31c98 | 76 | |
iforce2d | 0:972874f31c98 | 77 | /* get current values */ |
iforce2d | 0:972874f31c98 | 78 | color = u8g_GetColorIndex(u8g); |
iforce2d | 0:972874f31c98 | 79 | font = u8g->font; |
iforce2d | 0:972874f31c98 | 80 | |
iforce2d | 0:972874f31c98 | 81 | /* draw cursor */ |
iforce2d | 0:972874f31c98 | 82 | u8g->font = u8g->cursor_font; |
iforce2d | 0:972874f31c98 | 83 | encoding++; |
iforce2d | 0:972874f31c98 | 84 | u8g_SetColorIndex(u8g, u8g->cursor_bg_color); |
iforce2d | 0:972874f31c98 | 85 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ |
iforce2d | 0:972874f31c98 | 86 | /* required, because y adjustment should not happen to the cursor fonts */ |
iforce2d | 0:972874f31c98 | 87 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); |
iforce2d | 0:972874f31c98 | 88 | encoding--; |
iforce2d | 0:972874f31c98 | 89 | u8g_SetColorIndex(u8g, u8g->cursor_fg_color); |
iforce2d | 0:972874f31c98 | 90 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ |
iforce2d | 0:972874f31c98 | 91 | /* required, because y adjustment should not happen to the cursor fonts */ |
iforce2d | 0:972874f31c98 | 92 | /* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */ |
iforce2d | 0:972874f31c98 | 93 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); |
iforce2d | 0:972874f31c98 | 94 | |
iforce2d | 0:972874f31c98 | 95 | /* restore previous values */ |
iforce2d | 0:972874f31c98 | 96 | u8g->font = font; |
iforce2d | 0:972874f31c98 | 97 | u8g_SetColorIndex(u8g, color); |
iforce2d | 0:972874f31c98 | 98 | } |
iforce2d | 0:972874f31c98 | 99 | |
iforce2d | 0:972874f31c98 | 100 |