~ubuntu-branches/ubuntu/utopic/lebiniou/utopic

« back to all changes in this revision

Viewing changes to plugins/stable/output/SDL/ttf.c

  • Committer: Package Import Robot
  • Author(s): Olivier Girondel
  • Date: 2012-04-22 22:07:40 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120422220740-xncgwhc3g71nopnu
Tags: 3.18-1
* New upstream release 3.18.
* Support older libswscale.
* Add missing Build-Depends: libfreetype6-dev, libasound2-dev,
  libpulse-dev. (Closes: #669437)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright 1994-2012 Olivier Girondel
 
3
 *
 
4
 *  This file is part of lebiniou.
 
5
 *
 
6
 *  lebiniou 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
 *  lebiniou 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 lebiniou. If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "ttf.h"
 
21
#include "SDL.h"
 
22
 
 
23
static SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
 
24
static SDL_Color black = { 0, 0, 0, 0 };
 
25
static SDL_Color red   = { 0xFF, 0, 0, 0 };
 
26
 
 
27
static TTF_Font *font = NULL;
 
28
u_short fontlineskip;
 
29
extern char enabled;
 
30
 
 
31
#ifndef FIXED
 
32
extern u_short out_width, out_height;
 
33
#else
 
34
#define out_width  WIDTH
 
35
#define out_height HEIGHT
 
36
#endif
 
37
 
 
38
 
 
39
void
 
40
ttf_init()
 
41
{
 
42
  /* Initialize the TTF library */
 
43
  if (!TTF_WasInit())
 
44
    if (TTF_Init() < 0)
 
45
      xerror("Couldn't initialize TTF: %s\n", SDL_GetError());
 
46
        
 
47
  /* Open the font file with the requested point size */
 
48
  font = TTF_OpenFont(OSD_FONT, OSD_PTSIZE);
 
49
  if (font == NULL) {
 
50
    printf("[!] %s, OSD is disabled.\n", SDL_GetError());
 
51
    enabled = 0;
 
52
  } else {
 
53
    TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
 
54
    /* TTF_SetFontStyle(font, TTF_STYLE_BOLD); */
 
55
  }
 
56
 
 
57
  fontlineskip = TTF_FontLineSkip(font);
 
58
}
 
59
 
 
60
 
 
61
void
 
62
ttf_quit()
 
63
{
 
64
  if (NULL != font)
 
65
    TTF_CloseFont(font);
 
66
  TTF_Quit();
 
67
}
 
68
 
 
69
 
 
70
u_short
 
71
osd_print(const u_short x, u_short y,
 
72
          const u_char rev_x, const u_char rev_y,
 
73
          const u_char mode, const int disabled, const char *fmt, ...)
 
74
{
 
75
  char str[OSD_BUFFLEN+1];
 
76
  va_list ap;
 
77
  SDL_Surface *text = NULL;
 
78
  SDL_Rect    dstrect;
 
79
  SDL_Color   fg_color;
 
80
 
 
81
  memset((void *)str, '\0', OSD_BUFFLEN*sizeof(char));
 
82
  assert(fmt != NULL);
 
83
  va_start(ap, fmt);
 
84
  vsprintf(str, fmt, ap); /* TODO vsnprintf */
 
85
  va_end(ap);
 
86
 
 
87
  fg_color = (disabled) ? red : white;
 
88
 
 
89
  text = ((mode == 1) || (mode == 2)) ? TTF_RenderText_Blended(font, str, black)
 
90
    : TTF_RenderText_Shaded(font, str, fg_color, black);
 
91
 
 
92
  if (text != NULL) {
 
93
    if (mode == 3) {
 
94
      dstrect.x = (rev_x) ? (out_width - x - text->w) : x;
 
95
      dstrect.y = (rev_y) ? (out_height - y - text->h) : y;
 
96
      dstrect.w = text->w;
 
97
      dstrect.h = text->h;
 
98
      SDL_BlitSurface(text, NULL, drv.sc, &dstrect);
 
99
      SDL_FreeSurface(text);
 
100
    } else {
 
101
      int dx, dy;
 
102
      
 
103
      dstrect.w = text->w;
 
104
      dstrect.h = text->h;
 
105
      for (dx = -2; dx <= 2; dx ++) {
 
106
        for (dy = -2; dy <= 2; dy ++) {
 
107
          dstrect.x = (rev_x) ? (out_width - x - text->w) : x;
 
108
          dstrect.y = (rev_y) ? (out_height - y - text->h) : y;
 
109
          dstrect.x += dx;
 
110
          dstrect.y += dy;
 
111
          SDL_BlitSurface(text, NULL, drv.sc, &dstrect);
 
112
        }
 
113
      }
 
114
      SDL_FreeSurface(text);
 
115
 
 
116
      text = TTF_RenderText_Blended(font, str, fg_color);
 
117
      dstrect.x = (rev_x) ? (out_width - x - text->w) : x;
 
118
      dstrect.y = (rev_y) ? (out_height - y - text->h) : y;
 
119
      SDL_BlitSurface(text, NULL, drv.sc, &dstrect);
 
120
      SDL_FreeSurface(text);
 
121
    }
 
122
    y += TTF_FontLineSkip(font) - 1; /* FIXME why -1 ?? --oliv3 */
 
123
  }
 
124
 
 
125
  return y;
 
126
}