Subversion Repositories Kolibri OS

Rev

Rev 7908 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1005 barsuk 1
#include "func.h"
2
#include "parser.h"
3
#include "use_library.h"
4
 
5
const char header[] = "Graph";
6
const char empty_text[] = "No function loaded. Type file name and press Enter. ";
7
const char er_file_not_found[] = "Cannot open file. ";
8
const char str_filename[]="Filename:";
9
const char str_editfile[]="Edit";
10
 
11
// начальные размеры
6761 leency 12
#define WND_W 600
13
#define WND_H 470
1005 barsuk 14
 
15
#define LIGHTGREEN 0xff0000
16
#define WHITE 0xffffff
17
#define BLACK 0x0
18
#define LIGHTBLUE 0x0000ff
19
#define LIGHTRED 0xff0000
20
 
21
// font colors
22
#define BIGFONTCOLOR BLACK
23
#define SMALLFONTCOLOR BLACK
24
 
25
#define THREE 3.0
26
// minimum space: 3 pixels
27
 
28
#define BIG_HEIGHT 4.0
29
#define SMALL_HEIGHT 2.0
30
#define TEXT_X 15.0
31
// numeric format for output
32
#define FORMAT "%f"
33
// format for two coords
34
#define FORMAT_COORD "(%f,%f)"
35
// special value to text if enough space
36
#define FORMAT_TEST "0.00"
37
 
38
#define DELTA_BIG 1.0
39
#define DELTA_SMALL 0.1
40
 
41
double *points;
42
Dword point_count = 0;
43
double x1,y1,x2,y2;
44
char *funct = NULL;
45
 
7648 leency 46
char edit_path[256];
7933 leency 47
edit_box mybox = {200,92,WND_H-16-32,0xffffff,0x94AECE,0,0x808080,0x10000000,
48
	sizeof(edit_path)-1,(dword)&edit_path, 0, 0, 0};
1005 barsuk 49
 
50
char *full_head;
51
 
52
char *HugeBuf = NULL;
53
 
54
//char fuck[64] = "$this is a fucking marker$";
55
// параметры командной строки
1764 clevermous 56
#ifdef AUTOBUILD
57
extern char params[1024];
58
char params[1024];
59
#else
1005 barsuk 60
char params[1024] = "_FIND_ME_";
1764 clevermous 61
#endif
1005 barsuk 62
 
63
/*
64
 
65
  fucking piece of shit
66
 
67
  */
68
 
69
// constructor of TCoord
70
TCoord coord(double x, double y)
71
{
72
  TCoord r;
73
  r.x = x;
74
  r.y = y;
75
  return r;
76
}
77
 
78
// move and scale mathematical coords to fit screen coords
79
TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax)
80
{
81
  TCoord r;
82
  if (c.x > mMax.x)
83
    c.x = mMax.x;
84
  if (c.x < mMin.x)
85
    c.x = mMin.x;
86
  if (c.y > mMax.y)
87
    c.y = mMax.y;
88
  if (c.y < mMin.y)
89
    c.y = mMin.y;
90
  r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x;
91
  r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y;
92
 
93
  return r;
94
}
95
 
96
// double-обертки
97
void line_d( double x1, double y1, double x2, double y2)
98
{
99
   line(di(x1), di(y1), di(x2), di(y2));
100
}
101
 
102
void outtextxy_d( double x, double y, char * text, int len)
103
{
104
   outtextxy(di(x), di(y), text, len);
105
}
106
 
107
// huge function to draw all the stuff except the function itself
108
void drawAxis( TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax)
109
{
110
  TCoord cZero={0.0,0.0},
111
	   gMin, gMax, gZero, step;
112
  TCoord from, to;
113
  double i=0.0;
114
  int j;
115
  double xmin, xmin2, ymin, ymin2;
116
  char buf[30]="";
117
 
118
 
119
// scr means Screen(bounding rect)
120
// m   means Mathematical
121
// g   means Graphic(real screen position)
122
 
123
  //rtlDebugOutString("draw axis called\n");
124
 
125
  //format(debuf, 30, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57);
126
  //rtlDebugOutString(debuf);
127
 
128
  gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax);
129
  gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax);
130
  gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax);
131
 
132
  // clear
133
 // setcolor(WHITE);
134
 //rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y));
135
  // ftopku
136
 
137
  setcolor(BLACK);
138
  // osy X
139
  line_d(gMin.x, gZero.y ,gMax.x, gZero.y);
140
  // osy Y
141
  line_d(gZero.x, gMin.y, gZero.x, gMax.y);
142
  // bounding rect
143
  line_d(gMin.x, gMin.y, gMax.x, gMin.y);
144
  line_d(gMin.x, gMax.y, gMax.x, gMax.y);
145
 
