source: abuse/tags/pd/macabuse/imlib/visobj.c @ 161

Last change on this file since 161 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.3 KB
RevLine 
[49]1#include "visobj.hpp"
2
3void image_visual::draw(image *screen, int x, int y,
4                    window_manager *wm, filter *f)
5{
6  if (f)
7    f->put_image(screen,im,x,y,1);
8  else
9    im->put_image(screen,x,y);
10}
11
12
13string_visual::string_visual(char *string, int Color)
14{
15  st=strcpy((char *)jmalloc(strlen(string)+1,"string visual"),string);
16  color=Color;
17  w=-1;
18}
19
20
21int string_visual::width(window_manager *wm)
22{
23  if (w==-1)  // not calculated yet
24  {
25    int fw=wm->font()->width(),fh=wm->font()->height(),maxw=0;
26    char *info=st;
27    for (w=fw,h=fh+1;*info;info++)
28    {
29      if (w>maxw) maxw=w;
30      if (*info=='\n')
31      {
32        h+=fh+1;
33        w=1;
34      }
35      else w+=fw;     
36    }
37    w=maxw;
38  }
39  return w;
40}
41
42int string_visual::height(window_manager *wm)
43{
44  if (w==-1) width(wm);
45  return h;
46}
47
48
49static void put_para(image *screen, char *st, int dx, int dy,
50                     int xspace, int yspace, JCFont *font, int color)
51{
52  int ox=dx;
53  while (*st)
54  {
55    if (*st=='\n')
56    {
57      dx=ox;
58      dy+=yspace;
59    }
60    else
61    {
62      font->put_char(screen,dx,dy,*st,color);
63      dx+=xspace;
64    }
65    st++;
66  }
67}
68
69void string_visual::draw(image *screen, int x, int y,
70                    window_manager *wm, filter *f)
71
72{
73  put_para(screen,st,x+1,y+1,wm->font()->width(),wm->font()->height(),
74           wm->font(),f ? f->get_mapping(color) : color);
75}
76
Note: See TracBrowser for help on using the repository browser.