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

Last change on this file since 106 was 106, checked in by Sam Hocevar, 15 years ago
  • Rename the "eh" variable to "wm" because it's a window manager, not an event handler.
  • No longer pass the window manager to functions, there's only one.

Inspired by Win32 Abuse changelog for January 28, 2001:

  • Starting work on singleton code; will get rid of all

references to an arbitrary window_manager* because
there's only going to be one, and it's not ever
going to change.

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