File: 3deffects.c

package info (click to toggle)
zgv 3.0-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 680 kB
  • ctags: 616
  • sloc: ansic: 6,696; makefile: 109; sh: 23
file content (172 lines) | stat: -rw-r--r-- 4,452 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* Zgv v3.0 - GIF, JPEG and PBM/PGM/PPM viewer, for VGA PCs running Linux.
 * Copyright (C) 1993-1998 Russell Marks. See README for license details.
 *
 * 3deffects.c - provides the '3d' style boxes, text etc.
 *                used by zgv.c (for file selector) and vgadisp.c
 *                (for help screen)
 */


#include <unistd.h>
#include <vga.h>
#include "3deffects.h"
#include "font.h"
#include "readnbkey.h"
#include "zgv.h"
#include "rc_config.h"
#include "rcfile.h"


int msgbox_draw_ok=0;	/* 1 if ok to draw msgbox in current mode */


/* produce tacky 3d text */
void drawtext3d(int x,int y,int s,char *str,
                int isout,int lite,int dark,int txt)
{
vga_setcolor(isout?lite:dark);
vgadrawtext(x-1,y-1,s,str);
vga_setcolor(isout?dark:lite);
vgadrawtext(x+1,y+1,s,str);
vga_setcolor(txt);
vgadrawtext(x,y,s,str);
}


/* restore sanity */
void undrawtext3d(int x,int y,int s,char *str)
{
vga_setcolor(idx_medium);
vgadrawtext(x-1,y-1,s,str);
vgadrawtext(x+1,y+1,s,str);
vgadrawtext(x,y,s,str);
}


/* render each bock in 3d */
void draw3dbox(int x1,int y1,int x2,int y2,int depth,
               int isout,int lite,int dark)
{
int f;

for(f=0;f<depth;f++)
  {
  vga_setcolor(isout?lite:dark);
  vga_drawline(x1+f,y2-f,x1+f,y1+f);
  vga_drawline(x1+f,y1+f,x2-f,y1+f);
  vga_setcolor(isout?dark:lite);
  vga_drawline(x2-f,y1+f,x2-f,y2-f);
  vga_drawline(x2-f,y2-f,x1+f,y2-f);
  }
}


/* Undraw each relevant bock */
void undraw3dbox(int x1,int y1,int x2,int y2,int depth)
{
int f;

vga_setcolor(idx_medium);
for(f=0;f<depth;f++)
  {
  vga_drawline(x1+f,y2-f,x1+f,y1+f);
  vga_drawline(x1+f,y1+f,x2-f,y1+f);
  vga_drawline(x2-f,y1+f,x2-f,y2-f);
  vga_drawline(x2-f,y2-f,x1+f,y2-f);
  }
}


/* this blasts whatever is 'under' it - you have to save or redraw it.
 * also, if msgbox_draw_ok is zero, it changes to 640x480x16 mode before
 * drawing the box, and obviously this blasts the lot. :-)
 */
int msgbox(int ttyfd,char *message,int replytype,int lite,int dark,int txt)
{
int f,x1,y1,x2,y2,wide,high,key;

if(!msgbox_draw_ok)
  {
  /* fairly nasty, but it'll be followed by a mode change so it
   * doesn't matter.
   */
  vga_setmode((vga_hasmode(G640x480x256) && cfg.force16fs==0)?
                G640x480x256:G640x480x16);
  vga_setpalette(idx_medium=1,cfg.medium.r,cfg.medium.g,cfg.medium.b);
  vga_setpalette(dark=2,cfg.dark.r,cfg.dark.g,cfg.dark.b);
  vga_setpalette(lite=3,cfg.light.r,cfg.light.g,cfg.light.b);
  vga_setpalette(txt =4,cfg.black.r,cfg.black.g,cfg.black.b);
  }

set_max_text_width(570);

high=90;
wide=vgatextsize(3,message)+60;
x1=((vga_getxdim()-wide)>>1);
y1=((vga_getydim()-high)>>1);
x2=((vga_getxdim()+wide)>>1);
y2=((vga_getydim()+high)>>1);

vga_setcolor(idx_medium);
for(f=y1;f<y2;f++)
  vga_drawline(x1,f,x2,f);

/* draw outer box */
draw3dbox(x1 ,y1  ,x2  ,y2  ,2,1, lite,dark);
draw3dbox(x1+9,y1+9,x2-9,y2-9,1,0, lite,dark);

/* finally, I've got around to doing different types of msgbox! */
switch(replytype)
  {
  /* a box with a single 'OK' button, for warnings, errors, etc. */
  case MSGBOXTYPE_OK:
    /* draw 'button' */
    draw3dbox((vga_getxdim()-40)>>1,y2-45,
              (vga_getxdim()+40)>>1,y2-20, 1,1, lite,dark);

    vga_setcolor(txt);
    vgadrawtext(x1+30,y1+20,3,message);
    drawtext3d(((vga_getxdim()-15)>>1)-3*(cfg.linetext==0),y2-39,3,
    	"OK",0,lite,dark,txt);
    set_max_text_width(NO_CLIP_FONT);

    do
      {
      usleep(40000);
      key=readnbkey(ttyfd);
      }
    while((key!=RK_ESC)&&(key!=RK_ENTER));
    return(1);

  /* a box with two buttons, 'Yes' and 'No'. Enter or 'y' selects yes,
   * Esc or 'n' selects no.
   */    
  case MSGBOXTYPE_YESNO:
    /* draw 'yes' button */
    draw3dbox((vga_getxdim()>>1)-50,y2-45,
              (vga_getxdim()>>1)-10,y2-20, 1,1, lite,dark);
    vga_setcolor(txt);
    vgadrawtext(x1+30,y1+20,3,message);		/* draw message */
    drawtext3d((vga_getxdim()>>1)-43-1*(cfg.linetext==0),y2-39,3,
    	"Yes",0,lite,dark,txt);

    /* draw 'no' button */
    draw3dbox((vga_getxdim()>>1)+10,y2-45,
              (vga_getxdim()>>1)+50,y2-20, 1,1, lite,dark);
    vga_setcolor(txt);
    drawtext3d((vga_getxdim()>>1)+23-2*(cfg.linetext==0),y2-39,3,
    	"No",0,lite,dark,txt);

    set_max_text_width(NO_CLIP_FONT);
    
    do
      {
      usleep(40000);
      key=readnbkey(ttyfd);
      }
    while(key!=RK_ESC && key!=RK_ENTER && key!='y' && key!='n');

    return(key==RK_ENTER || key=='y');
  }
return(0);
}