]> git.vomp.tv Git - vompclient-marten.git/blob - surface.cc
Teletext
[vompclient-marten.git] / surface.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "surface.h"
22
23 #include "osd.h"
24 #include "log.h"
25
26 Surface* Surface::screen = NULL;
27 osd_font_t* Surface::font = &font_helvB18;
28
29 Surface::Surface(int id)
30 {
31   if (id == SCREEN) screen = this;
32 }
33
34 Surface::~Surface()
35 {
36 }
37
38 Surface* Surface::getScreen()
39 {
40   return screen;
41 }
42
43 int Surface::drawText(const char* text, int x, int y, ULONG rgba)
44 {
45   return drawText(text, x, y, 2000, rgba);
46 }
47
48 int Surface::drawText(const char* text, int x, int y, int width, ULONG rgba)
49 {
50   int h, n, i;
51   int Y, X, cx;
52
53   n = strlen(text);
54   h = font->height;
55
56   X = 0;
57   cx = 0;
58   startFastDraw();
59   for (i=0; i<n; i++)
60   {
61     unsigned char c = text[i];
62     unsigned long *character = &font->content[font->offset[c]];
63     int w = font->width[c];
64     int pixels = 0;
65
66     for (X=0; (X<w) && (X + cx < width); X++)
67     {
68       for (Y=0; Y<h; Y++)
69       {
70         if ((character[Y] >> (32 - X)) & 0x1)
71         {
72           drawPixel(x+X+cx, y+Y, rgba,true);
73           pixels++;
74         }
75       }
76     }
77     cx += w;
78   }
79   endFastDraw();
80   return 1;
81 }
82
83 int Surface::drawTextRJ(const char* text, int x, int y, ULONG rgba)
84 {
85   int i, n, w;
86   w = 0;
87
88   n = strlen(text);
89
90   for (i = 0; i < n; i++)
91   {
92     w += font->width[text[i]];
93   }
94
95   x -= w;
96
97   if (x < 0) return 0;
98   else return drawText(text, x, y, rgba);
99 }
100
101 int Surface::drawTextCentre(const char* text, int x, int y, ULONG rgba)
102 {
103   int i, n, w;
104   w = 0;
105
106   n = strlen(text);
107
108   for (i = 0; i < n; i++)
109   {
110     w += font->width[text[i]];
111   }
112
113   x -= w / 2;
114
115   if (x < 0) return 0;
116   else return drawText(text, x, y, rgba);
117 }
118
119 int Surface::getCharWidth(char c)
120 {
121   return font->width[(unsigned char) c];
122 }
123
124 int Surface::getFontHeight()
125 {
126   return font->spacing;
127 }