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