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 | |
---|
15 | void 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 | |
---|
25 | string_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 | |
---|
33 | int 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 | |
---|
54 | int string_visual::height() |
---|
55 | { |
---|
56 | if (w==-1) width(); |
---|
57 | return h; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | static 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 | |
---|
81 | void 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 | |
---|