]> git.vomp.tv Git - vompclient-marten.git/blob - surface.cc
Patch from Philipp Mueller for long drawText lines
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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   for (i=0; i<n; i++)
59   {
60     unsigned char c = text[i];
61     unsigned long *character = &font->content[font->offset[c]];
62     int w = font->width[c];
63     int pixels = 0;
64
65     for (X=0; (X<w) && (X + cx < width); X++)
66     {
67       for (Y=0; Y<h; Y++)
68       {
69         if ((character[Y] >> (32 - X)) & 0x1)
70         {
71           drawPixel(x+X+cx, y+Y, rgba);
72           pixels++;
73         }
74       }
75     }
76     cx += w;
77   }
78   return 1;
79 }
80
81 int Surface::drawTextRJ(const char* text, int x, int y, ULONG rgba)
82 {
83   int i, n, w;
84   w = 0;
85
86   n = strlen(text);
87
88   for (i = 0; i < n; i++)
89   {
90     w += font->width[text[i]];
91   }
92
93   x -= w;
94
95   if (x < 0) return 0;
96   else return drawText(text, x, y, rgba);
97 }
98
99 int Surface::drawTextCentre(const char* text, int x, int y, ULONG rgba)
100 {
101   int i, n, w;
102   w = 0;
103
104   n = strlen(text);
105
106   for (i = 0; i < n; i++)
107   {
108     w += font->width[text[i]];
109   }
110
111   x -= w / 2;
112
113   if (x < 0) return 0;
114   else return drawText(text, x, y, rgba);
115 }
116
117 int Surface::getCharWidth(char c)
118 {
119   return font->width[(unsigned char) c];
120 }
121
122 int Surface::getFontHeight()
123 {
124   return font->spacing;
125 }