28 de septiembre de 2015

Dibujando polígonos con VFP 9.0

Ahora con Visual FoxPro 9.0 podemos dibujar polígonos con un objeto Shape y la nueva propiedad PolyPoints.

La propiedad PolyPoints especifica el nombre de una matriz que contiene las coordenadas para crear formas poligonales usando el control Shape. La matriz debe estar en el alcance del objeto Shape para que el polígono sea dibujado.

Las cordenadas son de la forma (X,Y). Las coordenadas especificadas son porcentajes relativos a las dimensiones del control Shape. La coordenada (0,0) corresponde al ángulo superior izquierdo del objeto Shape, como se muestra en la gráfica. El polígono se dibujará en el orden que estas coordenadas aparezcan en la matriz.



A continuación el código de un formulario de ejemplo con dos polígonos dibujados.

PUBLIC goForm
goForm = CREATEOBJECT("MiForm")
goForm.SHOW(1)
RETURN

DEFINE CLASS MiForm AS FORM
  DOCREATE = .T.
  AUTOCENTER = .T.
  CAPTION = "Dibujando polígonos con VFP 9.0"
  NAME = "MiForm"
  *-- Triángulo
  ADD OBJECT shpTriangulo AS SHAPE WITH ;
    TOP = 36, ;
    LEFT = 24, ;
    HEIGHT = 144, ;
    WIDTH = 144, ;
    BACKCOLOR = RGB(255,0,0), ;
    POLYPOINTS = "This.aTri", ;
    NAME = "shpTriangulo"
  *-- Octógono
  ADD OBJECT shpOctogono AS SHAPE WITH ;
    TOP = 36, ;
    LEFT = 204, ;
    HEIGHT = 144, ;
    WIDTH = 144, ;
    BACKCOLOR = RGB(0,0,255), ;
    POLYPOINTS = "This.aOct", ;
    NAME = "shpOctogono"
  PROCEDURE shpTriangulo.INIT
    THIS.ADDPROPERTY("aTri[3,2]")
    THIS.aTri[1,1]= 50
    THIS.aTri[1,2]= 0
    THIS.aTri[2,1]= 100
    THIS.aTri[2,2]= 100
    THIS.aTri[3,1]= 0
    THIS.aTri[3,2]= 100
  ENDPROC
  PROCEDURE shpOctogono.INIT
    THIS.ADDPROPERTY("aOct[8,2]")
    THIS.aOct[1,1]= 33
    THIS.aOct[1,2]= 0
    THIS.aOct[2,1]= 67
    THIS.aOct[2,2]= 0
    THIS.aOct[3,1]= 100
    THIS.aOct[3,2]= 33
    THIS.aOct[4,1]= 100
    THIS.aOct[4,2]= 67
    THIS.aOct[5,1]= 67
    THIS.aOct[5,2]= 100
    THIS.aOct[6,1]= 33
    THIS.aOct[6,2]= 100
    THIS.aOct[7,1]= 0
    THIS.aOct[7,2]= 67
    THIS.aOct[8,1]= 0
    THIS.aOct[8,2]= 33
  ENDPROC
ENDDEFINE
Luis María Guayán

