Commits

chunquedong committed aa25a9a Draft

using new fgfx2d API 2

Comments (0)

Files changed (32)

chunmap/ctrl/build.fan

     depends =
     [
       "sys 1.0",
-      "gfx 1.0",
-      "fwt 1.0",
-      "gfx2 1.0",
-      "gfx2Imp 1.0",
       "chunmapView 1.0",
       "chunmapModel 1.0",
       "chunmapData 1.0",
       "chunmapUtil 1.0",
       "slanData 1.0",
       "array 1.0",
-      "fan3dMath 1.0",
-      "fan3dTouch 1.0"
+      "fgfxMath 1.0",
+      "fgfx2d 1.0",
+      "fgfxWtk 1.0",
+      "gfx 1.0",
+      "fwt 1.0",
+      "fgfxFwt 1.0"
     ]
     srcDirs =
     [

chunmap/ctrl/fan/MapCanvas.fan

 //
 
 using chunmapView
-using fwt
-using gfx
-using gfx2
-using gfx2Imp
+using fgfx2d
+using fgfxWtk
 
 **
 ** MapCanvas is a map widget
 **
 @Js
-class MapCanvas : Canvas2, MapObserver
+class MapCanvas : fwt::Canvas, MapObserver
 {
   MapCtrl ctrl
 
     bindEvent
   }
 
-  override Void onPaint2(Graphics2 g)
+  override Void doRepaint() { repaint }
+
+  override Void onPaint(gfx::Graphics gc)
   {
-    if (ctrl.resetSize(size))
+    Graphics g := fgfxFwt::FwtToolkitEnv.toGraphics(gc)
+    if (ctrl.resetSize(Size(size.w, size.h)))
     {
       ctrl.renderMap
     }
     ctrl.onPaint(g)
   }
 
-  override Void doRepaint() { repaint }
-
-  private Void bindEvent()
+  internal Void bindEvent()
   {
     this.onMouseDown.add { this.focus; onEvent(it, CEvent.mouseDown) }
     this.onMouseEnter.add { onEvent(it, CEvent.mouseEnter) }

chunmap/ctrl/fan/MapCtrl.fan

 //
 
 using chunmapView
-using gfx
-using gfx2
-using gfx2Imp
+using fgfx2d
 
 **
 ** MapObserver
 class MapCtrl
 {
   CMap? map
-  private Image2? bufferImage
+  private BufImage? bufferImage
   private MapObserver? mapObserver
 
   OperateManager operateManager := OperateManager(this)
   {
     this.mapObserver = mapObserver
     map = CMap(size, size.w /2 , size.h /2)
-    bufferImage = Image2(size)
+    bufferImage = BufImage(size)
   }
 
 //////////////////////////////////////////////////////////////////////////
   **
   ** paint the buffer to the graphics
   **
-  Void onPaint(Graphics2 g)
+  Void onPaint(Graphics g)
   {
-    g.drawImage2(bufferImage, 0, 0)
-    g.drawText("ChunMap", 2, 8)
+    g.drawImage(bufferImage, 0, 0)
+    g.font = Font("Arial", 8)
+    g.drawText("ChunMap", 2, 16)
   }
 
   **
     if (size.w != map.view.width || size.h != map.view.height)
     {
       map.resetSize(size, size.w /2 , size.h /2)
-      bufferImage = Image2(size)
+      bufferImage = BufImage(size)
       Env.cur.gc
       return true
     }
   **
   ** draw original image to the graphics
   **
-  Void drawOriginImage(Graphics2 g, Int dx, Int dy)
+  Void drawOriginImage(Graphics g, Int dx, Int dy)
   {
-    g.drawImage2(map.image, dx-map.xBuffer, dy-map.yBuffer)
+    g.drawImage(map.image, dx-map.xBuffer, dy-map.yBuffer)
   }
 
   **
   ** paint on buffer
   **
-  Void paintOnBuffer(|Graphics2 g| f)
+  Void paintOnBuffer(|Graphics g| f)
   {
     g := bufferImage.graphics
     g.fillRect(0, 0, bufferImage.size.w, bufferImage.size.h)

chunmap/ctrl/fan/MapWidget.fan

 //
 
 using chunmapView
-using fan3dTouch
-using gfx
-using gfx2
-using gfx2Imp
+using fgfx2d
+using fgfxWtk
 
 **
 ** MapCanvas is a map widget
 **
 @Js
-class MapWidget : Widget, MapObserver
+class MapWidget : View, MapObserver
 {
   MapCtrl ctrl
 
     ctrl = MapCtrl(this)
   }
 
-  override Void onPaint(Graphics2 g)
+  override Void onPaint(Graphics g)
   {
     if (ctrl.resetSize(size))
     {
       ctrl.renderMap
     }
     ctrl.onPaint(g)
-    super.onPaint(g)
   }
 
-  override Void doRepaint() { repaint }
+  override NativeView? nativeView
 
-  override Void touch(MotionEvent e)
+  override Size size() { ctrl.map.size }
+
+  override Void doRepaint() { nativeView.repaint }
+
+  override Void onMotionEvent(MotionEvent e)
   {
-    super.touch(e)
     if (e.consumed) return
 
     CEvent ce := CEvent(CEvent.touchEvent)
-    if (e.isDown) ce.type = EventType.press
-    else if (e.isUp) ce.type = EventType.release
-    else if (e.isMove) ce.type = EventType.move
+    if (e.id == MotionEvent.pressed) ce.type = EventType.press
+    else if (e.id == MotionEvent.released) ce.type = EventType.release
+    else if (e.id == MotionEvent.moved) ce.type = EventType.move
 
-    ce.x = e.pos.x
-    ce.y = e.pos.y
+    ce.x = e.x
+    ce.y = e.y
     ce.rawEvent = e
     ctrl.onEvent(ce)
     e.consumed = true

chunmap/ctrl/fan/OperateManager.fan

 //
 
 using chunmapView
-using gfx
+using fgfx2d
 
 **
 ** OperateManager

chunmap/ctrl/fan/command/ExtentCommand.fan

 
 using chunmapView
 using chunmapModel
-using gfx
+using fgfx2d
 
 **
 ** ExtentCommand

chunmap/ctrl/fan/command/MoveToCommand.fan

 
 using chunmapView
 using chunmapModel
-using gfx
+using fgfx2d
 
 **
 ** MoveToCommand

chunmap/ctrl/fan/command/ZoomCommand.fan

 
 using chunmapView
 using chunmapModel
-using gfx
+using fgfx2d
 
 **
 ** ZoomCommand

chunmap/ctrl/fan/tools/DistanceTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil
     {
       map.drawOriginImage(g, 0, 0)
       g.pen = Pen { width = 3 }
-      g.drawPolyline2(toIntArray(e.x, e.y))
+      g.drawPolyline(toIntArray(e.x, e.y))
       dis := getLength(e.x, e.y)
+      g.font = Font("Arial", 8)
       g.drawText(dis.toLocale("#,###")+"m", e.x+5, e.y-20)
     }
     e.consumed = true

chunmap/ctrl/fan/tools/PickTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil

chunmap/ctrl/fan/tools/RectSelectTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil

chunmap/ctrl/fan/tools/RectangleTool.fan

 //   2011-05-05  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 
 using chunmapModel
 

chunmap/ctrl/fan/tools/SelectTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil

chunmap/ctrl/fan/tools/create/AreaTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
-using array
+using fgfx2d
 
 using chunmapModel
 
     }
   }
 
-  protected override Array toIntArray(Int x, Int y)
+  protected override PointArray toIntArray(Int x, Int y)
   {
-    ps := Array.allocate((lse.size+2) * 2)
+    ps := PointArray((lse.size+2))
     n := lse.size
     i:=0
     for (; i<n; ++i)
     {
       p := lse.get(i)
-      ps.setInt(i*2, map.view.x2Screen(p.x).toInt)
-      ps.setInt(i*2+1, map.view.y2Screen(p.y).toInt)
+      ps.setX(i, map.view.x2Screen(p.x).toInt)
+      ps.setY(i, map.view.y2Screen(p.y).toInt)
     }
-    k := n*2
-    ps.setInt(k, x)
-    ps.setInt(k+1, y)
+    k := n
+    ps.setX(k, x)
+    ps.setY(k, y)
     first := lse.first
-    ps.setInt(k+2, map.view.x2Screen(first.x).toInt)
-    ps.setInt(k+3, map.view.y2Screen(first.y).toInt)
+    ps.setX(k+1, map.view.x2Screen(first.x).toInt)
+    ps.setY(k+1, map.view.y2Screen(first.y).toInt)
     return ps
   }
 }

chunmap/ctrl/fan/tools/create/LineTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
-using array
+using fgfx2d
 
 using chunmapModel
 
     map.paintOnBuffer |g|
     {
       map.drawOriginImage(g, 0, 0)
-      g.drawPolyline2(toIntArray(e.x, e.y))
+      g.drawPolyline(toIntArray(e.x, e.y))
     }
     e.consumed = true
     map.repaint
   }
 
-  protected virtual Array toIntArray(Int x, Int y)
+  protected virtual PointArray toIntArray(Int x, Int y)
   {
-    ps := Array.allocate((lse.size+1) * 2)
+    ps := PointArray((lse.size+1))
     n := lse.size
     i:=0
-
     for (; i<n; ++i)
     {
       p := lse.get(i)
-      ps.setInt(i*2, map.view.x2Screen(p.x).toInt)
-      ps.setInt((i*2)+1, map.view.y2Screen(p.y).toInt)
+      ps.setX(i, map.view.x2Screen(p.x).toInt)
+      ps.setY(i, map.view.y2Screen(p.y).toInt)
     }
-    k := n*2
-    ps.setInt(k, x)
-    ps.setInt(k+1, y)
+    k := n
+    ps.setX(k, x)
+    ps.setY(k, y)
     return ps
   }
 

chunmap/ctrl/fan/tools/create/PointTool.fan

 //   2011-10-29  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 
 using chunmapModel
 

chunmap/ctrl/fan/tools/edit/EditLineNodeTool.fan

 //   2012-05-12  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil
 using chunmapView
 using slanData
-using array
 using chunmapModel::Point as CPoint
 
 **
       map.paintOnBuffer |g|
       {
         map.drawOriginImage(g, 0, 0)
-        g.drawPolyline2(toIntArray(coordSeqBuf))
+        g.drawPolyline(toIntArray(coordSeqBuf))
       }
       e.consumed = true
       map.repaint
     }
   }
 
