123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- deferred class CD_COMPLEX_CLIPPING_REGIONS
- -- A complex region can composed of boxes, sectors, chords, polygons and texts.
- -- It is implemented only in the Windows GDI, Windows GDI+, GDK, Cairo(*), and
- -- X-Windows base drivers.
- --
- -- Complex clipping regions can be created using
- -- "begin_region"/(filled primtives)/.../"end_polygon". For more about
- -- "begin_***" and "end_polygon" see Polygons.
- --
- -- Between a "begin_region" and a "end", all calls to "box", "sector", "chord",
- -- "begin_fill"/"vertex(x,y)"/.../"end_polygon" and Text will be composed in a
- -- region for clipping. This is the only exception when you can call a
- -- "begin_***" after another "begin_***".
- --
- -- When you call "begin_region" a new empty region will be created. So for the
- -- first operation you should use CD_UNION or CD_NOTINTERSECT combine modes.
- -- When you finished to compose the region call "end_polygon".
- --
- -- To make the region active you must call "clip_region". For other clipping
- -- regions see Clipping.
- --
- -- Although Cairo is capable of creating regions, you can not use them for
- -- clipping, just to use "is_point_in_region". And it can create only
- -- rectangle based regions, i.e. only "box" will actually combine rectangles
- -- into the region.
- --
- -- Complex clipping regions are not saved by "save_state".
- inherit
- CANVAS_DRAW
- feature {ANY}
- set_combine_mode (mode: STRING)
- -- Changes the way regions are combined when created. Values: CD_UNION,
- -- CD_INTERSECT, CD_DIFFERENCE or CD_NOTINTERSECT. Default
- -- value: CD_UNION.
- require
- is_valid_combine_mode (mode)
- local
- i: INTEGER
- do
- if mode.is_equal("CD_UNION") then
- i := int_canvas_region_combine_mode (cnvs, 0)
- elseif mode.is_equal("CD_INTERSECT") then
- i := int_canvas_region_combine_mode (cnvs, 1)
- elseif mode.is_equal("CD_DIFFERENCE") then
- i := int_canvas_region_combine_mode (cnvs, 2)
- elseif mode.is_equal("CD_NOTINTERSECT") then
- i := int_canvas_region_combine_mode (cnvs, 3)
- end
- end
- get_combine_mode: STRING
- local
- i: INTEGER
- do
- i := int_canvas_region_combine_mode (cnvs, -1)
- if i.is_equal(0) then
- Result := "CD_UNION"
- elseif i.is_equal(1) then
- Result := "CD_INTERSECT"
- elseif i.is_equal(2) then
- Result := "CD_DIFFERENCE"
- elseif i.is_equal(3) then
- Result := "CD_NOTINTERSECT"
- end
- end
- set_combine_mode_union
- local
- i: INTEGER
- do
- i := int_canvas_region_combine_mode (cnvs, 0)
- end
- set_combine_mode_intersect
- local
- i: INTEGER
- do
- i := int_canvas_region_combine_mode (cnvs, 1)
- end
- set_combine_mode_difference
- local
- i: INTEGER
- do
- i := int_canvas_region_combine_mode (cnvs, 2)
- end
- set_combine_mode_not_intersect
- local
- i: INTEGER
- do
- i := int_canvas_region_combine_mode (cnvs, 3)
- end
- is_point_in_region (x, y: INTEGER): BOOLEAN
- -- Returns a non zero value if the point is contained inside the current
- -- region.
- local
- i: INTEGER
- do
- i := int_canvas_is_point_in_region (cnvs, x, y)
- if i.is_equal(0) then
- Result := False
- else
- Result := True
- end
- end
- wd_is_point_in_region (x, y: REAL_64): BOOLEAN
- -- Like "is_point_in_region" but for World coordinates.
- local
- i: REAL_64
- do
- i := int_wd_canvas_is_point_in_region (cnvs, x, y)
- if i.is_equal(0) then
- Result := False
- else
- Result := True
- end
- end
- offset_region (dx, dy: INTEGER)
- -- Moves the current region by the given offset. In X-Windows, if the
- -- region moves to outside the canvas border, the part moved outside will
- -- be lost, the region will need to be reconstructed.
- do
- int_canvas_offset_region (cnvs, dx, dy)
- end
- wd_offset_region (dx, dy: REAL_64)
- -- Like "offset_region" but for World coordinates.
- do
- int_wd_canvas_offset_region (cnvs, dx, dy)
- end
- get_region_box: TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
- -- Returns the rectangle of the bounding box of the current region.
- -- In the form (xmin, xmax, ymin, ymax)
- local
- xmin, xmax, ymin, ymax: INTEGER
- do
- int_canvas_get_region_box (cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- wd_get_region_box: TUPLE[REAL_64, REAL_64, REAL_64, REAL_64]
- -- Like "get_region_box" but with World coordinates.
- local
- xmin, xmax, ymin, ymax: REAL_64
- do
- int_wd_canvas_get_region_box (cnvs, $xmin, $xmax, $ymin, $ymax)
- Result := [xmin, xmax, ymin, ymax]
- end
- feature {}
- -- Verifications
- is_valid_combine_mode (mode: STRING): BOOLEAN
- do
- if mode.is_equal("CD_UNION") or
- mode.is_equal("CD_INTERSECT") or
- mode.is_equal("CD_DIFFERENCE") or
- mode.is_equal("CD_NOTINTERSECT") then
- Result := True
- else
- Result := False
- end
- end
- -- Internals
- int_canvas_region_combine_mode (wgt: POINTER; m: INTEGER): INTEGER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasRegionCombineMode"
- }"
- end
- int_canvas_is_point_in_region (wgt: POINTER; x, y: INTEGER): INTEGER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasIsPointInRegion"
- }"
- end
- int_wd_canvas_is_point_in_region (wgt: POINTER; x, y: REAL_64): INTEGER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "wdCanvasIsPointInRegion"
- }"
- end
- int_canvas_offset_region (wgt: POINTER; dx, dy: INTEGER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasOffsetRegion"
- }"
- end
- int_wd_canvas_offset_region (wgt: POINTER; dx, dy: REAL_64)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "wdCanvasOffsetRegion"
- }"
- end
- int_canvas_get_region_box (wgt, c1, c2, c3, c4: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "cdCanvasGetRegionBox"
- }"
- end
- int_wd_canvas_get_region_box (wgt, c1, c2, c3, c4: POINTER)
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "wdCanvasGetRegionBox"
- }"
- end
- end
- -- The MIT License (MIT)
- -- Copyright (c) 2016 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.
|