SDL_easy.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * I wrote this header to be as portable as possible for other homebrew switch projects
  3. * The only thing that needs to be changed will be the name / number of textures you want to load
  4. * If you decide to use this header and add functions, please consider opening a pr for said functions
  5. * I would greatly appreaciate it :)
  6. *
  7. * TotalJustice.
  8. */
  9. #pragma once
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #include <SDL2/SDL.h>
  13. #include <SDL2/SDL_ttf.h>
  14. #define SCREEN_W 1280 //width of the window
  15. #define SCREEN_H 720 //hight of the window
  16. #define COLOUR_MAX 50
  17. #define DEFAULT_FPS 60
  18. #define TICKS_PER_FRAME (1000 / DEFAULT_FPS)
  19. typedef enum
  20. {
  21. Colour_White,
  22. Colour_Grey,
  23. Colour_DarkGrey,
  24. Colour_Black,
  25. Colour_Pink,
  26. Colour_NeonPink,
  27. Colour_HotPink,
  28. Colour_Orange,
  29. Colour_Yellow,
  30. Colour_Gold,
  31. Colour_Brown,
  32. Colour_Red,
  33. Colour_DarkRed,
  34. Colour_Green,
  35. Colour_LimeGreen,
  36. Colour_Aqua,
  37. Colour_Teal,
  38. Colour_LightBlue,
  39. Colour_Blue,
  40. Colour_JordyBlue,
  41. Colour_FaintBlue,
  42. Colour_DarkBlue,
  43. Colour_Purple,
  44. Colour_Indigo,
  45. Colour_Beige,
  46. Colour_Nintendo_Black,
  47. Colour_Nintendo_LightBlack,
  48. Colour_Nintendo_LightSilver,
  49. Colour_Nintendo_Silver,
  50. Colour_Nintendo_BrightSilver,
  51. Colour_Nintendo_DarkGrey,
  52. Colour_Nintendo_Grey,
  53. Colour_Nintendo_White,
  54. Colour_Nintendo_Cyan,
  55. Colour_Nintendo_Teal,
  56. Colour_Nintendo_Blue,
  57. Colour_Nintendo_LightBlue,
  58. Colour_Nintendo_Yellow,
  59. Colour_Nintendo_Red,
  60. Colour_Glacia_Red,
  61. Colour_Glacia_Blue,
  62. Colour_Glacia_Purple,
  63. Colour_Tomi_Red,
  64. Colour_Law_Blue,
  65. Colour_Law_Red,
  66. Colour_Law_Green,
  67. Colour_Law_DarkGreen,
  68. Colour_Law_Purple,
  69. Colour_Law_Fuchsia,
  70. Colour_Law_Orange,
  71. } Colour;
  72. typedef enum
  73. {
  74. Font_Button_POWER = 0xE0B8,
  75. Font_Button_A = 0xE0E0,
  76. Font_Button_B = 0xE0E1,
  77. Font_Button_X = 0xE0E2,
  78. Font_Button_Y = 0xE0E3,
  79. Font_Button_L = 0xE0E4,
  80. Font_Button_R = 0xE0E5,
  81. Font_Button_ZL = 0xE0E6,
  82. Font_Button_ZR = 0xE0E7,
  83. Font_Button_SL = 0xE0E8,
  84. Font_Button_SR = 0xE0E9,
  85. Font_Button_UP = 0xE0EB,
  86. Font_Button_DOWN = 0xE0EC,
  87. Font_Button_LEFT = 0xE0ED,
  88. Font_Button_RIGHT = 0xE0EE,
  89. Font_Button_PLUS = 0xE0EF,
  90. Font_Button_MINUS = 0xE0F0,
  91. Font_Button_HOME = 0xE0F4,
  92. Font_Button_SCREENSHOT = 0xE0F5,
  93. Font_Button_LS = 0xE101,
  94. Font_Button_RS = 0xE102,
  95. Font_Button_L3 = 0xE104,
  96. Font_Button_R3 = 0xE105,
  97. Font_Button_SWITCH = 0xE121,
  98. font_Button_DUALCONS = 0xE122,
  99. Font_Button_SETTINGS = 0xE130,
  100. Font_Button_NEWS = 0xE132,
  101. Font_Button_ESHOP = 0xE133,
  102. Font_Button_ALBUM = 0xE134,
  103. Font_Button_ALLAPPS = 0xE135,
  104. Font_Button_CONTROLLER = 0xE136,
  105. } Font; // buttons from NintendoExt
  106. typedef uint32_t Window_Flags;
  107. typedef uint32_t Renderer_Flags;
  108. SDL_Colour SDL_GetColour(Colour colour_option); //pass the name of colour, returns the colour
  109. SDL_Window* SDL_GetWindow(void); //get sdl window
  110. SDL_Texture *SDL_ImageLoad(const char *path); //load image from texture
  111. SDL_Texture *SDL_ImageLoadMem(void *data, int size); //load image from memory
  112. void SDL_DrawText(TTF_Font *font, int x, int y, Colour colour, const char *text, ...); //draw text to screen
  113. void SDL_DrawTextCenterX(TTF_Font *font, int y, int clip_x, int clip_w, Colour colour, const char *text, ...);
  114. void SDL_DrawButton(TTF_Font *font, uint16_t btn, int x, int y, Colour colour); //draw button to screen
  115. void SDL_DrawImage(SDL_Texture *texture, int x, int y); //draw image to screen from texture
  116. void SDL_DrawImageRotate(SDL_Texture *texture, int x, int y, double rotate);
  117. void SDL_DrawImageScale(SDL_Texture *texture, int x, int y, int w, int h); //scale the image drawn to screen
  118. void SDL_DrawShape(Colour colour, int x, int y, int w, int h, bool filled); //draw shap (rect)
  119. void SDL_DrawShapeEX(uint8_t r, uint8_t g, uint8_t b, uint8_t a, int x, int y, int w, int h, bool filled);
  120. void SDL_DrawShapeOutline(Colour colour, int x, int y, int w, int h, int thicc);
  121. void SDL_DrawShapeOutlineEX(uint8_t r, uint8_t g, uint8_t b, uint8_t a, int x, int y, int w, int h, int thicc);
  122. void SDL_DrawShapeRounded(Colour colour, int x, int y, int w, int h, int r);
  123. void SDL_DrawShapeRoundedOutline(Colour colour, int x, int y, int w, int h, int r);
  124. void SDL_DrawCircle(Colour colour, int x, int y, int r);
  125. void SDL_DrawCircleOutline(Colour colour, int x, int y, int r);
  126. void SDL_SurfaceToFile(SDL_Surface *surface, const char *path, bool to_free);
  127. SDL_Texture *SDL_ScreenShotToTexture(void);
  128. void SDL_ScreenShotToFile(const char *save_path);
  129. int SDL_GetTextureWidth(SDL_Texture *texture);
  130. int SDL_GetTextureHeight(SDL_Texture *texture);
  131. void SDL_GetTextSize(TTF_Font *font, int *w, int *h, const char *text, ...);
  132. void SDL_SetTextureColour(SDL_Texture *texture, Colour colour);
  133. void SDL_ClearRenderer(void); //clear the screen
  134. void SDL_UpdateRenderer(void); //update the screen
  135. void SDL_EasyInit(Window_Flags w_flags, Renderer_Flags r_flags); //init all sdl stuff
  136. void SDL_EasyExit(void); //clean and exit