-  protected virtual Array toIntArray(CoordSeqBuf coordSeqBuf)
+  protected virtual PointArray toIntArray(CoordSeqBuf coordSeqBuf)
   {
-    ps := Array.allocate((coordSeqBuf.size) * 2)
+    ps := PointArray((coordSeqBuf.size))
     n := coordSeqBuf.size
     i:=0
     for (; i<n; ++i)
     {
       p := coordSeqBuf.get(i)
-      ps.setInt(i*2, map.view.x2Screen(p.x).toInt)
-      ps.setInt((i*2)+1, map.view.y2Screen(p.y).toInt)
+      ps.setX(i, map.view.x2Screen(p.x).toInt)
+      ps.setY(i, map.view.y2Screen(p.y).toInt)
     }
     return ps
   }

chunmap/ctrl/fan/tools/edit/EditPointTool.fan

 //   2012-05-12  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil
 using chunmapView
 using slanData
-using array
 
 **
 ** Edit the point geometry

chunmap/ctrl/fan/tools/edit/EditTool.fan

 //   2012-05-12  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 using chunmapModel
 using chunmapData
 using chunmapUtil
 using chunmapView
 using slanData
-using array
 
 **
 ** Edit the node of geometry

chunmap/ctrl/fan/tools/navigate/BoxZoomInTool.fan

 //   2011-05-05  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 
 using chunmapModel
 

