source: abuse/trunk/src/imlib/visobj.cpp @ 555

Last change on this file since 555 was 555, checked in by Sam Hocevar, 11 years ago

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

File size: 1.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <string.h>
16
17#include "input.h"
18#include "visobj.h"
19
20void image_visual::draw(image *screen, int x, int y,
21            filter *f)
22{
23  if (f)
24    f->put_image(screen,im,x,y,1);
25  else
26    im->put_image(screen,x,y);
27}
28
29
30string_visual::string_visual(char *string, int Color)
31{
32    st = strdup(string);
33    color = Color;
34    w = -1;
35}
36
37
38int string_visual::width()
39{
40  if (w==-1)  // not calculated yet
41  {
42    int fw=wm->font()->width(),fh=wm->font()->height(),maxw=0;
43    char *info=st;
44    for (w=fw,h=fh+1; *info; info++)
45    {
46      if (w>maxw) maxw=w;
47      if (*info=='\n')
48      {
49    h+=fh+1;
50    w=1;
51      }
52      else w+=fw;
53    }
54    w=maxw;
55  }
56  return w;
57}
58
59int string_visual::height()
60{
61  if (w==-1) width();
62  return h;
63}
64
65
66static void put_para(image *screen, char *st, int dx, int dy,
67             int xspace, int yspace, JCFont *font, int color)
68{
69  int ox=dx;
70  while (*st)
71  {
72    if (*st=='\n')
73    {
74      dx=ox;
75      dy+=yspace;
76    }
77    else
78    {
79      font->put_char(screen,dx,dy,*st,color);
80      dx+=xspace;
81    }
82    st++;
83  }
84}
85
86void string_visual::draw(image *screen, int x, int y, filter *f)
87
88{
89  put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
90       wm->font(),f ? f->get_mapping(color) : color);
91}
92
Note: See TracBrowser for help on using the repository browser.