Replace region with full system
[lsnes.git] / src / interface / cover.cpp
blob71a43f8fa71b5396667825887380cd9d25c42335
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 bitmap_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 size_t spos = 0;
76 size_t slen = str.length();
77 uint16_t state = utf8_initial_state;
78 while(true) {
79 int ch = (spos < slen) ? (unsigned char)str[spos] : - 1;
80 int32_t u = utf8_parse_byte(ch, state);
81 if(u < 0) {
82 if(ch < 0)
83 break;
84 spos++;
85 continue;
87 if(u != 9 && u != 10)
88 cover_render_character(fb, x, y, u, fg, bg, w, h, istride, pstride);
89 cover_next_position(u, x, y);
90 spos++;
94 void cover_next_position(uint32_t ch, unsigned& x, unsigned& y)
96 unsigned ox = x;
97 unsigned oy = y;
98 if(ch == 9)
99 x = (x + 63) >> 6 << 6;
100 else if(ch == 10) {
101 x = 0;
102 y = y + 16;
103 } else {
104 const bitmap_font::glyph& g = main_font.get_glyph(ch);
105 x = x + (g.wide ? 16 : 8);
109 void cover_next_position(const std::string& str, unsigned& x, unsigned& y)
111 size_t spos = 0;
112 size_t slen = str.length();
113 uint16_t state = utf8_initial_state;
114 while(true) {
115 int ch = (spos < slen) ? (unsigned char)str[spos] : - 1;
116 int32_t u = utf8_parse_byte(ch, state);
117 if(u < 0) {
118 if(ch < 0)
119 break;
120 spos++;
121 continue;
123 cover_next_position(u, x, y);
124 spos++;
128 std::vector<std::string> cover_information()
130 std::vector<std::string> ret;
131 ret.push_back("System: " + our_rom->rtype->get_hname() + " (" + our_rom->region->get_hname() + ")");
132 return ret;