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

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

style: remove trailing spaces, fix copyright statements.

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
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
[131]13#include <string.h>
14
[481]15#include "input.h"
16#include "visobj.h"
[2]17
[124]18void image_visual::draw(image *screen, int x, int y,
19            filter *f)
20{
[2]21  if (f)
22    f->put_image(screen,im,x,y,1);
23  else
[124]24    im->put_image(screen,x,y);
[2]25}
26
27
28string_visual::string_visual(char *string, int Color)
29{
[131]30    st = strdup(string);
31    color = Color;
32    w = -1;
[2]33}
34
35
[106]36int string_visual::width()
[2]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;
[494]42    for (w=fw,h=fh+1; *info; info++)
[2]43    {
44      if (w>maxw) maxw=w;
45      if (*info=='\n')
46      {
[124]47    h+=fh+1;
48    w=1;
[2]49      }
[124]50      else w+=fw;
[2]51    }
52    w=maxw;
53  }
54  return w;
55}
56
[106]57int string_visual::height()
[124]58{
[106]59  if (w==-1) width();
[2]60  return h;
61}
62
63
[124]64static void put_para(image *screen, char *st, int dx, int dy,
65             int xspace, int yspace, JCFont *font, int color)
[2]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
[106]84void string_visual::draw(image *screen, int x, int y, filter *f)
[2]85
[124]86{
[2]87  put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
[124]88       wm->font(),f ? f->get_mapping(color) : color);
[2]89}
90
Note: See TracBrowser for help on using the repository browser.