chunmap/ctrl/fan/tools/navigate/PanTool.fan

 //   2011-05-05  Jed Young  Creation
 //
 
-using fan3dTouch
-using gfx
+using fgfx2d
+using fgfxWtk
 
 **
 ** Tool

chunmap/ctrl/fan/tools/navigate/TouchZoomTool.fan

 //   2011-05-05  Jed Young  Creation
 //
 
-using fan3dTouch
-using gfx
-using fan3dMath
+using fgfx2d
+using fgfxMath
+using fgfxWtk
 using chunmapModel
 
 **
   {
     if (ce.id != CEvent.touchEvent) return
 
-    MotionEvent e := ce.rawEvent
-    if (e.count == 2)
+    MotionEvent? e := ce.rawEvent as MotionEvent
+    if (e == null || e.pointers == null) return
+    if (e.pointers.size == 2)
     {
-      if (!e.isMove(0) && !e.isMove(1))
+      if (!(e.pointers[0].id == MotionEvent.moved) && !(e.pointers[1].id == MotionEvent.moved))
       {
-        if (lastDis < 0f) startZoom(e)
+        if (lastDis < 0f) startZoom(e.pointers)
         else endZoom(e)
         e.consumed = true
       }
       else
       {
-        multiTouchZoom(e)
+        multiTouchZoom(e.pointers)
         e.consumed = true
       }
     }
   }
 
