1 /****************************************************************************
2  *               userdisp.cpp
3  *
4  * This module contains non-graphic display I/O routines.
5  *
6  * from Persistence of Vision(tm) Ray Tracer version 3.6.
7  * Copyright 1991-2003 Persistence of Vision Team
8  * Copyright 2003-2004 Persistence of Vision Raytracer Pty. Ltd.
9  *---------------------------------------------------------------------------
10  * NOTICE: This source code file is provided so that users may experiment
11  * with enhancements to POV-Ray and to port the software to platforms other
12  * than those supported by the POV-Ray developers. There are strict rules
13  * regarding how you are permitted to use this file. These rules are contained
14  * in the distribution and derivative versions licenses which should have been
15  * provided with this file.
16  *
17  * These licences may be found online, linked from the end-user license
18  * agreement that is located at http://www.povray.org/povlegal.html
19  *---------------------------------------------------------------------------
20  * This program is based on the popular DKB raytracer version 2.12.
21  * DKBTrace was originally written by David K. Buck.
22  * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
23  *---------------------------------------------------------------------------
24  *
25  *===========================================================================
26  * This file is part of MegaPOV, a modified and unofficial version of POV-Ray
27  * For more information on MegaPOV visit our website:
28  * http://megapov.inetart.net/
29  *===========================================================================
30  *
31  * $RCSfile: userdisp.cpp,v $
32  * $Revision: 1.10 $
33  * $Author: chris $
34  *
35  *****************************************************************************/
36 
37 #include <stdarg.h>
38 #include "frame.h"
39 #include "vector.h"
40 #include "parse.h"
41 #include "povray.h"
42 #include "tokenize.h"
43 #include "userio.h"
44 #include "userdisp.h"
45 
46 BEGIN_POV_NAMESPACE
47 
48 /***************************************************************************
49  *
50  * Dummy display routines for non-graphic Unix ports
51  *
52  **************************************************************************/
53 
54 static DBL Display_Width_Scale, Display_Height_Scale; // GLOBAL VARIABLE
55 static int Prev_X, Prev_Y; // GLOBAL VARIABLE
56 
57 /****************************************************************************/
POV_Std_Display_Init(int w,int h)58 int POV_Std_Display_Init(int w, int  h)
59 {
60   Display_Width_Scale = 78.0 / (DBL)w;
61   Display_Height_Scale = 24.0 / (DBL)h;
62   Prev_X = 0;
63   Prev_Y = 0;
64   #ifdef AVOID_EMPTY_STRING_WARNING
65     char *s = NULL;
66     fprintf(stderr, "%s", s);
67   #else
68     fprintf(stderr, "");
69   #endif
70 
71   return true;
72 }
73 
74 /****************************************************************************/
POV_Std_Display_Finished()75 void POV_Std_Display_Finished()
76 {
77   char s[3];
78 
79   #ifndef UNIX_FINISH_BEEP_PATCH
80     fprintf(stderr, "\007\007");
81   #endif
82 
83   if (opts.Options & PROMPTEXIT)
84   {
85     #ifdef UNIX_FINISH_BEEP_PATCH
86       fprintf(stderr, "\007\007");
87     #endif
88 
89     fgets(s, 2, stdin);
90   }
91 }
92 
93 /****************************************************************************/
POV_Std_Display_Close()94 void POV_Std_Display_Close()
95 {
96   #ifdef AVOID_EMPTY_STRING_WARNING
97     char *s = NULL;
98     fprintf(stderr, "%s", s);
99   #else
100     fprintf(stderr, "");
101   #endif
102 }
103 
104 /****************************************************************************/
POV_Std_Display_Plot(int x,int y,unsigned int r,unsigned int g,unsigned int b,unsigned int)105 void POV_Std_Display_Plot(int x, int y, unsigned int r, unsigned int g, unsigned int b, unsigned int)
106 {
107   int sx = (int)(Display_Width_Scale * ((DBL)x));
108   int sy = (int)(Display_Height_Scale * ((DBL)y));
109   char I;
110   unsigned char G[6] = { ' ', '.', 'o', '*', '@', 'M' };
111 
112   if (sy > Prev_Y)
113   {
114     Prev_Y++;
115 
116   #ifdef AVOID_EMPTY_STRING_WARNING
117     char *s = NULL;
118     fprintf(stderr, "%s", s);
119   #else
120     fprintf(stderr, "");
121   #endif
122 
123     Prev_X = 0;
124   }
125 
126   if (sx > Prev_X)
127   {
128     I = (int)(((DBL)r * 1.80 + (DBL)g * 3.54 + (DBL)b * 0.66) / 256.0);
129 
130     fprintf(stderr, "%c", G[(int)I]);
131 
132     Prev_X++;
133   }
134 }
135 
136 /****************************************************************************/
POV_Std_Display_Plot_Rect(int x1,int y1,int x2,int y2,unsigned int r,unsigned int g,unsigned int b,unsigned int a)137 void POV_Std_Display_Plot_Rect(int x1, int y1, int x2, int y2, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
138 {
139 	int x,y;
140 
141 	for(y = y1; y <= y2; y++)
142 	{
143 		for(x = x1; x <= x2; x++)
144 			POV_Std_Display_Plot(x, y, r, g, b, a);
145 	}
146 }
147 
148 /*****************************************************************************
149 *
150 * FUNCTION
151 *
152 *   POV_Std_Display_Plot_Box
153 *
154 * INPUT
155 *
156 * OUTPUT
157 *
158 * RETURNS
159 *
160 * AUTHOR
161 *
162 *   Chris Young
163 *
164 * DESCRIPTION
165 *
166 *   Generic box drawing routine which may be overriden in POV_DRAW_BOX
167 *   by a platform specific routine.
168 *
169 * CHANGES
170 *
171 *   Nov 1995 : Creation.
172 *
173 ******************************************************************************/
POV_Std_Display_Plot_Box(int x1,int y1,int x2,int y2,unsigned int r,unsigned int g,unsigned int b,unsigned int a)174 void POV_Std_Display_Plot_Box(int x1, int y1, int x2, int y2, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
175 {
176      int x,y;
177 
178      for (x = x1; x <= x2; x++)
179      {
180        POV_DISPLAY_PLOT(opts.Preview_RefCon, x, y1, r, g, b, a);
181        POV_DISPLAY_PLOT(opts.Preview_RefCon, x, y2, r, g, b, a);
182      }
183 
184      for (y = y1; y <= y2; y++)
185      {
186        POV_DISPLAY_PLOT(opts.Preview_RefCon, x1, y, r, g, b, a);
187        POV_DISPLAY_PLOT(opts.Preview_RefCon, x2, y, r, g, b, a);
188      }
189 }
190 
191 END_POV_NAMESPACE
192