rllib  1
rlsvganimator.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rlsvganimator.cpp - description
3  -------------------
4  begin : Tue Apr 10 2006
5  copyright : (C) 2006 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #include "rlcutil.h"
17 #include "rlsvganimator.h"
18 #include "rlsvgcat.h"
19 #ifndef RLWIN32
20 #include "rlspawn.h"
21 #endif
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <math.h>
27 
28 #ifdef RLWIN32
29 #include <windows.h>
30 #include <io.h>
31 #include <direct.h>
32 #define MSG_NOSIGNAL 0
33 #else
34 #include <sys/time.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 #include <netdb.h>
39 #include "unistd.h"
40 #endif
41 
42 #ifdef __VMS
43 #define MSG_NOSIGNAL 0
44 #endif
45 
46 #ifdef PVMAC
47 #define MSG_NOSIGNAL 0
48 #endif
49 
50 #define MAXLINE 256*256
51 
53 {
54  sx = 1.0f;
55  alpha = x0 = y0 = cx = cy = 0.0f;
56  init.sx = init.alpha = init.x0 = init.y0 = init.w = init.h = -1;
57 }
58 
59 rlSvgPosition::rlSvgPosition(float sx_init, float a_init, float x0_init, float y0_init, float w_init, float h_init)
60 {
61  sx = 1.0f;
62  alpha = x0 = y0 = cx = cy = 0.0f;
63  init.sx = sx_init;
64  init.alpha = a_init;
65  init.x0 = x0_init;
66  init.y0 = y0_init;
67  init.w = w_init;
68  init.h = h_init;
69 }
70 
72 {
73 }
74 
75 void rlSvgPosition::setInit(float x0_init, float y0_init, float w_init, float h_init)
76 {
77  init.x0 = x0_init;
78  init.y0 = y0_init;
79  init.w = w_init;
80  init.h = h_init;
81 }
82 
83 void rlSvgPosition::move(float x, float y)
84 {
85  x0 = x;
86  y0 = y;
87 }
88 
89 void rlSvgPosition::moveRelative(float dx, float dy)
90 {
91  x0 += dx;
92  y0 += dy;
93 }
94 
95 void rlSvgPosition::scale(float s)
96 {
97  sx = s;
98 }
99 
101 {
102  sx *= ds;
103 }
104 
105 void rlSvgPosition::rotate(float _alpha, float _cx, float _cy)
106 {
107  alpha = _alpha;
108  cx = _cx;
109  cy = _cy;
110 }
111 
112 
114 {
115  s = NULL;
116  id = 0;
117  isModified = 1;
118 
119  // zoomer follows
120  svgX0 = svgY0 = 0.0f;
121  svgScale = 1.0f;
122  svgWindowWidth = 640.0f;
123  svgWindowHeight = 480.0f;
124  svgMouseX0 = svgMouseY0 = 0.0f;
125  svgMouseX1 = svgMouseY1 = 0.0f;
126  main_object_name.setText("main");
127 }
128 
130 {
131 }
132 
133 int rlSvgAnimator::tcpsend(const char *buf, int len)
134 {
135  int ret,bytes_left,first_byte;
136 
137  if(s == NULL) return -1;
138  //rlDebugPrintf("tcpsend len=%d buf=%s",len,buf);
139  bytes_left = len;
140  first_byte = 0;
141  while(bytes_left > 0)
142  {
143  if(*s == 1) // use stdout
144  {
145 #ifdef __VMS
146  ret = send(1,&buf[first_byte],bytes_left,MSG_NOSIGNAL);
147 #else
148  ret = write(1,&buf[first_byte],bytes_left);
149 #endif
150  if(ret <= 0)
151  {
152  *s = -1;
153  return -1;
154  }
155  }
156  else // use socket
157  {
158  ret = send(*s,&buf[first_byte],bytes_left,MSG_NOSIGNAL);
159  if(ret <= 0)
160  {
161  *s = -1;
162  return -1;
163  }
164  }
165  bytes_left -= ret;
166  first_byte += ret;
167  }
168  return 0;
169 }
170 
171 int rlSvgAnimator::read(const char *infile, rlIniFile *inifile)
172 {
173  isModified = 1;
174 #ifdef RLUNIX
175  rlSpawn rlsvg;
176  int ret, use_stdout;
177  char command[MAXLINE];
178  const char *line;
179 
180  inifileState = 0;
181  inifileCount = 0;
182  if(inifile == NULL) use_stdout = 0;
183  use_stdout = 0;
184  if(s != NULL && *s == 1) use_stdout = 1;
185 
186  rlDebugPrintf("rlSvgAnimator step=1 infile=%s\n",infile);
187  if(use_stdout == 0)
188  {
189  sprintf(command,"rlsvgcat %s",infile);
190  ret = rlsvg.spawn(command);
191  if(ret < 0) return -1;
192  }
193 
194  rlDebugPrintf("rlSvgAnimator step=2\n");
195 
196  if(id != 0 && s != NULL) // new style programming
197  {
198  sprintf(command,"gsvgRead(%d)\n",id);
199  tcpsend(command,strlen(command));
200  if(use_stdout == 0)
201  {
202  while((line = rlsvg.readLine()) != NULL)
203  {
204  tcpsend(line,strlen(line));
205  if(inifile != NULL) fillIniFile(inifile, line);
206  }
207  }
208  else
209  {
210  sprintf(command,"/usr/bin/rlsvgcat %s",infile);
211  ret = system(command);
212  if(ret == -1) return -1;
213  if(inifile != NULL)
214  {
215  char outfile[80];
216  sprintf(outfile,"PVTMP%d.svg",*s);
217  sprintf(command,"/usr/bin/rlsvgcat %s %s",infile,outfile);
218  ret = system(command);
219  if(ret == -1) return -1;
220  fileFillIniFile(outfile, inifile);
221  unlink(outfile);
222  }
223  }
224  sprintf(command,"\n<svgend></svgend>\n");
225  tcpsend(command,strlen(command));
226  return 0;
227  }
228  else
229  {
230  return -1;
231  }
232 #else
233  // Windows: use file instead of pipe
234  FILE *fin;
235  int ret;
236  char filename[1024];
237  char cmd[1024];
238  char command[MAXLINE];
239  char line[MAXLINE];
240  char *cptr;
241 
242  inifileState = 0;
243  inifileCount = 0;
244  if(s==NULL) sprintf(filename,"PVTEMP%s",infile);
245  else sprintf(filename,"PVTEMP%d%s",*s,infile);
246  sprintf(cmd,"rlsvgcat %s %s",infile,filename);
247  ret = system(cmd);
248  if(ret < 0) return -1;
249  fin = fopen(filename,"r");
250  if(fin == NULL) return -1;
251  sprintf(command,"gsvgRead(%d)\n",id);
252  tcpsend(command,strlen(command));
253  while(fgets(line,sizeof(line)-1,fin) != NULL)
254  {
255  cptr = strchr(line,0x0d);
256  if(cptr != NULL) *cptr = '\0';
257  cptr = strchr(line,0x0a);
258  if(cptr != NULL) *cptr = '\0';
259  tcpsend(line,strlen(line));
260  tcpsend("\n",strlen("\n"));
261  if(inifile != NULL) fillIniFile(inifile, line);
262  }
263  sprintf(command,"\n<svgend></svgend>\n");
264  tcpsend(command, strlen(command));;
265  unlink(filename);
266  return 0;
267 #endif
268 }
269 
270 int rlSvgAnimator::setSocket(int *socket)
271 {
272  isModified = 1;
273  s = socket;
274  return 0;
275 }
276 
278 {
279  isModified = 1;
280  id = _id;
281  return 0;
282 }
283 
285 {
286  char buf[80];
287 
288  isModified = 0;
289 
290  if(s == NULL)
291  {
292  printf("rlSvgAnimator: ERROR please use setSocket first\n");
293  return -1;
294  }
295  if(id != 0)
296  {
297  sprintf(buf,"gupdateSVG(%d)\n",id);
298  tcpsend(buf, strlen(buf));
299  return 0;
300  }
301  return -1;
302 }
303 
304 #define MAXBUF 1024
305 
306 int rlSvgAnimator::svgPrintf(const char *objectname, const char *tag, const char *format, ...)
307 {
308  char buf[MAXBUF+40];
309  char text[MAXBUF];
310  int len = strlen(objectname);
311 
312  isModified = 1;
313  if(id != 0)
314  {
315  sprintf(buf,"gsvgPrintf(%d)\n",id);
316  tcpsend(buf, strlen(buf));
317  sprintf(buf,"%s\n",objectname);
318  tcpsend(buf, strlen(buf));
319  sprintf(buf,"%s\n",tag);
320  tcpsend(buf, strlen(buf));
321  va_list ap;
322  va_start(ap,format);
323 #ifdef RLWIN32
324  _vsnprintf(text, MAXBUF - 1, format, ap);
325 #endif
326 #ifdef __VMS
327  vsprintf(text, format, ap);
328 #endif
329 #ifdef RLUNIX
330  vsnprintf(text, MAXBUF - 1, format, ap);
331 #endif
332  va_end(ap);
333  strcat(text,"\n");
334  len = strlen(text);
335  tcpsend(text, len);
336  return len;
337  }
338  return -1;
339 }
340 
341 int rlSvgAnimator::svgRecursivePrintf(const char *objectname, const char *tag, const char *format, ...)
342 {
343  char buf[MAXBUF+40];
344  char text[MAXBUF];
345  int len;
346 
347  isModified = 1;
348  sprintf(buf,"gsvgRecursivePrintf(%d)\n",id);
349  tcpsend(buf, strlen(buf));
350  sprintf(buf,"%s\n",objectname);
351  tcpsend(buf, strlen(buf));
352  sprintf(buf,"%s\n",tag);
353  tcpsend(buf, strlen(buf));
354  va_list ap;
355  va_start(ap,format);
356 #ifdef RLWIN32
357  _vsnprintf(text, MAXBUF - 1, format, ap);
358 #endif
359 #ifdef __VMS
360  vsprintf(text, format, ap);
361 #endif
362 #ifdef RLUNIX
363  vsnprintf(text, MAXBUF - 1, format, ap);
364 #endif
365  va_end(ap);
366  strcat(text,"\n");
367  len = strlen(text);
368  tcpsend(text, len);
369  return len;
370 }
371 
372 int rlSvgAnimator::svgSearchAndReplace(const char *objectname, const char *tag, const char *before, const char *after)
373 {
374  char buf[MAXBUF+40];
375 
376  isModified = 1;
377  sprintf(buf,"gsvgSearchAndReplace(%d)\n",id);
378  tcpsend(buf, strlen(buf));
379  sprintf(buf,"%s\n",objectname);
380  tcpsend(buf, strlen(buf));
381  sprintf(buf,"%s\n",tag);
382  tcpsend(buf, strlen(buf));
383  sprintf(buf,"%s\n",before);
384  tcpsend(buf, strlen(buf));
385  sprintf(buf,"%s\n",after);
386  tcpsend(buf, strlen(buf));
387  return 0;
388 }
389 
390 int rlSvgAnimator::svgRecursiveSearchAndReplace(const char *objectname, const char *tag, const char *before, const char *after)
391 {
392  char buf[MAXBUF+40];
393 
394  isModified = 1;
395  sprintf(buf,"gsvgRecursiveSearchAndReplace(%d)\n",id);
396  tcpsend(buf, strlen(buf));
397  sprintf(buf,"%s\n",objectname);
398  tcpsend(buf, strlen(buf));
399  sprintf(buf,"%s\n",tag);
400  tcpsend(buf, strlen(buf));
401  sprintf(buf,"%s\n",before);
402  tcpsend(buf, strlen(buf));
403  sprintf(buf,"%s\n",after);
404  tcpsend(buf, strlen(buf));
405  return 0;
406 }
407 
408 int rlSvgAnimator::svgTextPrintf(const char *objectname, const char *format, ...)
409 {
410  char buf[MAXBUF+40];
411  char text[MAXBUF];
412  int len = strlen(objectname);
413 
414  isModified = 1;
415  if(id != 0)
416  {
417  sprintf(buf,"gsvgTextPrintf(%d)\n",id);
418  tcpsend(buf, strlen(buf));
419  sprintf(buf,"%s\n",objectname);
420  tcpsend(buf, strlen(buf));
421  va_list ap;
422  va_start(ap,format);
423 #ifdef RLWIN32
424  _vsnprintf(text, MAXBUF - 1, format, ap);
425 #endif
426 #ifdef __VMS
427  vsprintf(text, format, ap);
428 #endif
429 #ifdef RLUNIX
430  vsnprintf(text, MAXBUF - 1, format, ap);
431 #endif
432  va_end(ap);
433  strcat(text,"\n");
434  len = strlen(text);
435  tcpsend(text, len);
436  return len;
437  }
438  return -1;
439 }
440 
441 int rlSvgAnimator::svgRemoveStyleOption(const char *objectname, const char *option)
442 {
443  char buf[MAXBUF+40];
444 
445  isModified = 1;
446  sprintf(buf,"gsvgRemoveStyleOption(%d)\n",id);
447  tcpsend(buf, strlen(buf));
448  sprintf(buf,"%s\n",objectname);
449  tcpsend(buf, strlen(buf));
450  sprintf(buf,"%s\n","style=");
451  tcpsend(buf, strlen(buf));
452  sprintf(buf,"%s\n",option);
453  tcpsend(buf, strlen(buf));
454  return 0;
455 }
456 
457 int rlSvgAnimator::svgRecursiveRemoveStyleOption(const char *objectname, const char *option)
458 {
459  char buf[MAXBUF+40];
460 
461  isModified = 1;
462  sprintf(buf,"gsvgRecursiveRemoveStyleOption(%d)\n",id);
463  tcpsend(buf, strlen(buf));
464  sprintf(buf,"%s\n",objectname);
465  tcpsend(buf, strlen(buf));
466  sprintf(buf,"%s\n","style=");
467  tcpsend(buf, strlen(buf));
468  sprintf(buf,"%s\n",option);
469  tcpsend(buf, strlen(buf));
470  return 0;
471 }
472 
473 int rlSvgAnimator::svgChangeStyleOption(const char *objectname, const char *option, const char *value)
474 {
475  char buf[MAXBUF+40];
476 
477  isModified = 1;
478  sprintf(buf,"gsvgChangeStyleOption(%d)\n",id);
479  tcpsend(buf, strlen(buf));
480  sprintf(buf,"%s\n",objectname);
481  tcpsend(buf, strlen(buf));
482  sprintf(buf,"%s\n","style=");
483  tcpsend(buf, strlen(buf));
484  sprintf(buf,"%s\n",option);
485  tcpsend(buf, strlen(buf));
486  sprintf(buf,"%s\n",value);
487  tcpsend(buf, strlen(buf));
488  return 0;
489 }
490 
491 int rlSvgAnimator::svgRecursiveChangeStyleOption(const char *objectname, const char *option, const char *value)
492 {
493  char buf[MAXBUF+40];
494 
495  isModified = 1;
496  sprintf(buf,"gsvgRecursiveChangeStyleOption(%d)\n",id);
497  tcpsend(buf, strlen(buf));
498  sprintf(buf,"%s\n",objectname);
499  tcpsend(buf, strlen(buf));
500  sprintf(buf,"%s\n","style=");
501  tcpsend(buf, strlen(buf));
502  sprintf(buf,"%s\n",option);
503  tcpsend(buf, strlen(buf));
504  sprintf(buf,"%s\n",value);
505  tcpsend(buf, strlen(buf));
506  return 0;
507 }
508 
509 int rlSvgAnimator::svgSetStyleOption(const char *objectname, const char *value)
510 {
511  char buf[MAXBUF+40];
512 
513  isModified = 1;
514  sprintf(buf,"gsvgSetStyleOption(%d)\n",id);
515  tcpsend(buf, strlen(buf));
516  sprintf(buf,"%s\n",objectname);
517  tcpsend(buf, strlen(buf));
518  sprintf(buf,"%s\n","style=");
519  tcpsend(buf, strlen(buf));
520  sprintf(buf,"%s\n",value);
521  tcpsend(buf, strlen(buf));
522  return 0;
523 }
524 
525 int rlSvgAnimator::svgRecursiveSetStyleOption(const char *objectname, const char *value)
526 {
527  char buf[MAXBUF+40];
528 
529  isModified = 1;
530  sprintf(buf,"gsvgRecursiveSetStyleOption(%d)\n",id);
531  tcpsend(buf, strlen(buf));
532  sprintf(buf,"%s\n",objectname);
533  tcpsend(buf, strlen(buf));
534  sprintf(buf,"%s\n","style=");
535  tcpsend(buf, strlen(buf));
536  sprintf(buf,"%s\n",value);
537  tcpsend(buf, strlen(buf));
538  return 0;
539 }
540 
541 int rlSvgAnimator::show(const char *objectname, int state)
542 {
543  rlDebugPrintf("rlSvgAnimator.show state=%d objectname=%s\n",state,objectname);
544  isModified = 1;
545  if(id != 0)
546  {
547  char buf[MAXLINE];
548  sprintf(buf,"gsvgShow(%d,%d)\n",id,state);
549  //printf("buf=%s",buf);
550  tcpsend(buf, strlen(buf));
551  sprintf(buf,"%s\n",objectname);
552  tcpsend(buf, strlen(buf));
553  return 0;
554  }
555  return -1;
556 }
557 
558 int rlSvgAnimator::setMatrix(const char *objectname, rlSvgPosition &pos)
559 {
560  isModified = 1;
561  return setMatrix(objectname, pos.sx, pos.alpha, pos.x0, pos.y0, pos.cx, pos.cy);
562 }
563 
564 int rlSvgAnimator::setMatrix(const char *objectname, float sx, float alpha, float x0, float y0, float cx_in, float cy_in)
565 {
566  // sx = scale x
567  // alpha = rotation
568  // x0,y0 = tranlation
569  // cx,cy = rotation center
570  //
571  // matrix:
572  // a11 a12 a13
573  // a21 a22 a23
574  // a31 a32 a33
575 
576  float a11, a12, a13, a21, a22, a23; // a31, a32, a33;
577  float cx, cy;
578 
579  isModified = 1;
580  cx = cx_in + x0;
581  cy = cy_in + y0;
582 
583  a11 = sx*((float) cos(alpha));
584  a12 = -sx*((float) sin(alpha));
585  a13 = (x0 - cx)*((float) cos(alpha)) - (y0 - cy)*((float) sin(alpha)) + cx;
586  a21 = sx*((float) sin(alpha));
587  a22 = sx*((float) cos(alpha));
588  a23 = (x0 - cx)*((float) sin(alpha)) + (y0 - cy)*((float) cos(alpha)) + cy;
589  //a31 = 0.0f;
590  //a32 = 0.0f;
591  //a33 = 1.0f;
592 
593  return svgPrintf(objectname,"transform=","matrix(%f,%f,%f,%f,%f,%f)",a11,a21,a12,a22,a13,a23);
594 
595 /*********************************************************************************************
596 
597 Definition
598 CTM := CurrentTransformationMatrix
599 t := translate
600 r := rotate
601 s := scale
602 
603 Equotiation
604 CTM = t(cx,cy)*r(a)*t(-cx,-cy)*t(x0,y0)*s(sx)
605 
606  |1 0 cx| |cos(a) -sin(a) 0| |1 0 -cx| |1 0 x0| |sx 0 0|
607 CTM = |0 1 cy|*|sin(a) cos(a) 0|*|0 1 -cy|*|0 1 y0|*|0 sx 0| # OK
608  |0 0 1 | | 0 0 1| |0 0 1 | |0 0 1 | |0 0 1|
609 
610  |1 0 cx| |cos(a) -sin(a) 0| |1 0 -cx| |sx 0 x0|
611 CTM = |0 1 cy|*|sin(a) cos(a) 0|*|0 1 -cy|*|0 sx y0| # OK
612  |0 0 1 | | 0 0 1| |0 0 1 | |0 0 1 |
613 
614  |1 0 cx| |cos(a) -sin(a) 0| |sx 0 x0-cx|
615 CTM = |0 1 cy|*|sin(a) cos(a) 0|*|0 sx y0-cy| # OK
616  |0 0 1 | | 0 0 1| |0 0 1 |
617 
618  |1 0 cx| |sx*cos(a) -sx*sin(a) (x0-cx)*cos(a)-(y0-cy)*sin(a)|
619 CTM = |0 1 cy|*|sx*sin(a) sx*cos(a) (x0-cx)*sin(a)+(y0-cy)*cos(a)| # OK
620  |0 0 1 | | 0 0 1 |
621 
622  |sx*cos(a) -sx*sin(a) (x0-cx)*cos(a)-(y0-cy)*sin(a)+cx|
623 CTM = |sx*sin(a) sx*cos(a) (x0-cx)*sin(a)+(y0-cy)*cos(a)+cy| # OK
624  | 0 0 1 |
625 
626 Check
627 with sx = 1 and a,x0,y0,cx,cy = 0
628 
629  |1 0 0|
630 CTM = |0 1 0| # OK
631  |0 0 1|
632 
633 |x'| |x| |sx*cos(a)*x-sx*sin(a)*y+(x0-cx)*cos(a)-(y0-cy)*sin(a)+cx| |1*x-0*y|
634 |y'| = CTM * |y| = |sx*sin(a)*x+sx*cos(a)*y+(x0-cx)*sin(a)+(y0-cy)*cos(a)+cy| = |0*x+1*y| # OK
635 |0 | |0| | 0 | | 0 |
636 
637 **********************************************************************************************/
638 }
639 
640 int rlSvgAnimator::fillIniFile(rlIniFile *inifile, const char *line)
641 {
642  char myline[MAXLINE],*cptr, *cptr2;
643  const char *id;
644  int i;
645 
646  strcpy(myline,line);
647  cptr = strchr(myline,'\n');
648  if(cptr != NULL) *cptr = '\0';
649 
650  if(myline[0] == '>' || strncmp(myline,"/>",2) == 0)
651  { // end of data -> fill inifile
652  if(inifileState == 1) // if id was found
653  {
654  for(i=0; i<inifileCount; i++)
655  {
656  id = inifileID.text();
657  inifile->setText(id, inifileTable.text(1,i+1), inifileTable.text(2,i+1));
658  }
659  }
660  inifileState = 0;
661  inifileCount = 0;
662  inifileID.clear();
664  }
665  else if(myline[0] == '<')
666  { // ignore this
667  }
668  else if(strncmp(myline,"id=",3) == 0)
669  { // remenber id
670  cptr = strchr(myline,'=');
671  if(cptr != NULL)
672  {
673  cptr++; cptr++;
674  cptr2 = strchr(cptr,'\"');
675  if(cptr2 != NULL) *cptr2 = '\0';
676  inifileID.setText(cptr);
677  inifileState = 1; // id was found
678  }
679  }
680  else
681  { // fill this in table
682  cptr = strchr(myline,'=');
683  if(cptr != NULL)
684  {
685  *cptr = '\0';
686  cptr++; cptr++;
687  cptr2 = strrchr(cptr,'\"');
688  if(cptr2 != NULL) *cptr2 = '\0';
689  inifileTable.setText(1,inifileCount+1,myline);
691  inifileCount++;
692  }
693  }
694 
695  return 0;
696 }
697 
698 int rlSvgAnimator::fileFillIniFile(const char *infile, rlIniFile *inifile)
699 {
700  char line[MAXLINE];
701  FILE *fin;
702 
703  fin = fopen(infile,"r");
704  if(fin == NULL) return -1;
705  while(fgets(line,sizeof(line)-1,fin) != NULL)
706  {
707  fillIniFile(inifile, line);
708  }
709  fclose(fin);
710  return 0;
711 }
712 
713 // zoomer methods follows
714 
715 int rlSvgAnimator::setMainObject(const char *main_object)
716 {
717  isModified = 1;
718  if(main_object == NULL) return -1;
719  main_object_name.setText(main_object);
720  return 0;
721 }
722 
724 {
725  return main_object_name.text();
726 }
727 
728 int rlSvgAnimator::setXY0(float x0, float y0)
729 {
730  isModified = 1;
731  svgX0 = x0;
732  svgY0 = y0;
733  return 0;
734 }
735 
737 {
738  return svgX0;
739 }
740 
742 {
743  return svgY0;
744 }
745 
746 int rlSvgAnimator::setMouseXY0(float x0, float y0)
747 {
748  isModified = 1;
749  svgMouseX0 = x0;
750  svgMouseY0 = y0;
751  return 0;
752 }
753 
755 {
756  return svgMouseX0;
757 }
758 
760 {
761  return svgMouseY0;
762 }
763 
764 int rlSvgAnimator::setMouseXY1(float x1, float y1)
765 {
766  isModified = 1;
767  svgMouseX1 = x1;
768  svgMouseY1 = y1;
769  return 0;
770 }
771 
773 {
774  return svgMouseX1;
775 }
776 
778 {
779  return svgMouseY1;
780 }
781 
782 int rlSvgAnimator::setScale(float scale)
783 {
784  isModified = 1;
785  svgScale = scale;
786  return 0;
787 }
788 
790 {
791  return svgScale;
792 }
793 
794 int rlSvgAnimator::zoomCenter(float newScale)
795 {
796  float oldX0, oldY0;
797 
798  isModified = 1;
799  if (newScale > 1000) newScale = 1000.0f;
800 
801  oldX0 = (svgX0 - ((svgWindowWidth) * (1.0f - svgScale)) / 2.0f) / svgScale;
802  oldY0 = (svgY0 - ((svgWindowHeight) * (1.0f - svgScale)) / 2.0f) / svgScale;
803 
804  svgScale = newScale;
805 
806  svgX0 = oldX0*svgScale + ((svgWindowWidth) * (1.0f - svgScale)) / 2.0f;
807  svgY0 = oldY0*svgScale + ((svgWindowHeight) * (1.0f - svgScale)) / 2.0f;
808 
809  return 0;
810 }
811 
813 {
814  float newScale, scale1, scale2, rectWidth, rectHeight;
815 
816  isModified = 1;
817  rectWidth = svgMouseX1-svgMouseX0;
818  rectHeight = svgMouseY1-svgMouseY0;
819  svgX0 = svgX0 + svgWindowWidth/2 - (svgMouseX0 + rectWidth/2);
820  svgY0 = svgY0 + svgWindowHeight/2 - (svgMouseY0 + rectHeight/2);
821  rectWidth = rectWidth / svgScale;
822  rectHeight = rectHeight / svgScale;
823  scale1 = svgWindowWidth / rectWidth;
824  scale2 = svgWindowHeight / rectHeight;
825 
826  if(scale1 < scale2) newScale = scale1;
827  else newScale = scale2;
828  zoomCenter(newScale);
829 
830  return 0;
831 }
832 
834 {
835  isModified = 1;
836  setMatrix(main_object_name.text(), svgScale, 0.0f, svgX0, svgY0, 0.0f, 0.0f);
837  return 0;
838 }
839 
840 int rlSvgAnimator::setWindowSize(int width, int height)
841 {
842  isModified = 1;
843  svgWindowWidth = (float) width;
844  svgWindowHeight = (float) height;
845  return 0;
846 }
847 
849 {
850  return svgWindowWidth;
851 }
852 
854 {
855  return svgWindowHeight;
856 }
857 
858 int rlSvgAnimator::moveMainObject(float x, float y)
859 {
860  isModified = 1;
861  float xx0 = x0() + (x - mouseX0());
862  float yy0 = y0() + (y - mouseY0());
863  setXY0(xx0,yy0);
865  return 0;
866 }
867 
868 
int rlDebugPrintf(const char *format,...)
Definition: rlcutil.cpp:61
int svgRecursiveRemoveStyleOption(const char *objectname, const char *option)
void moveRelative(float dx, float dy)
int tcpsend(const char *buf, int len)
const char * text(int column, int row)
int setId(int Id)
int setSocket(int *socket)
float svgWindowHeight
int read(const char *infile, rlIniFile *inifile=NULL)
int svgRemoveStyleOption(const char *objectname, const char *option)
void setText(int column, int row, const char *text)
void rotate(float alpha, float cx, float cy)
float windowHeight()
int svgChangeStyleOption(const char *objectname, const char *option, const char *value)
#define MSG_NOSIGNAL
rlSpreadsheetTable inifileTable
void move(float x, float y)
const char * text()
virtual ~rlSvgPosition()
int setWindowSize(int width, int height)
int svgSetStyleOption(const char *objectname, const char *value)
const char * mainObject()
char * text()
Definition: rlstring.cpp:126
#define MAXBUF
int setXY0(float x0, float y0)
int fillIniFile(rlIniFile *inifile, const char *line)
virtual ~rlSvgAnimator()
int svgRecursiveSearchAndReplace(const char *objectname, const char *tag, const char *before, const char *after)
void setText(const char *section, const char *name, const char *text)
Definition: rlinifile.cpp:234
int moveMainObject(float x, float y)
#define MAXLINE
int svgPrintf(const char *objectname, const char *tag, const char *format,...)
int setText(const char *text)
Definition: rlstring.cpp:136
int setMatrix(const char *objectname, float sx, float alpha, float x0, float y0, float cx, float cy)
int setMainObject(const char *main_object)
void scale(float s)
void setText(const char *text)
rlSpreadsheetCell inifileID
int svgSearchAndReplace(const char *objectname, const char *tag, const char *before, const char *after)
int zoomCenter(float newScale)
int setScale(float scale)
int svgTextPrintf(const char *objectname, const char *format,...)
float svgWindowWidth
const char * readLine()
Definition: rlspawn.cpp:307
rlString main_object_name
int svgRecursivePrintf(const char *objectname, const char *tag, const char *format,...)
int setMainObjectMatrix()
void setInit(float x0_init, float y0_init, float w_init, float h_init)
int fileFillIniFile(const char *infile, rlIniFile *inifile)
int show(const char *objectname, int state)
int svgRecursiveChangeStyleOption(const char *objectname, const char *option, const char *value)
int svgRecursiveSetStyleOption(const char *objectname, const char *value)
struct rlSvgPosition::rlPositionInit init
int writeSocket()
The following methods are for modifying a object within a SVG graphic identified by objectname...
int spawn(const char *command)
Definition: rlspawn.cpp:168
int setMouseXY0(float x0, float y0)
int setMouseXY1(float x1, float y1)
void scaleRelative(float ds)