-  private Void startZoom(MotionEvent e)
+  private Void startZoom(MotionEvent[] e)
   {
-    p1 := e.pos(0)
-    p2 := e.pos(1)
+    p1_x := e[0].x
+    p1_y := e[0].y
+    p2_x := e[1].x
+    p2_y := e[1].y
 
     //distance
-    d1 := (p1.x - p2.x).pow(2).toFloat
-    d2 := (p1.y - p2.y).pow(2).toFloat
+    d1 := (p1_x - p2_x).pow(2).toFloat
+    d2 := (p1_y - p2_y).pow(2).toFloat
     startDis = (d1 + d2).sqrt
 
     //center point
-    startX = (p1.x + p2.x)/2f
-    startY = (p1.y + p2.y)/2f
+    startX = (p1_x + p2_x)/2f
+    startY = (p1_y + p2_y)/2f
   }
 
   private Void endZoom(MotionEvent e)
     reset
   }
 
-  private Void multiTouchZoom(MotionEvent e)
+  private Void multiTouchZoom(MotionEvent[] e)
   {
-    p1 := e.pos(0)
-    p2 := e.pos(1)
+    p1_x := e[0].x
+    p1_y := e[0].y
+    p2_x := e[1].x
+    p2_y := e[1].y
 
     //distance
-    d1 := (p1.x - p2.x).pow(2).toFloat
-    d2 := (p1.y - p2.y).pow(2).toFloat
+    d1 := (p1_x - p2_x).pow(2).toFloat
+    d2 := (p1_y - p2_y).pow(2).toFloat
     lastDis = (d1 + d2).sqrt
 
     //scale

chunmap/ctrl/fan/tools/navigate/ZoomTool.fan

 //   2011-05-05  Jed Young  Creation
 //
 
-using gfx
+using fgfx2d
 
 **
 ** ZoomTool

chunmap/view/fan/CMap.fan

   ** map data
   LayerList layers := LayerList()
 
+  Size size
+
   new make(Size size, Int xBuffer := 0, Int yBuffer := 0)
   {
     this.xBuffer = xBuffer
     this.yBuffer = yBuffer
     view = ViewPort(size.w, size.h, (xBuffer+1).toFloat, (yBuffer+1).toFloat)
     image = BufImage(Size(size.w + xBuffer + xBuffer, size.h + yBuffer + yBuffer))
+    this.size = size
   }
 
 //////////////////////////////////////////////////////////////////////////
     this.yBuffer = yBuffer
     view.resetSize(size.w, size.h, (xBuffer+1).toFloat, (yBuffer+1).toFloat)
     image = BufImage(Size(size.w + xBuffer + xBuffer, size.h + yBuffer + yBuffer))
+    this.size = size
   }
 }

