123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- deferred class CD_CANVAS_COORDINATE_SYSTEM
- inherit
- CANVAS_DRAW
- feature {ANY}
- get_size_pixels: TUPLE[INTEGER, INTEGER]
- -- Returns the canvas size in pixels.
- local
- p: POINTER
- ix, iy: INTEGER
- tup: TUPLE[INTEGER, INTEGER]
- do
- int_canvas_get_size(cnvs, $ix, $iy, p, p)
- tup := [ix, iy]
- Result := tup
- end
- get_size_millimeters: TUPLE[REAL_64, REAL_64]
- -- Returns the canvas size in millimeters.
- local
- p: POINTER
- ix, iy: REAL_64
- tup: TUPLE[REAL_64, REAL_64]
- do
- int_canvas_get_size(cnvs, p, p, $ix, $iy)
- tup := [ix, iy]
- Result := tup
- end
- update_y_axis (y: INTEGER): INTEGER
- -- Invert the given Y coordinate if the native Y axis orientation is
- -- different from the CD axis orientation. The CD axis orientation is
- -- always bottom-top.
- local
- yc: INTEGER
- do
- yc := y
-
- Result := int_canvas_update_y_axis(cnvs, $yc)
- end
- invert_y_axis (y: INTEGER): INTEGER
- -- Invert the given Y coordinate independent of the driver Y axis
- -- orientation.
- do
- Result := int_canvas_invert_y_axis(cnvs, y)
- end
- convert_mm_to_pixels (mmx, mmy: REAL_64): TUPLE[INTEGER, INTEGER]
- -- Converts sizes in millimeters into pixels (canvas coordinates).
- -- Return integer values.
- local
- px, py: INTEGER
- tup: TUPLE[INTEGER, INTEGER]
- do
- int_canvas_mm_to_pixels(cnvs, mmx, mmy, $px, $py)
- tup := [px, py]
- Result := tup
- end
- convert_mm_to_pixels_real (mmx, mmy: REAL_64): TUPLE[REAL_64, REAL_64]
- -- Converts sizes in millimeters into pixels (canvas coordinates).
- -- Return real 64 values.
- local
- px, py: REAL_64
- tup: TUPLE[REAL_64, REAL_64]
- do
- int_canvas_c_double_mm_to_pixels(cnvs, mmx, mmy, $px, $py)
- tup := [px, py]
- Result := tup
- end
- convert_pixels_to_mm (px, py: INTEGER): TUPLE[REAL_64, REAL_64]
- -- Converts sizes in pixels (canvas coordinates as integer values) into
- -- millimeters. Use this function to obtain the horizontal and vertical
- -- resolution of the canvas by passing 1 as parameter in dx and dy. The
- -- resolution value is obtained using the formula res=1.0/mm.
- local
- mmx, mmy: REAL_64
- tup: TUPLE[REAL_64, REAL_64]
- do
- int_canvas_pixels_to_mm(cnvs, px, py, $mmx, $mmy)
- tup := [mmx, mmy]
- Result := tup
- end
- convert_pixels_to_mm_real (px, py: REAL_64): TUPLE[REAL_64, REAL_64]
- -- Converts sizes in pixels (canvas coordinates as real 64 values) into
- -- millimeters. Use this function to obtain the horizontal and vertical
- -- resolution of the canvas by passing 1 as parameter in dx and dy. The
- -- resolution value is obtained using the formula res=1.0/mm.
- local
- mmx, mmy: REAL_64
- tup: TUPLE[REAL_64, REAL_64]
- do
- int_canvas_c_double_pixels_to_mm(cnvs, px, py, $mmx, $mmy)
- tup := [mmx, mmy]
- Result := tup
- end
- set_origin (x, y: INTEGER)
- -- Allows translating the origin - for instance, to the center of the
- -- canvas. The function profits from the architecture of the library to
- -- simulate a translation of the origin, which in fact is never actually
- -- passed to the canvas in the respective driver. It is not related with
- -- WD nor Transformation Matrix. Default values: (0, 0)
- do
- int_canvas_origin(cnvs, x, y)
- end
- set_origin_real (x, y: REAL_64)
- -- As "set_origin" but the parematers are real 64 values.
- do
- int_canvas_c_double_origin(cnvs, x, y)
- end
- get_origin: TUPLE[INTEGER, INTEGER]
- -- Return the origin as integer values.
- local
- x, y: INTEGER
- do
- int_canvas_get_origin(cnvs, $x, $y)
- Result := [x, y]
- end
- get_origin_real: TUPLE[REAL_64, REAL_64]
- -- Return the origin as real 64 values.
- local
- x, y: REAL_64
- do
- int_canvas_c_double_get_origin(cnvs, $x, $y)
- Result := [x, y]
- end
- -- Transformation matrix
- set_transform (matrix: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64, REAL_64, REAL_64])
- -- Defines a transformation matrix with 6 elements. If the matrix is
- -- Void, the transformation is reset to the identity. Default value: Void.
- --
- -- The matrix contains scale (sx,sy), rotation (angle) and translation
- -- (dx,dy) elements as follows:
- --
- -- matrix[0] = sx*cos(angle) // Horizontal Scale and Rotation component
- -- matrix[1] = sin(angle) // Rotation component (can also contain an
- -- horizontal shear component)
- -- matrix[2] = -sin(angle) // Rotation component (can also contain a
- -- vertical shear component)
- -- matrix[3] = sy*cos(angle) // Vertical Scale and Rotation component
- -- matrix[4] = dx // Horizontal Translation component
- -- matrix[5] = dy // Vertical Translation component
- --
- -- Functions that retrieve images from the canvas are not affected by the
- -- transformation matrix, such as "get_image", "get_image_rgb" and
- -- "scroll_area".
- --
- -- Transformation matrix is independent of the World Coordinate and
- -- Origin functions. And those are affected if a transformation is set,
- -- just like other regular primitives.
- --
- -- The transformation matrix and world coordinates perform similar
- -- functions. World coordinates were developed before the transformation
- -- matrix support. The transformation matrix operates at a lower level
- -- than world coordinates, and, as such, might be faster, but might
- -- behave differently on different platforms. World coordinates behave
- -- consistently across platforms.
- local
- m: NATIVE_ARRAY[REAL_64]
- do
- m := m.calloc(6)
- m.put(matrix.item_1, 0)
- m.put(matrix.item_1, 1)
- m.put(matrix.item_1, 2)
- m.put(matrix.item_1, 3)
- m.put(matrix.item_1, 4)
- m.put(matrix.item_1, 5)
- int_canvas_transform(cnvs, m.to_external)
- end
- get_transform: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64, REAL_64, REAL_64]
- -- Returns the transformation matrix. If the identity is set,
- -- returns Void.
- local
- p: POINTER
- m: NATIVE_ARRAY[REAL_64]
- do
- p := int_canvas_get_transform(cnvs)
- if p.is_not_null then
- m := m.calloc(6)
- m := m.from_pointer(p)
- Result := [m.item(0), m.item(1), m.item(2), m.item(3), m.item(4), m.item(5)]
- end
- end
- apply_transform_multiply (matrix: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64])
- -- Left multiply the current transformation by the given transformation.
- local
- m: NATIVE_ARRAY[REAL_64]
- do
- m := m.calloc(4)
- m.put(matrix.item_1, 0)
- m.put(matrix.item_1, 1)
- m.put(matrix.item_1, 2)
- m.put(matrix.item_1, 3)
- int_canvas_transform_multiply(cnvs, m.to_external)
- end
- apply_transform_translate (dx, dy: REAL_64)
- -- Applies a translation to the current transformation.
- do
- int_canvas_transform_translate(cnvs, dx, dy)
- end
- apply_transform_scale (sx, sy: REAL_64)
- -- Applies a scale to the current transformation.
- do
- int_canvas_transform_scale(cnvs, sx, sy)
- end
- apply_transform_rotate (angle: REAL_64)
- -- Applies a rotation to the current transformation. Angle is in degrees,
- -- oriented counter-clockwise from the horizontal axis.
- do
- int_canvas_transform_rotate(cnvs, angle)
- end
- transform_point (x, y: INTEGER): TUPLE[INTEGER, INTEGER]
- -- Applies a transformation to a given point.
- local
- tx, ty: INTEGER
- do
- int_canvas_transform_point(cnvs, x, y, $tx, $ty)
- Result := [tx, ty]
- end
- transform_point_real (x, y: REAL_64): TUPLE[REAL_64, REAL_64]
- -- Like "transform_point" but with REAL_64 values.
- local
- tx, ty: REAL_64
- do
- int_canvas_c_double_transform_point(cnvs, x, y, $tx, $ty)
- Result := [tx, ty]
- end
- feature {}
- int_canvas_get_size (wgt: POINTER; x, y, xm, ym: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasGetSize"
- }"
- end
- int_canvas_update_y_axis (wgt, y: POINTER): INTEGER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasUpdateYAxis"
- }"
- end
- int_canvas_invert_y_axis (wgt: POINTER; yc: INTEGER): INTEGER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasInvertYAxis"
- }"
- end
- int_canvas_mm_to_pixels (wgt: POINTER; mm_x, mm_y: REAL_64; cx, cy: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasMM2Pixel"
- }"
- end
- int_canvas_c_double_mm_to_pixels (wgt: POINTER; mm_x, mm_y: REAL_64; cx, cy: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdfCanvasMM2Pixel"
- }"
- end
- int_canvas_pixels_to_mm (wgt: POINTER; p_x, p_y: INTEGER; cx, cy: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasPixel2MM"
- }"
- end
- int_canvas_c_double_pixels_to_mm (wgt: POINTER; p_x, p_y: REAL_64; cx, cy: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdfCanvasPixel2MM"
- }"
- end
- int_canvas_origin (wgt: POINTER; x, y: INTEGER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasOrigin"
- }"
- end
- int_canvas_c_double_origin (wgt: POINTER; x, y: REAL_64)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdfCanvasOrigin"
- }"
- end
- int_canvas_get_origin (wgt, x, y: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasGetOrigin"
- }"
- end
- int_canvas_c_double_get_origin (wgt, x, y: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdfCanvasGetOrigin"
- }"
- end
- int_canvas_transform (wgt, m: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasTransform"
- }"
- end
- int_canvas_get_transform (wgt: POINTER): POINTER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasGetTransform"
- }"
- end
- int_canvas_transform_multiply (wgt, m: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasTransformMultiply"
- }"
- end
- int_canvas_transform_translate (wgt: POINTER; dx, dy: REAL_64)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasTransformTranslate"
- }"
- end
- int_canvas_transform_scale (wgt: POINTER; sx, sy: REAL_64)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasTransformScale"
- }"
- end
- int_canvas_transform_rotate (wgt: POINTER; ang: REAL_64)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasTransformRotate"
- }"
- end
- int_canvas_transform_point (wgt: POINTER; x, y: INTEGER; tx, ty: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasTransformPoint"
- }"
- end
- int_canvas_c_double_transform_point (wgt: POINTER; x, y: REAL_64; tx, ty: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdfCanvasTransformPoint"
- }"
- end
- end
- -- The MIT License (MIT)
- -- Copyright (c) 2016, 2017 by German A. Arias
- -- Permission is hereby granted, free of charge, to any person obtaining a copy
- -- of this software and associated documentation files (the "Software"), to deal
- -- in the Software without restriction, including without limitation the rights
- -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- -- copies of the Software, and to permit persons to whom the Software is
- -- furnished to do so, subject to the following conditions:
- --
- -- The above copyright notice and this permission notice shall be included in
- -- all copies or substantial portions of the Software.
- --
- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- -- SOFTWARE.
|