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

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