123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- deferred class CD_CLIPPING
- -- The clipping area is an area that limits the available drawing area inside
- -- the canvas. Any primitive is drawn only inside the clipping area. It affects
- -- all primitives.
- --
- -- You can set the clipping area by using the feature "set_clip_area", and
- -- retrieve it using "get_clip_area". The clipping area is a rectangle by
- -- default, but it can has other shapes. In some drivers a polygon area can be
- -- defined, and in display based drivers a complex region can be defined. The
- -- complex region can be a combination of boxes, polygons, sectors, chords and
- -- texts.
- --
- -- The Clip function activates and deactivaes the clipping.
- inherit
- CANVAS_DRAW
- feature {ANY}
- set_clipping_mode (mode: STRING)
- -- Activates or deactivates clipping. Values: CD_CLIPAREA,
- -- CD_CLIPPOLYGON, CD_CLIPREGION or CD_CLIPOFF. Default value: CD_CLIPOFF.
- --
- -- The value CD_CLIPAREA activates a rectangular area as the clipping
- -- region.
- --
- -- The value CD_CLIPPOLYGON activates a polygon as a clipping region, but
- -- works only in some drivers (please refer to the notes of each driver).
- -- The clipping polygon must be defined before activating the polygon
- -- clipping; if it is not defined, the current clipping state remains
- -- unchanged.
- --
- -- The value CD_CLIPREGION activates a complex clipping region. See the
- -- documentation of Regions.
- --
- -- The defined clipping area, polygon and complex regions are stored
- -- internally, so you may define them independently and switch between
- -- area, polygon and complex region without having to define them again.
- -- Also if the active clipping region is re-defined it immediately
- -- becomes the current clipping region.
- require
- is_valid_clipping_mode(mode)
- local
- i: INTEGER
- do
- if mode.is_equal("CD_CLIPOFF") then
- i := int_canvas_clip (cnvs, 0)
- elseif mode.is_equal("CD_CLIPAREA") then
- i := int_canvas_clip (cnvs, 1)
- elseif mode.is_equal("CD_CLIPPOLYGON") then
- i := int_canvas_clip (cnvs, 2)
- elseif mode.is_equal("CD_CLIPREGION") then
- i := int_canvas_clip (cnvs, 3)
- else
- i := int_canvas_clip (cnvs, 0)
- end
- end
- get_clipping_mode: STRING
- local
- i: INTEGER
- do
- i := int_canvas_clip (cnvs, -1)
- if i.is_equal(0) then
- Result := "CD_CLIPOFF"
- elseif i.is_equal(1) then
- Result := "CD_CLIPAREA"
- elseif i.is_equal(2) then
- Result := "CD_CLIPPOLYGON"
- elseif i.is_equal(3) then
- Result := "CD_CLIPREGION"
- else
- Result := "CD_CLIPOFF"
- end
- end
- set_clip_area (xmin, xmax, ymin, ymax: INTEGER)
- -- Defines the current rectangle for clipping. Only the points in the
- -- interval xmin<= x <= xmax and ymin <= y <= ymax will be printed.
- -- Default region: (0, w-1, 0, h-1).
- do
- int_canvas_clip_area (cnvs, xmin, xmax, ymin, ymax)
- end
- set_clip_area_real (xmin, xmax, ymin, ymax: REAL_64)
- -- Like "set_clip_area" but using REAL_64 values.
- do
- int_canvas_c_double_clip_area (cnvs, xmin, xmax, ymin, ymax)
- end
- set_wd_clip_area (xmin, xmax, ymin, ymax: REAL_64)
- -- Like "set_clip_area" but using World Coordinates.
- do
- int_wd_canvas_clip_area (cnvs, xmin, xmax, ymin, ymax)
- end
- get_clip_area: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
- local
- xmin, xmax, ymin, ymax: INTEGER
- do
- int_canvas_get_clip_area (cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- get_clip_area_real: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
- local
- xmin, xmax, ymin, ymax: REAL_64
- do
- int_canvas_c_double_get_clip_area (cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- get_wd_clip_area: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
- local
- xmin, xmax, ymin, ymax: REAL_64
- do
- int_wd_canvas_get_clip_area (cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- -- Validations
- is_valid_clipping_mode (mode: STRING): BOOLEAN
- do
- if mode.is_equal("CD_CLIPAREA") or
- mode.is_equal("CD_CLIPPOLYGON") or
- mode.is_equal("CD_CLIPREGION") or
- mode.is_equal("CD_CLIPOFF") then
- Result := True
- else
- Result := False
- end
- end
- feature {NONE}
-
- -- Internals
- int_canvas_clip (wgt: POINTER; m: INTEGER): INTEGER
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "return cdCanvasClip ($wgt, $m);"
- end
- int_canvas_clip_area (wgt: POINTER; x1, x2, y1, y2: INTEGER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "cdCanvasClipArea ($wgt, $x1, $x2, $y1, $y2);"
- end
- int_canvas_c_double_clip_area (wgt: POINTER; x1, x2, y1, y2: REAL_64)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "cdfCanvasClipArea ($wgt, $x1, $x2, $y1, $y2);"
- end
- int_wd_canvas_clip_area (wgt: POINTER; x1, x2, y1, y2: REAL_64)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasClipArea ($wgt, $x1, $x2, $y1, $y2);"
- end
- int_canvas_get_clip_area (wgt, x1, x2, y1, y2: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "cdCanvasGetClipArea ($wgt, $x1, $x2, $y1, $y2);"
- end
- int_canvas_c_double_get_clip_area (wgt, x1, x2, y1, y2: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "cdfCanvasGetClipArea ($wgt, $x1, $x2, $y1, $y2);"
- end
- int_wd_canvas_get_clip_area (wgt, x1, x2, y1, y2: POINTER)
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "wdCanvasGetClipArea ($wgt, $x1, $x2, $y1, $y2);"
- 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.
|