My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

u8g_cursor.c 3.0KB

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