146
  line_d(gMin.x, gMin.y, gMin.x, gMax.y);
147
  line_d(gMax.x, gMin.y, gMax.x, gMax.y);
148
 
149
  // coords of the rect : lower left
150
  format(buf, 30, FORMAT_COORD, x1, y1);
151
  //rtlDebugOutString(buf);
152
  outtextxy_d(gMin.x, gMin.y + textheight(buf, 20), buf, 20);
153
  // upper left
154
  format(buf, 30, FORMAT_COORD, x1, y2);
155
  outtextxy_d(gMin.x, gMax.y - textheight(buf, 20), buf, 20);
156
  // lower right
157
  format(buf, 30, FORMAT_COORD, x2, y1);
158
  outtextxy_d(gMax.x - textwidth(buf, 20), gMin.y + textheight(buf, 20), buf, 20);
159
  // upper right
160
  format(buf, 30, FORMAT_COORD, x2, y2);
161
  outtextxy_d(gMax.x - textwidth(buf, 20), gMax.y - textheight(buf, 20), buf, 20);
162
 
163
  //rtlDebugOutString("some lines painted\n");
164
 
165
 
166
  step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
167
  step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y);
168
 
169
// round values
170
  xmin = id(di((mMin.x / DELTA_BIG) * DELTA_BIG));
171
  ymin = id(di((mMin.y / DELTA_BIG) * DELTA_BIG));
172
 
173
  // (0,0)
174
 
175
  if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0))
176
  {
177
	  from.x=0.0;
178
	  from.y=0.0;
179
	  from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
180
	  setcolor(BLACK);
181
	  format(buf, 30, FORMAT, 0.0);
182
	  outtextxy_d(from.x - textwidth(buf, 20), from.y + textheight(buf, 20), buf, 20);
183
  }
184
 
185
 
186
  // big marks on X
187
  //settextstyle(0, 0, 1);
188
  if (DELTA_BIG / step.x > THREE)
189
  {
190
    for (i = xmin; i <= mMax.x; i += DELTA_BIG)
191
    {
192
	  if (i != 0.0)
193
	  {
194
		  from.x = i;
195
		  to.x = from.x;
196
		  from.y = -BIG_HEIGHT * step.y;
197
		  to.y = BIG_HEIGHT * step.y;
198
		  from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
199
		  to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
200
		  setcolor(BLACK);
201
		  line_d(from.x, from.y, to.x, to.y);
202
		  // write number
203
		  format(buf, 30, FORMAT, i);
204
		  // if it fits in the GAP, then write it
205
		  if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, 20) + 1.0) * step.x))
206
		  {
207
			   setcolor(BIGFONTCOLOR);
208
			   outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20);
209
		  }
210
	  }
211
    }
212
  }
213
  //rtlDebugOutString("big marks x painted\n");
214
 
215
  // big marks on Y
216
  if (DELTA_BIG / step.y > THREE)
217
  {
218
    for (i = ymin; i <= mMax.y; i += DELTA_BIG)
219
    {
220
	  if (i != 0.0)
221
	  {
222
		  from.y = i;
223
		  to.y = from.y;
224
		  from.x = -BIG_HEIGHT * step.x;
225
		  to.x = BIG_HEIGHT * step.x;
226
		  from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
227
		  to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
228
		  setcolor(BLACK);
229
		  line_d(from.x, from.y, to.x, to.y);
230
		  format(buf, 30, FORMAT, i);
231
		  if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, 20) * step.y))
232
		  {
233
			   setcolor(BIGFONTCOLOR);
234
			 outtextxy_d(from.x + TEXT_X, to.y - textheight(buf, 20) / 2.0, buf, 20);
235
		  }
236
	  }
237
    }
238
  }
239
 
240
  xmin2 = id(di(mMin.x / DELTA_SMALL)) * DELTA_SMALL;
241
  ymin2 = id(di(mMin.y / DELTA_SMALL)) * DELTA_SMALL;
242
 
243
  if (DELTA_SMALL / step.x  > THREE)
244
  {
245
    j = di((( - xmin + xmin2 ) / DELTA_SMALL));
246
    for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++)
247
    {
248
      if (j % 10 == 0)
249
      {
250
      // we need to skip every tenth mark, to avoid overwriting big marks
251
		j = 0;
252
		continue;
253
      }
254
      from.x = i;
255
      to.x = from.x;
256
      from.y = -SMALL_HEIGHT * step.y;
257
      to.y = SMALL_HEIGHT * step.y;
258
      from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
259
	  to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
260
      setcolor(BLACK);
261
      line_d(from.x, from.y, to.x, to.y);
262
      format(buf, 30, FORMAT, i);
263
 
264
      if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, 20) * step.x))
265
      {
266
		setcolor(SMALLFONTCOLOR);
267
		outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20);
268
      }
269