]> git.vomp.tv Git - vompclient.git/blob - surface.cc
Add -s option to select server
[vompclient.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   int h, n, i;
46   int Y, X, cx;
47
48   n = strlen(text);
49   h = font->height;
50
51   X = 0;
52   cx = 0;
53   for (i=0; i<n; i++)
54   {
55     unsigned char c = text[i];
56     unsigned long *character = &font->content[font->offset[c]];
57     int w = font->width[c];
58     int pixels = 0;
59
60     for (X=0; X<w; X++)
61     {
62       for (Y=0; Y<h; Y++)
63       {
64         if ((character[Y] >> (32 - X)) & 0x1)
65         {
66           drawPixel(x+X+cx, y+Y, rgba);
67           pixels++;
68         }
69       }
70     }
71     cx += w;
72   }
73   return 1;
74 }
75
76 int Surface::drawTextRJ(const char* text, int x, int y, ULONG rgba)
77 {
78   int i, n, w;
79   w = 0;
80
81   n = strlen(text);
82
83   for (i = 0; i < n; i++)
84   {
85     w += font->width[text[i]];
86   }
87
88   x -= w;
89
90   if (x < 0) return 0;
91   else return drawText(text, x, y, rgba);
92 }
93
94 int Surface::drawTextCentre(const char* text, int x, int y, ULONG rgba)
95 {
96   int i, n, w;
97   w = 0;
98
99   n = strlen(text);
100
101   for (i = 0; i < n; i++)
102   {
103     w += font->width[text[i]];
104   }
105
106   x -= w / 2;
107
108   if (x < 0) return 0;
109   else return drawText(text, x, y, rgba);
110 }
111
112 int Surface::getCharWidth(char c)
113 {
114   return font->width[(unsigned char) c];
115 }
116
117 int Surface::getFontHeight()
118 {
119   return font->spacing;
120 }