]> git.vomp.tv Git - vompclient-marten.git/blob - surface.cc
*** empty log message ***
[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 #include "osd.h"
23
24 Surface* Surface::screen = NULL;
25 osd_font_t* Surface::font = &font_helvB18;
26
27 Surface::Surface(int id)
28 {
29   if (id == SCREEN) screen = this;
30 }
31
32 Surface::~Surface()
33 {
34 }
35
36 Surface* Surface::getScreen()
37 {
38   return screen;
39 }
40
41 int Surface::drawText(char* text, int x, int y, ULONG rgba)
42 {
43   int h, n, i;
44   int Y, X, cx;
45
46   n = strlen(text);
47   h = font->height;
48
49   X = 0;
50   cx = 0;
51   for (i=0; i<n; i++)
52   {
53     unsigned char c = text[i];
54     unsigned long *character = &font->content[font->offset[c]];
55     int w = font->width[c];
56     int pixels = 0;
57
58     for (X=0; X<w; X++)
59     {
60       for (Y=0; Y<h; Y++)
61       {
62         if ((character[Y] >> (32 - X)) & 0x1)
63         {
64           drawPixel(x+X+cx, y+Y, rgba);
65           pixels++;
66         }
67       }
68     }
69     cx += w;
70   }
71   return 1;
72 }
73
74 int Surface::drawTextRJ(char* text, int x, int y, ULONG rgba)
75 {
76   int i, n, w;
77   w = 0;
78
79   n = strlen(text);
80
81   for (i = 0; i < n; i++)
82   {
83     w += font->width[text[i]];
84   }
85
86   x -= w;
87
88   if (x < 0) return 0;
89   else return drawText(text, x, y, rgba);
90 }
91
92 int Surface::drawTextCentre(char* text, int x, int y, ULONG rgba)
93 {
94   int i, n, w;
95   w = 0;
96
97   n = strlen(text);
98
99   for (i = 0; i < n; i++)
100   {
101     w += font->width[text[i]];
102   }
103
104   x -= w / 2;
105
106   if (x < 0) return 0;
107   else return drawText(text, x, y, rgba);
108 }
109
110 int Surface::getCharWidth(char c)
111 {
112   return font->width[(unsigned char) c];
113 }
114
115 int Surface::getFontHeight()
116 {
117   return font->spacing;
118 }