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

Last change on this file since 56 was 56, checked in by Sam Hocevar, 11 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 1.6 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 "visobj.hpp"
13
14void image_visual::draw(image *screen, int x, int y,
15                    window_manager *wm, filter *f)
16{
17  if (f)
18    f->put_image(screen,im,x,y,1);
19  else
20    im->put_image(screen,x,y);
21}
22
23
24string_visual::string_visual(char *string, int Color)
25{
26  st=strcpy((char *)jmalloc(strlen(string)+1,"string visual"),string);
27  color=Color;
28  w=-1;
29}
30
31
32int string_visual::width(window_manager *wm)
33{
34  if (w==-1)  // not calculated yet
35  {
36    int fw=wm->font()->width(),fh=wm->font()->height(),maxw=0;
37    char *info=st;
38    for (w=fw,h=fh+1;*info;info++)
39    {
40      if (w>maxw) maxw=w;
41      if (*info=='\n')
42      {
43        h+=fh+1;
44        w=1;
45      }
46      else w+=fw;     
47    }
48    w=maxw;
49  }
50  return w;
51}
52
53int string_visual::height(window_manager *wm)
54{
55  if (w==-1) width(wm);
56  return h;
57}
58
59
60static void put_para(image *screen, char *st, int dx, int dy,
61                     int xspace, int yspace, JCFont *font, int color)
62{
63  int ox=dx;
64  while (*st)
65  {
66    if (*st=='\n')
67    {
68      dx=ox;
69      dy+=yspace;
70    }
71    else
72    {
73      font->put_char(screen,dx,dy,*st,color);
74      dx+=xspace;
75    }
76    st++;
77  }
78}
79
80void string_visual::draw(image *screen, int x, int y,
81                    window_manager *wm, filter *f)
82
83{
84  put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
85           wm->font(),f ? f->get_mapping(color) : color);
86}
87
Note: See TracBrowser for help on using the repository browser.