1 comentario :

  1. Un ejemplo mas completo que cambia la altura de las formas, pero no el porcentaje de sus coordenadas:

    PUBLIC goForm
    goForm = CREATEOBJECT("MiForm")
    goForm.SHOW(1)
    RETURN

    DEFINE CLASS MiForm AS FORM

    DOCREATE = .T.
    AUTOCENTER = .T.
    CAPTION = "Dibujando polígonos con VFP 9.0"
    NAME = "MiForm"
    WIDTH = 800
    HEIGHT = 400

    *-- Triángulo
    ADD OBJECT shpTriangulo AS SHAPE WITH ;
    TOP = 36, ;
    LEFT = 24, ;
    HEIGHT = 144, ;
    WIDTH = 144, ;
    BACKCOLOR = RGB(255,0,0), ;
    POLYPOINTS = "This.aTri", ;
    NAME = "shpTriangulo"

    *-- Octógono
    ADD OBJECT shpOctogono AS SHAPE WITH ;
    TOP = 36, ;
    LEFT = 204, ;
    HEIGHT = 144, ;
    WIDTH = 144, ;
    BACKCOLOR = RGB(0,0,255), ;
    POLYPOINTS = "This.aOct", ;
    NAME = "shpOctogono"

    *-- Estrella
    ADD OBJECT shpStar AS SHAPE WITH ;
    TOP = 36, ;
    LEFT = 400, ;
    HEIGHT = 144, ;
    WIDTH = 144, ;
    BACKCOLOR = RGB(0,255,0), ;
    POLYPOINTS = "This.aStar", ;
    NAME = "shpStar"

    *-- Spinner
    ADD OBJECT SpnPorc AS SPINNER WITH ;
    TOP = 36, ;
    LEFT = 600, ;
    NAME = "SpnPorc", ;
    VALUE = 100, ;
    INCREMENT = 5, ;
    SPINNERHIGHVALUE = 200, ;
    SPINNERLOWVALUE = 10

    PROCEDURE shpTriangulo.INIT
    THIS.ADDPROPERTY("aTri[3,2]")
    THIS.aTri[1,1]= 50
    THIS.aTri[1,2]= 0
    THIS.aTri[2,1]= 100
    THIS.aTri[2,2]= 100
    THIS.aTri[3,1]= 0
    THIS.aTri[3,2]= 100
    ENDPROC

    PROCEDURE shpOctogono.INIT
    THIS.ADDPROPERTY("aOct[8,2]")
    THIS.aOct[1,1]= 33
    THIS.aOct[1,2]= 0
    THIS.aOct[2,1]= 67
    THIS.aOct[2,2]= 0
    THIS.aOct[3,1]= 100
    THIS.aOct[3,2]= 33
    THIS.aOct[4,1]= 100
    THIS.aOct[4,2]= 67
    THIS.aOct[5,1]= 67
    THIS.aOct[5,2]= 100
    THIS.aOct[6,1]= 33
    THIS.aOct[6,2]= 100
    THIS.aOct[7,1]= 0
    THIS.aOct[7,2]= 67
    THIS.aOct[8,1]= 0
    THIS.aOct[8,2]= 33
    ENDPROC

    PROCEDURE shpStar.INIT
    THIS.ADDPROPERTY("aStar[12,2]")
    THIS.aStar[1,1] = 50
    THIS.aStar[1,2] = 0
    THIS.aStar[2,1] = 66
    THIS.aStar[2,2] = 25
    THIS.aStar[3,1] = 100
    THIS.aStar[3,2] = 25
    THIS.aStar[4,1] = 84
    THIS.aStar[4,2] = 50
    THIS.aStar[5,1] = 100
    THIS.aStar[5,2] = 75
    THIS.aStar[6,1] = 66
    THIS.aStar[6,2] = 75
    THIS.aStar[7,1] = 50
    THIS.aStar[7,2] = 100
    THIS.aStar[8,1] = 33
    THIS.aStar[8,2] = 75
    THIS.aStar[9,1] = 0
    THIS.aStar[9,2] = 75
    THIS.aStar[10,1] = 16
    THIS.aStar[10,2] = 50
    THIS.aStar[11,1] = 0
    THIS.aStar[11,2] = 25
    THIS.aStar[12,1] = 33
    THIS.aStar[12,2] = 25
    ENDPROC

    PROCEDURE SpnPorc.INTERACTIVECHANGE
    THISFORM.shpTriangulo.HEIGHT = 144 * THIS.VALUE / 100
    THISFORM.shpOctogono.HEIGHT = 144 * THIS.VALUE / 100
    THISFORM.shpStar.HEIGHT = 144 * THIS.VALUE / 100
    ENDPROC

    ENDDEFINE

    ResponderEliminar