Code

Add item transforms
authorishmal <ishmal@users.sourceforge.net>
Fri, 1 Aug 2008 04:35:42 +0000 (04:35 +0000)
committerishmal <ishmal@users.sourceforge.net>
Fri, 1 Aug 2008 04:35:42 +0000 (04:35 +0000)
src/extension/internal/javafx-out.cpp

index d521c34472d26b02ab848db3891cfa6996bf22b4..a5b4cbf37d5648ebe3cfea0591286e14875bd61f 100644 (file)
@@ -140,6 +140,8 @@ bool JavaFXOutput::doHeader(const String &name)
     out("import javafx.ui.UIElement;\n");\r
     out("import javafx.ui.*;\n");\r
     out("import javafx.ui.canvas.*;\n");\r
+    out("\n");\r
+    out("import java.lang.System;\n");\r
     out("\n\n");\r
     out("public class %s extends CompositeNode {\n", name.c_str());\r
     out("}\n");\r
@@ -155,6 +157,19 @@ bool JavaFXOutput::doHeader(const String &name)
 bool JavaFXOutput::doTail(const String &name)\r
 {\r
     out("\n\n\n\n");\r
+    out("Frame {\n");\r
+    out("    title: \"Test\"\n");\r
+    out("    width: 500\n");\r
+    out("    height: 500\n");\r
+    out("    onClose: function()\n");\r
+    out("        {\n");\r
+    out("        return System.exit( 0 );\n");\r
+    out("        }\n");\r
+    out("    visible: true\n");\r
+    out("    content: Canvas {\n");\r
+    out("        content: tux{}\n");\r
+    out("    }\n");\r
+    out("}\n");\r
     out("/*###################################################################\n");\r
     out("### E N D   C L A S S    %s\n", name.c_str());\r
     out("###################################################################*/\n");\r
@@ -221,7 +236,7 @@ bool JavaFXOutput::doCurves(SPDocument *doc, const String &name)
         out("        ###################################################*/\n");\r
         out("        Path \n");\r
         out("        {\n");\r
-        out("        id : \"%s\"\n", id.c_str());\r
+        out("        id: \"%s\"\n", id.c_str());\r
 \r
         /**\r
          * Get the fill and stroke of the shape\r
@@ -264,56 +279,65 @@ bool JavaFXOutput::doCurves(SPDocument *doc, const String &name)
                 segmentCount += 1;\r
         }\r
 \r
-        out("        d :\n");\r
+        out("        d:\n");\r
         out("            [\n");\r
 \r
         unsigned int segmentNr = 0;\r
 \r
         nrSegments += segmentCount;\r
 \r
-        for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) {\r
-\r
-\r
-            for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit) {\r
-\r
+        for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit)\r
+            {\r
+            Geom::Point p = pit->initialPoint() * tf;\r
+            out("            MoveTo {\n");\r
+            out("                x: %s\n", dstr(p[X]).c_str());\r
+            out("                y: %s\n", dstr(p[Y]).c_str());\r
+            out("                absolute: true\n");\r
+            out("                },\n");\r
+            for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)\r
+                {\r
                 //### LINE\r
                 if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||\r
                     dynamic_cast<Geom::HLineSegment const *>(&*cit) ||\r
                     dynamic_cast<Geom::VLineSegment const *>(&*cit) )\r
-                {\r
+                    {\r
+                    Geom::Point p = cit->initialPoint() * tf;\r
                     out("            LineTo {\n");\r
-                    out("                x: %s\n", dstr(cit->initialPoint()[X]).c_str());\r
-                    out("                y: %s\n", dstr(cit->initialPoint()[Y]).c_str());\r
+                    out("                x: %s\n", dstr(p[X]).c_str());\r
+                    out("                y: %s\n", dstr(p[Y]).c_str());\r
                     out("                absolute: true\n");\r
-                    out("                }");\r
+                    out("                },\n");\r
                     nrNodes++;\r
-                }\r
+                    }\r
                 //### BEZIER\r
-                else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit)) {\r
+                else if(Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const*>(&*cit))\r
+                    {\r
                     std::vector<Geom::Point> points = cubic->points();\r
+                    Geom::Point p0 = points[0] * tf;\r
+                    Geom::Point p1 = points[1] * tf;\r
+                    Geom::Point p2 = points[2] * tf;\r
                     out("            CurveTo {\n");\r
-                    out("                x1: %s\n", dstr(points[0][X]).c_str());\r
-                    out("                y1: %s\n", dstr(points[0][Y]).c_str());\r
-                    out("                x2: %s\n", dstr(points[1][X]).c_str());\r
-                    out("                y2: %s\n", dstr(points[1][Y]).c_str());\r
-                    out("                x3: %s\n", dstr(points[2][X]).c_str());\r
-                    out("                y3: %s\n", dstr(points[3][Y]).c_str());\r
+                    out("                x1: %s\n", dstr(p0[X]).c_str());\r
+                    out("                y1: %s\n", dstr(p0[Y]).c_str());\r
+                    out("                x2: %s\n", dstr(p1[X]).c_str());\r
+                    out("                y2: %s\n", dstr(p1[Y]).c_str());\r
+                    out("                x3: %s\n", dstr(p2[X]).c_str());\r
+                    out("                y3: %s\n", dstr(p2[Y]).c_str());\r
                     out("                smooth: false\n");\r
                     out("                absolute: true\n");\r
-                    out("                }");\r
+                    out("                },\n");\r
                     nrNodes++;\r
-                }\r
-                else {\r
+                    }\r
+                else\r
+                    {\r
                     g_error ("logical error, because pathv_to_linear_and_cubic_beziers was used");\r
+                    }\r
+                }\r
+            if (pit->closed())\r
+                {\r
+                out("            ClosePath {},\n");\r
                 }\r
-\r
-                if (segmentNr <= segmentCount)\r
-                    out(",\n");\r
-                else\r
-                    out("\n");\r
-\r
             }\r
-        }\r
 \r
         out("            ] // d\n");\r
         out("        }, // Path\n");\r