chunmapx/frame/build.fan

       "sys 1.0",
       "fwt 1.0",
       "gfx 1.0",
-      "gfx2 1.0",
+      "fgfxFwt 1.0",
       "concurrent 1.0",
       "slanData 1.0",
-      "gfx2Imp 1.0",
       "chunmapView 1.0",
       "chunmapModel 1.0",
       "chunmapRaster 1.0",

chunmapx/frame/fan/Frame.fan

 
 using fwt
 using gfx
-using gfx2
-using gfx2Imp
+using fgfxFwt
 using concurrent
 
 using chunmapCtrl
 
   new make() : super()
   {
+    FwtToolkitEnv.init
     mapCanvas := MapCanvas()
     mapCtrl = mapCanvas.ctrl
     title = "Chunmap"

chunmapx/frame/fan/Main.fan

 {
   static Void main(Str[] args)
   {
-    if (!args.isEmpty && args[0] == "frame")
-    {
-      Frame().open
-    }
+    Frame().open
   }
 }

example/GeometryTest.fan

 
 using fwt
 using gfx
-using gfx2
-using gfx2Imp
+using fgfxFwt
 
 using chunmapCtrl
 using chunmapModel
   Void main()
   {
     //Gfx2.setEngine("AWT")
+    FwtToolkitEnv.init
 
     map := MapCanvas()
 

example/Projection.fan

 
 using fwt
 using gfx
-using gfx2
-using gfx2Imp
+using fgfxFwt
 
 using chunmapCtrl
 using chunmapModel
 {
   Void main()
   {
+    FwtToolkitEnv.init
+
     map := MapCanvas()
 
     layer0 := VectorLayer.makeUri((this.typeof->sourceFile.toStr.toUri + `data/cntry02/cntry02.shp`))

example/Raster.fan

 using concurrent
 using fwt
 using gfx
-using gfx2
-using gfx2Imp
+using fgfxFwt
 
 using chunmapCtrl
 using chunmapModel
 
   Void main()
   {
+    FwtToolkitEnv.init
     map := MapCanvas()
 
     uri := `http://localhost:8080/chunmapService/test`

example/Shape.fan

 
 using fwt
 using gfx
-using gfx2
-using gfx2Imp
+using fgfxFwt
 
 using chunmapCtrl
 using chunmapModel
   Void main()
   {
     //Gfx2.setEngine("AWT")
+    FwtToolkitEnv.init
 
     map := MapCanvas()
 

example/TouchMap.fan

 //   2011-05-03  Jed Young  Creation
 //
 
-using fan3dTouch
 using gfx
-using gfx2
-using gfx2Imp
+using fgfxWtk
+using fgfxFwt
 
 using chunmapModel
 using chunmapView
 {
   Void main()
   {
-    Gfx2.setEngine("SWT")
-    Actor.locals["fan3dTouch.NativeViewFactory"] = FwtViewFactory()
+    //Gfx2.setEngine("SWT")
+    FwtToolkitEnv.init
 
-    map := MapWidget
-    {
-      size = Size(900,600)
-    }
+    map := MapWidget()
+    window := Toolkit.cur.build
+    window.add(map)
 
     layer0 := VectorLayer.makeUri((this.typeof->sourceFile.toStr.toUri + `data/cntry02/cntry02.shp`))
     map.ctrl.layers.add(layer0)
     map.ctrl.layers.add(layer1)
 
     map.ctrl.fullView
+    map.ctrl.renderMap
     map.ctrl.setCurrentTool(PanTool())
 
+/*
     zoomIn := Button
     {
       it.onAction.add |e|
       pos = gfx::Point(70, 10)
       text = "-"
     }
+*/
 
-    map.add(zoomIn)
-    map.add(zoomOut)
-
-    View
-    {
-      size = Size(900,600)
-      doubleBuffer
-      map,
-    }.show
+    window.show(fgfx2d::Size(900,600))
   }
 }