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.

grid_layout.h 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*****************
  2. * grid_layout.h *
  3. *****************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <http://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #pragma once
  21. /* The grid layout macros allow buttons to be arranged on a grid so
  22. * that their locations become independent of the display size. The
  23. * layout model is similar to that of HTML TABLEs.
  24. *
  25. * These macros are meant to be evaluated into constants at compile
  26. * time, so resolution independence can be as efficient as using
  27. * hard-coded coordinates.
  28. */
  29. // Margin defines the margin (in pixels) on each side of a button in
  30. // the layout
  31. #ifdef TOUCH_UI_800x480
  32. #define MARGIN_L 5
  33. #define MARGIN_R 5
  34. #define MARGIN_T 5
  35. #define MARGIN_B 5
  36. #define MARGIN_DEFAULT 5
  37. #else
  38. #define MARGIN_L 3
  39. #define MARGIN_R 3
  40. #define MARGIN_T 3
  41. #define MARGIN_B 3
  42. #define MARGIN_DEFAULT 3
  43. #endif
  44. // EDGE_R adds some black space on the right edge of the display
  45. // This shifts some of the screens left to visually center them.
  46. #define EDGE_R 0
  47. // GRID_X and GRID_Y computes the positions of the divisions on
  48. // the layout grid.
  49. #define GRID_X(x) ((x)*(FTDI::display_width-EDGE_R)/GRID_COLS)
  50. #define GRID_Y(y) ((y)*FTDI::display_height/GRID_ROWS)
  51. // BTN_X, BTN_Y, BTN_W and BTN_X returns the top-left and width
  52. // and height of a button, taking into account the button margins.
  53. #define BTN_X(x) (GRID_X((x)-1) + MARGIN_L)
  54. #define BTN_Y(y) (GRID_Y((y)-1) + MARGIN_T)
  55. #define BTN_W(w) (GRID_X(w) - MARGIN_L - MARGIN_R)
  56. #define BTN_H(h) (GRID_Y(h) - MARGIN_T - MARGIN_B)
  57. // Abbreviations for common phrases, to allow a button to be
  58. // defined in one line of source.
  59. #define BTN_POS(x,y) BTN_X(x), BTN_Y(y)
  60. #define BTN_SIZE(w,h) BTN_W(w), BTN_H(h)
  61. // Draw a reference grid for ease of spacing out widgets.
  62. #define DRAW_LAYOUT_GRID \
  63. { \
  64. cmd.cmd(LINE_WIDTH(4)); \
  65. for(int i = 1; i <= GRID_COLS; i++) { \
  66. cmd.cmd(BEGIN(LINES)); \
  67. cmd.cmd(VERTEX2F(GRID_X(i) *16, 0 *16)); \
  68. cmd.cmd(VERTEX2F(GRID_X(i) *16, FTDI::display_height *16)); \
  69. } \
  70. for(int i = 1; i < GRID_ROWS; i++) { \
  71. cmd.cmd(BEGIN(LINES)); \
  72. cmd.cmd(VERTEX2F(0 *16, GRID_Y(i) *16)); \
  73. cmd.cmd(VERTEX2F(FTDI::display_width *16, GRID_Y(i) *16)); \
  74. } \
  75. cmd.cmd(LINE_WIDTH(16)); \
  76. }
  77. namespace FTDI {
  78. #ifdef TOUCH_UI_PORTRAIT
  79. constexpr uint16_t display_width = Vsize;
  80. constexpr uint16_t display_height = Hsize;
  81. #else
  82. constexpr uint16_t display_width = Hsize;
  83. constexpr uint16_t display_height = Vsize;
  84. #endif
  85. }