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

Last change on this file since 521 was 494, checked in by Sam Hocevar, 12 years ago

style: remove trailing spaces, fix copyright statements.

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 or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include <string.h>
14
15#include "input.h"
16#include "visobj.h"
17
18void image_visual::draw(image *screen, int x, int y,
19            filter *f)
20{
21  if (f)
22    f->put_image(screen,im,x,y,1);
23  else
24    im->put_image(screen,x,y);
25}
26
27
28string_visual::string_visual(char *string, int Color)
29{
30    st = strdup(string);
31    color = Color;
32    w = -1;
33}
34
35
36int string_visual::width()
37{
38  if (w==-1)  // not calculated yet
39  {
40    int fw=wm->font()->width(),fh=wm->font()->height(),maxw=0;
41    char *info=st;
42    for (w=fw,h=fh+1; *info; info++)
43    {
44      if (w>maxw) maxw=w;
45      if (*info=='\n')
46      {
47    h+=fh+1;
48    w=1;
49      }
50      else w+=fw;
51    }
52    w=maxw;
53  }
54  return w;
55}
56
57int string_visual::height()
58{
59  if (w==-1) width();
60  return h;
61}
62
63
64static void put_para(image *screen, char *st, int dx, int dy,
65             int xspace, int yspace, JCFont *font, int color)
66{
67  int ox=dx;
68  while (*st)
69  {
70    if (*st=='\n')
71    {
72      dx=ox;
73      dy+=yspace;
74    }
75    else
76    {
77      font->put_char(screen,dx,dy,*st,color);
78      dx+=xspace;
79    }
80    st++;
81  }
82}
83
84void string_visual::draw(image *screen, int x, int y, filter *f)
85
86{
87  put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
88       wm->font(),f ? f->get_mapping(color) : color);
89}
90
Note: See TracBrowser for help on using the repository browser.