Common.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2018 shchmue
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <string>
  18. #include <vector>
  19. #include <ft2build.h>
  20. #include FT_FREETYPE_H
  21. #include <switch/types.h>
  22. #define FB_WIDTH 1280
  23. #define FB_HEIGHT 720
  24. #define GREEN RGBA8_MAXALPHA(0, 0xff, 0)
  25. #define RED RGBA8_MAXALPHA(0xff, 0, 0)
  26. #define CYAN RGBA8_MAXALPHA(0, 0xff, 0xff)
  27. #define YELLOW RGBA8_MAXALPHA(0xff, 0xff, 0)
  28. #define FLAG_RED RGBA8_MAXALPHA(0xe7, 0x00, 0x00)
  29. #define FLAG_ORANGE RGBA8_MAXALPHA(0xff, 0x8c, 0x00)
  30. #define FLAG_YELLOW RGBA8_MAXALPHA(0xff, 0xef, 0x00)
  31. #define FLAG_GREEN RGBA8_MAXALPHA(0x00, 0x81, 0x1f)
  32. #define FLAG_BLUE RGBA8_MAXALPHA(0x00, 0x44, 0xff)
  33. #define FLAG_VIOLET RGBA8_MAXALPHA(0x76, 0x00, 0x89)
  34. class Key;
  35. typedef std::vector<u8> byte_vector;
  36. namespace Common {
  37. // draw letter, called by draw_text
  38. void draw_glyph(FT_Bitmap *bitmap, u32 x, u32 y, u32 color);
  39. // draw horizontal line
  40. void draw_line(u32 x, u32 y, u32 length, u32 color);
  41. // draw filled rectangle
  42. void draw_set_rect(u32 x, u32 y, u32 width, u32 height, u32 color);
  43. // draw string
  44. void draw_text(u32 x, u32 y, u32 color, const char *str);
  45. // draw string and time elapsed
  46. void draw_text_with_time(u32 x, u32 y, u32 color, const char *str, const float time);
  47. // overload for microseconds
  48. void draw_text_with_time(u32 x, u32 y, u32 color, const char *str, const int64_t time);
  49. // init font and draw interface
  50. void intro();
  51. // get tegra keys from payload dump
  52. void get_tegra_keys(Key &sbk, Key &tsec, Key &tsec_root);
  53. // print exit
  54. void wait_to_exit();
  55. // refresh display
  56. void update_display();
  57. // reads "<keyname> = <hexkey>" and returns byte vector
  58. byte_vector key_string_to_byte_vector(std::string key_string);
  59. }