Use urandom / rtlgenrandom
[lsnes.git] / src / interface / cover.cpp
blob316c57b404d00d6506915f24a62a74c99e2b91f9
1 #include "core/moviedata.hpp"
2 #include "core/memorymanip.hpp"
3 #include "interface/cover.hpp"
4 #include "library/minmax.hpp"
5 #include "library/utf8.hpp"
6 #include "fonts/wrapper.hpp"
7 #include <iostream>
9 namespace
11 template<size_t pstride>
12 void cover_render_character(void* fb, unsigned x, unsigned y, uint32_t ch, uint32_t fg, uint32_t bg,
13 size_t w, size_t h, size_t istride)
15 unsigned char* _fg = reinterpret_cast<unsigned char*>(&fg);
16 unsigned char* _bg = reinterpret_cast<unsigned char*>(&bg);
17 if(x >= w || y >= h)
18 return;
19 const framebuffer::font::glyph& g = main_font.get_glyph(ch);
20 unsigned maxw = min((size_t)(g.wide ? 16 : 8), (size_t)(w - x));
21 unsigned maxh = min((size_t)16, (size_t)(h - y));
22 unsigned char* cellbase = reinterpret_cast<unsigned char*>(fb) + y * istride + pstride * x;
23 if(g.wide) {
24 //Wide character.
25 for(size_t y2 = 0; y2 < maxh; y2++) {
26 uint32_t d = g.data[y2 >> 1];
27 d >>= 16 - ((y2 & 1) << 4);
28 for(size_t j = 0; j < maxw; j++) {
29 uint32_t b = 15 - j;
30 if(((d >> b) & 1) != 0) {
31 for(unsigned k = 0; k < pstride; k++)
32 cellbase[pstride * j + k] = _fg[k];
33 } else {
34 for(unsigned k = 0; k < pstride; k++)
35 cellbase[pstride * j + k] = _bg[k];
38 cellbase += istride;
40 } else {
41 //Narrow character.
42 for(size_t y2 = 0; y2 < maxh; y2++) {
43 uint32_t d = g.data[y2 >> 2];
44 d >>= 24 - ((y2 & 3) << 3);
45 for(size_t j = 0; j < maxw; j++) {
46 uint32_t b = 7 - j;
47 if(((d >> b) & 1) != 0) {
48 for(unsigned k = 0; k < pstride; k++)
49 cellbase[pstride * j + k] = _fg[k];
50 } else {
51 for(unsigned k = 0; k < pstride; k++)
52 cellbase[pstride * j + k] = _bg[k];
55 cellbase += istride;
61 void cover_render_character(void* fb, unsigned x, unsigned y, uint32_t ch, uint32_t fg, uint32_t bg, size_t w,
62 size_t h, size_t istride, size_t pstride)
64 if(pstride == 2)
65 cover_render_character<2>(fb, x, y, ch, fg, bg, w, h, istride);
66 if(pstride == 3)
67 cover_render_character<3>(fb, x, y, ch, fg, bg, w, h, istride);
68 if(pstride == 4)
69 cover_render_character<4>(fb, x, y, ch, fg, bg, w, h, istride);
72 void cover_render_string(void* fb, unsigned x, unsigned y, const std::string& str, uint32_t fg, uint32_t bg,
73 size_t w, size_t h, size_t istride, size_t pstride)
75 utf8::to32i(str.begin(), str.end(), lambda_output_iterator<int32_t>([fb, &x, &y, fg, bg, w, h, istride,
76 pstride](int32_t u) {
77 if(u != 9 && u != 10)
78 cover_render_character(fb, x, y, u, fg, bg, w, h, istride, pstride);
79 cover_next_position(u, x, y);
80 }));
83 void cover_next_position(uint32_t ch, unsigned& x, unsigned& y)
85 if(ch == 9)
86 x = (x + 63) >> 6 << 6;
87 else if(ch == 10) {
88 x = 0;
89 y = y + 16;
90 } else {
91 const framebuffer::font::glyph& g = main_font.get_glyph(ch);
92 x = x + (g.wide ? 16 : 8);
96 void cover_next_position(const std::string& str, unsigned& x, unsigned& y)
98 utf8::to32i(str.begin(), str.end(), lambda_output_iterator<int32_t>([&x, &y](int32_t u) {
99 cover_next_position(u, x, y);
100 }));
103 std::vector<std::string> cover_information()
105 std::vector<std::string> ret;
106 ret.push_back("System: " + our_rom.rtype->get_hname() + " (" + our_rom.region->get_hname() + ")");
107 return ret;