123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- deferred class CD_CANVAS_WORLD_COORDINATES
- -- Allows the use of a World Coordinate System. In this system you can
- -- attribute coordinates to any unit you want. After you define a window
- -- (rectangular region) in your world, each given coordinate is then mapped to
- -- canvas coordinates to draw the primitives. You can define a viewport in your
- -- canvas to change the coordinate mapping from world to canvas.
- --
- -- If you want to map coordinates from one system to another, use the
- -- "wd_world_to_canvas" e "wd_canvas_to_world" functions.
- --
- -- The quality of the picture depends on the conversion from World to Canvas,
- -- so if the canvas has a small size the picture quality will be poor. To
- -- increase picture quality create a canvas with a larger size, if possible.
- --
- -- All World Coordinate drawing in all drivers are simulated using other CD
- -- primitives and do NOT depend or use the "set_transform" transformation
- -- matrix.
- inherit
- CANVAS_DRAW
- feature {ANY}
- set_window (xmin, xmax, ymin, ymax: REAL_64)
- -- Configures a window in the world coordinate system to be used to
- -- convert world coordinates (with values in real numbers) into canvas
- -- coordinates (with values in integers). The default window is the size
- -- in millimeters of the whole canvas.
- do
- int_wd_canvas_window(cnvs, xmin, xmax, ymin, ymax)
- end
- get_window: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
- -- Queries the current window in the world coordinate system being
- -- used to convert world coordinates into canvas coordinates (and the
- -- other way round).
- local
- xmin, xmax, ymin, ymax: REAL_64
- do
- int_wd_canvas_get_window(cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- set_viewport (xmin, xmax, ymin, ymax: INTEGER)
- -- Configures a viewport in the canvas coordinate system to be used to
- -- convert world coordinates (with values in real numbers) into canvas
- -- coordinates (with values in integers). The default viewport is the
- -- whole canvas (0,w-1,0,h-1). If the canvas size is changed, the
- -- viewport will not be automatically updated.
- do
- int_wd_canvas_viewport(cnvs, xmin, xmax, ymin, ymax)
- end
- get_viewport: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
- -- Queries the current viewport in the world coordinate system being used
- -- to convert world coordinates into canvas coordinates (and the other
- -- way round).
- local
- xmin, xmax, ymin, ymax: INTEGER
- do
- int_wd_canvas_get_viewport(cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- world_to_canvas (xw, yw: REAL_64): TUPLE[INTEGER, INTEGER]
- -- Converts world coordinates into canvas coordinates.
- local
- xv, yv: INTEGER
- do
- int_wd_canvas_world_to_canvas(cnvs, xw, yw, $xv, $yv)
- Result := [xv, yv]
- end
- canvas_to_world (xv, yv: INTEGER): TUPLE[REAL_64, REAL_64]
- -- Converts canvas coordinates into world coordinates.
- local
- xw, yw: REAL_64
- do
- int_wd_canvas_canvas_to_world(cnvs, xv, yv, $xw, $yw)
- Result := [xw, yw]
- end
- set_wd_transform (sx, sy, tx, ty: REAL_64)
- -- Configures the world coordinate system transformation to be used to
- -- convert world coordinates (with values in real numbers) into canvas
- -- coordinates (with values in integers). The transformation is
- -- automatically set by "set_window" and "set_viewport". This has NO
- -- relation with "set_transform".
- do
- int_wd_canvas_set_transform(cnvs, sx, sy, tx, ty)
- end
- get_wd_transform: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
- -- Queries the current transformation being used to convert world
- -- coordinates into canvas coordinates (and the other way round).
- local
- sx, sy, tx, ty: REAL_64
- do
- int_wd_canvas_get_transform(cnvs, $sx, $sy, $tx, $ty)
- Result := [sx, sy, tx, ty]
- end
- set_wd_translate (dtx, dty: REAL_64)
- -- Translates the transformation by a delta, by adding the given values
- -- to the current tx and ty values.
- do
- int_wd_canvas_translate(cnvs, dtx, dty)
- end
- set_wd_scale (dsx, dsy: REAL_64)
- -- Scales the transformation by a delta, by multiplying the given values
- -- by the current sx and sy values.
- do
- int_wd_canvas_scale(cnvs, dsx, dsy)
- end
- -- Extra
- wd_hard_copy
- do
- -- Not sure how add this feature.
- end
- feature {NONE}
- int_wd_canvas_window (wgt: POINTER; xmin, xmax, ymin, ymax: REAL_64)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasWindow ($wgt, $xmin, $xmax, $ymin, $ymax);"
- end
- int_wd_canvas_get_window (wgt, xmin, xmax, ymin, ymax: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasGetWindow ($wgt, $xmin, $xmax, $ymin, $ymax);"
- end
- int_wd_canvas_viewport (wgt: POINTER; xmin, xmax, ymin, ymax: INTEGER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasViewport ($wgt, $xmin, $xmax, $ymin, $ymax);"
- end
- int_wd_canvas_get_viewport (wgt, xmin, xmax, ymin, ymax: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasGetViewport ($wgt, $xmin, $xmax, $ymin, $ymax);"
- end
- int_wd_canvas_world_to_canvas (wgt: POINTER; xw, yw: REAL_64; xv, yv: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasWorld2Canvas ($wgt, $xw, $yw, $xv, $yv);"
- end
- int_wd_canvas_canvas_to_world (wgt: POINTER; xv, yv: INTEGER; xw, yw: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasCanvas2World ($wgt, $xv, $yv, $xw, $yw);"
- end
- int_wd_canvas_set_transform (wgt: POINTER; sx, sy, tx, ty: REAL_64)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasSetTransform ($wgt, $sx, $sy, $tx, $ty);"
- end
- int_wd_canvas_get_transform (wgt, sx, sy, tx, ty: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasGetTransform ($wgt, $sx, $sy, $tx, $ty);"
- end
- int_wd_canvas_translate (wgt: POINTER; dtx, dty: REAL_64)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasTranslate ($wgt, $dtx, $dty);"
- end
- int_wd_canvas_scale (wgt: POINTER; dsx, dsy: REAL_64)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasScale ($wgt, $dsx, $dsy);"
- end
- end
- -- The MIT License (MIT)
- -- Copyright (c) 2017, 2019 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.
|