~silwol/freenukum/trunk

« back to all changes in this revision

Viewing changes to src/fn_text.c

  • Committer: Wolfgang Silbermayr
  • Date: 2009-02-20 13:23:01 UTC
  • Revision ID: wolfgang@silbermayr.at-20090220132301-ordzjbq0cdehm88p
Replaced some more SDL_Surface occurrences by FnTexture's

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 *
27
27
 *******************************************************************/
28
28
 
29
 
#include <SDL.h>
30
29
#include <string.h>
31
30
 
32
31
/* --------------------------------------------------------------- */
34
33
#include "fn_text.h"
35
34
#include "fn_tilecache.h"
36
35
#include "fn_object.h"
 
36
#include "fntexture.h"
37
37
 
38
38
/* --------------------------------------------------------------- */
39
39
 
40
40
void fn_text_printletter(
41
 
    SDL_Surface * target,
42
 
    SDL_Rect * r,
 
41
    FnTexture * target,
 
42
    FnGeometry * r,
43
43
    fn_environment_t * env,
44
44
    char c)
45
45
{
49
49
    tilenr = c - ' ' + FONT_ASCII_UPPERCASE;
50
50
  else
51
51
    tilenr = c - 'a' + FONT_ASCII_LOWERCASE;
52
 
  fn_texture_blit_to_sdl_surface(
 
52
  fn_texture_clone_to_texture(
53
53
      fn_environment_get_tile(env, tilenr),
54
54
      NULL,
55
55
      target,
59
59
/* --------------------------------------------------------------- */
60
60
 
61
61
void fn_text_print(
62
 
    SDL_Surface * target,
63
 
    SDL_Rect * r,
 
62
    FnTexture * target,
 
63
    FnGeometry * r,
64
64
    fn_environment_t * env,
65
65
    char * text)
66
66
{
67
 
  SDL_Rect dstrect;
 
67
  FnGeometry * dstrect;
68
68
 
69
69
  char * walker;
70
70
  char * end;
71
71
 
72
 
  if (r != NULL)
73
 
    memcpy(&dstrect, r, sizeof(SDL_Rect));
74
 
  else {
75
 
    dstrect.x = 0;
76
 
    dstrect.y = 0;
 
72
  if (r != NULL) {
 
73
    dstrect = fn_geometry_clone(r);
 
74
  } else {
 
75
    dstrect = fn_geometry_new(0, 0, 0, 0);
77
76
  }
78
77
  Uint8 pixelsize = fn_environment_get_pixelsize(env);
79
 
  dstrect.w = pixelsize * FN_FONT_WIDTH;
80
 
  dstrect.h = pixelsize * FN_FONT_HEIGHT;
 
78
 
 
79
  fn_geometry_set_width(dstrect, pixelsize * FN_FONT_WIDTH);
 
80
  fn_geometry_set_height(dstrect, pixelsize * FN_FONT_HEIGHT);
81
81
 
82
82
  end = text + strlen(text);
83
83
 
84
84
  for (walker = text; walker < end; walker++) {
85
85
    if (*walker == '\n') {
86
 
      dstrect.x = r->x;
87
 
      dstrect.y += pixelsize * FN_FONT_HEIGHT;
 
86
      fn_geometry_set_x(dstrect, fn_geometry_get_x(r));
 
87
      gint y = fn_geometry_get_y(dstrect);
 
88
      fn_geometry_set_y(dstrect, y + pixelsize * FN_FONT_HEIGHT);
88
89
    } else {
89
 
      fn_text_printletter(target,
90
 
          &dstrect,
 
90
      fn_text_printletter(
 
91
          target,
 
92
          dstrect,
91
93
          env,
92
94
          *walker);
93
 
      dstrect.x += pixelsize * FN_FONT_WIDTH;
 
95
      gint x = fn_geometry_get_x(dstrect);
 
96
      fn_geometry_set_x(dstrect, x + pixelsize * FN_FONT_WIDTH);
94
97
    }
95
98
  }
 
99
  g_object_unref(dstrect);
96
100
}
97
101
 
98
102
/* --------------------------------------------------------------- */