ui_dummy.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * sfnedit/ui_dummy.c
  3. *
  4. * Copyright (C) 2019 bzt (bztsrc@gitlab)
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use, copy,
  10. * modify, merge, publish, distribute, sublicense, and/or sell copies
  11. * of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  21. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. *
  26. * @brief User interface driver skeleton for an arbitrary hobby OS
  27. *
  28. */
  29. #include <string.h>
  30. #include "lang.h"
  31. #include "util.h"
  32. #include "ui.h"
  33. /* TODO: include your user interface's headers here */
  34. /*#include <dummy.h> */
  35. /**
  36. * Copy text to clipboard
  37. */
  38. void ui_copy(char *s)
  39. {
  40. /* TODO: store the string "s" to the clipboard (up to 5 chars). In lack of such an interface, just print it to console */
  41. printf("UTF8: %s\n", s);
  42. }
  43. /**
  44. * Create a window
  45. */
  46. void *ui_createwin(int w, int h)
  47. {
  48. /* TODO: open a window of size w x h. "youwintype" could be a pointer, a numeric id, whatever you use. */
  49. yourwintype *window = ...;
  50. return (void *)window;
  51. }
  52. /**
  53. * Set window title
  54. */
  55. void ui_titlewin(ui_win_t *win, char *title)
  56. {
  57. /* TODO: set the title for (yourwintype *)win->winid */
  58. }
  59. /**
  60. * Resize a window
  61. */
  62. void ui_resizewin(ui_win_t *win, int w, int h)
  63. {
  64. /* TODO: resize a window to w x h and clear its backstore pixel buffer to theme[THEME_BG] */
  65. win->data = (uint32_t*)(((yourwintype*)win->winid)->pixelbuffer);
  66. for(i = 0; i < w * h; i++) win->data[i] = theme[THEME_BG];
  67. }
  68. /**
  69. * Display modified window
  70. */
  71. void ui_flushwin(ui_win_t *win, int x, int y, int w, int h)
  72. {
  73. /* TODO: the area (x,y)-(x+w,y+h) in backstore pixel buffer has changed, refresh window (yourwintype *)win->winid */
  74. }
  75. /**
  76. * Destroy a window
  77. */
  78. void ui_destroywin(ui_win_t *win)
  79. {
  80. /* TODO: free backstore buffer win->data and close the window (yourwintype *)win->winid */
  81. }
  82. /**
  83. * Focus a window
  84. */
  85. void ui_focuswin(ui_win_t *win)
  86. {
  87. /* TODO: refresh window (yourwintype *)win->winid with the backstore buffer, raise and give focus to it */
  88. }
  89. /**
  90. * Change cursor of window
  91. */
  92. void ui_cursorwin(ui_win_t *win, int cursor)
  93. {
  94. /* TODO: set cursor of window (yourwintype *)win->winid to "cursor" (see ui.h CURSOR_x defines) */
  95. }
  96. /**
  97. * Initialize DUMMY driver
  98. */
  99. void ui_init()
  100. {
  101. /* TODO: initialize your user interaface, load icons, cursors etc. report errors with */
  102. ui_error("DUMMY", ERR_DISPLAY);
  103. }
  104. /**
  105. * Finish DUMMY driver
  106. */
  107. void ui_fini()
  108. {
  109. /* TODO: release resources you allocated in ui_init() */
  110. }
  111. /**
  112. * Convert a DUMMY event
  113. */
  114. void ui_getevent()
  115. {
  116. /* TODO: wait for and read an event (blocking). Fill up the "event" global structure accordingly, see ui.h E_x defines */
  117. }