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