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
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]5 *
6 *  This software was released into the Public Domain. As with most public
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[555]11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
[56]14
[131]15#include <string.h>
16
[481]17#include "input.h"
18#include "visobj.h"
[2]19
[124]20void image_visual::draw(image *screen, int x, int y,
21            filter *f)
22{
[2]23  if (f)
24    f->put_image(screen,im,x,y,1);
25  else
[124]26    im->put_image(screen,x,y);
[2]27}
28
29
30string_visual::string_visual(char *string, int Color)
31{
[131]32    st = strdup(string);
33    color = Color;
34    w = -1;
[2]35}
36
37
[106]38int string_visual::width()
[2]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;
[494]44    for (w=fw,h=fh+1; *info; info++)
[2]45    {
46      if (w>maxw) maxw=w;
47      if (*info=='\n')
48      {
[124]49    h+=fh+1;
50    w=1;
[2]51      }
[124]52      else w+=fw;
[2]53    }
54    w=maxw;
55  }
56  return w;
57}
58
[106]59int string_visual::height()
[124]60{
[106]61  if (w==-1) width();
[2]62  return h;
63}
64
65
[124]66static void put_para(image *screen, char *st, int dx, int dy,
67             int xspace, int yspace, JCFont *font, int color)
[2]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
[106]86void string_visual::draw(image *screen, int x, int y, filter *f)
[2]87
[124]88{
[2]89  put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
[124]90       wm->font(),f ? f->get_mapping(color) : color);
[2]91}
92
Note: See TracBrowser for help on using the repository browser.