123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- class IUP_FLAT_BUTTON
- -- Creates an interface element that is a button, but it does not have native
- -- decorations. When selected, this element activates a function in the
- -- application. Its visual presentation can contain a text and/or an image.
- --
- -- It behaves just like an IUP_BUTTON, but since it is not a native control it
- -- has more flexibility for additional options. It can also behave like an
- -- IUP_TOGGLE (without the checkmark).
- --
- -- It inherits from IUP_CANVAS. Inherits all callbacks of the IUP_CANVAS, but
- -- redefines a few of them. Including ACTION, BUTTON_CB, FOCUS_CB,
- -- LEAVEWINDOW_CB, and ENTERWINDOW_CB. To allow the application to use those
- -- callbacks the same callbacks are exported with the "FLAT_" prefix using the
- -- same parameters, except the FLAT_ACTION callback that now mimics the
- -- IUP_BUTTON ACTION. They are all called before the internal callbacks and if
- -- they return IUP_IGNORE the internal callbacks are not processed.
-
- inherit
- IUP_CANVAS
- redefine
- set_border,
- execute_flat_action,
- execute_flat_button,
- execute_flat_focus,
- execute_flat_enterwindow,
- execute_flat_leavewindow,
- execute_valuechanged
- end
- IUP_WIDGET_FGCOLOR
- IUP_WIDGET_SPACING
- IUP_WIDGET_TITLE
- IUP_WIDGET_IGNORERADIO
- create {ANY}
- flat_button
- feature {ANY}
- flat_button (title: STRING)
- --
- local
- a_flat_button, p: POINTER
- do
- if title /= Void then
- a_flat_button := int_flat_button(title.to_external)
- else
- a_flat_button := int_flat_button(p)
- end
- set_widget(a_flat_button)
- end
- -- Attributes
- set_alignment (horizontal, vertical: STRING)
- -- (non inheritable): horizontal and vertical alignment. Possible values:
- -- "ALEFT", "ACENTER" and "ARIGHT", combined to "ATOP", "ACENTER" and
- -- "ABOTTOM". Default: "ACENTER:ACENTER".
- require
- is_valid_vertical_alignment(vertical)
- is_valid_horizontal_alignment(horizontal)
- local
- str: STRING
- do
- create str.copy(horizontal)
- str.append_string(":")
- str.append_string(vertical)
-
- iup_open.set_attribute(Current, "ALIGNMENT", str)
- end
- set_back_image (name: STRING)
- -- (non inheritable): image name to be used as background. It will be
- -- zoomed to fill the background (it does not includes the border).
- do
- iup_open.set_attribute(Current, "BACKIMAGE", name)
- end
- set_back_image_highlight (name: STRING)
- -- (non inheritable): background image name of the element in highlight
- -- state. If it is not defined then the BACKIMAGE is used.
- do
- iup_open.set_attribute(Current, "BACKIMAGEHIGHLIGHT", name)
- end
- set_back_image_inactive (name: STRING)
- -- (non inheritable): background image name of the element when inactive.
- -- If it is not defined then the BACKIMAGE is used and its colors will be
- -- replaced by a modified version creating the disabled effect.
- do
- iup_open.set_attribute(Current, "BACKIMAGEINACTIVE", name)
- end
- set_back_image_press (name: STRING)
- -- (non inheritable): background image name of the element in pressed
- -- state. If it is not defined then the BACKIMAGE is used.
- do
- iup_open.set_attribute(Current, "BACKIMAGEPRESS", name)
- end
- set_border (state: BOOLEAN)
- -- (creation only): Shows a border around the canvas. Default: "False".
- do
- Precursor (state)
- end
- set_rgb_border_color (red: INTEGER; green: INTEGER; blue: INTEGER)
- -- color used for borders. Default: "50 150 255". This is for the
- -- flat button drawn border.
- do
- iup_open.set_attribute(Current, "BORDERCOLOR",
- rgb_to_string(red, green, blue))
- end
- get_rgb_border_color: TUPLE[INTEGER, INTEGER, INTEGER]
- -- Return the RGB values of the border color.
- do
- Result := iup_open.get_rgb(Current, "BORDERCOLOR")
- end
- set_rgb_border_pressed_color (red: INTEGER; green: INTEGER; blue: INTEGER)
- -- color used for borders when pressed or selected. Default use border
- -- color.
- do
- iup_open.set_attribute(Current, "BORDERPSCOLOR",
- rgb_to_string(red, green, blue))
- end
- get_rgb_border_pressed_color: TUPLE[INTEGER, INTEGER, INTEGER]
- -- Return the RGB values of the border pressed color.
- do
- Result := iup_open.get_rgb(Current, "BORDERPSCOLOR")
- end
- set_rgb_border_highlighted_color (red: INTEGER; green: INTEGER; blue: INTEGER)
- -- color used for borders when highlighted. Default use border color.
- do
- iup_open.set_attribute(Current, "BORDERHLCOLOR",
- rgb_to_string(red, green, blue))
- end
- get_rgb_border_highlighted_color: TUPLE[INTEGER, INTEGER, INTEGER]
- -- Return the RGB values of the border highlighted color.
- do
- Result := iup_open.get_rgb(Current, "BORDERHLCOLOR")
- end
- set_border_width (value: INTEGER)
- -- line width used for borders. Default: "1". Any borders can be hidden
- -- by simply setting this value to 0. This is for the flat button drawn
- -- border.
- require
- non_negative: value >= 0
- do
- iup_open.set_attribute(Current, "BORDERWIDTH", value.to_string)
- end
- get_border_width: INTEGER
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "BORDERWIDTH")
- if str.is_integer then
- Result := str.to_integer
- end
- end
- set_fit_to_back_image (state: BOOLEAN)
- -- (non inheritable): enable the natural size to be computed from the
- -- back image. If back image is not defined will be ignored. When set to
- -- True it will set border width to 0. Default: False.
- do
- iup_open.set_attribute(Current, "FITTOBACKIMAGE", boolean_to_yesno(state))
- end
- set_front_image (name: STRING)
- -- (non inheritable): image name to be used as foreground. It will be
- -- zoomed to fill the foreground (it does not includes the border). The
- -- foreground has the same are as the background, but it is drawn at last.
- do
- iup_open.set_attribute(Current, "FRONTIMAGE", name)
- end
- set_front_image_highlight (name: STRING)
- -- (non inheritable): foreground image name of the element in highlight
- -- state. If it is not defined then the FRONTIMAGE is used.
- do
- iup_open.set_attribute(Current, "FRONTIMAGEHIGHLIGHT", name)
- end
- set_front_image_inactive (name: STRING)
- -- (non inheritable): foreground image name of the element when inactive.
- -- If it is not defined then the FRONTIMAGE is used and its colors will
- -- be replaced by a modified version creating the disabled effect.
- do
- iup_open.set_attribute(Current, "FRONTIMAGEINACTIVE", name)
- end
- set_front_image_press (name: STRING)
- -- (non inheritable): foreground image name of the element in pressed
- -- state. If it is not defined then the FRONTIMAGE is used.
- do
- iup_open.set_attribute(Current, "FRONTIMAGEPRESS", name)
- end
- has_focus: BOOLEAN
- -- Returns the button state if has focus.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "HASFOCUS")
- Result := yesno_to_boolean(str)
- end
- set_rgb_highlight_color (red: INTEGER; green: INTEGER; blue: INTEGER)
- -- color used to indicate a highlight state. Default: "200 225 245".
- do
- iup_open.set_attribute(Current, "HLCOLOR", rgb_to_string(red, green, blue))
- end
- get_rgb_highlight_color: TUPLE[INTEGER, INTEGER, INTEGER]
- do
- Result := iup_open.get_rgb(Current, "HLCOLOR")
- end
- is_highlighted: BOOLEAN
- -- Returns the button state if highlighted.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "HIGHLIGHTED")
- Result := yesno_to_boolean(str)
- end
- set_image (name: STRING)
- -- (non inheritable): Image name.
- do
- iup_open.set_attribute(Current, "IMAGE", name)
- end
- set_image_highlight (name: STRING)
- -- (non inheritable): Image name of the element in highlight state. If it
- -- is not defined then the IMAGE is used.
- do
- iup_open.set_attribute(Current, "IMAGEHIGHLIGHT", name)
- end
- set_image_inactive (name: STRING)
- -- (non inheritable): Image name of the element when inactive. If it is
- -- not defined then the IMAGE is used and its colors will be replaced by
- -- a modified version creating the disabled effect.
- do
- iup_open.set_attribute(Current, "IMAGEINACTIVE", name)
- end
- set_image_press (name: STRING)
- -- (non inheritable): Image name of the element in pressed state. If it
- -- is not defined then the IMAGE is used.
- do
- iup_open.set_attribute(Current, "IMAGEPRESS", name)
- end
- set_image_position (pos: STRING)
- -- (non inheritable): Position of the image relative to the text when
- -- both are displayed. Can be: LEFT, RIGHT, TOP, BOTTOM. Default: LEFT.
- require
- is_valid_position(pos)
- do
- iup_open.set_attribute(Current, "IMAGEPOSITION", pos)
- end
- set_padding (horizontal, vertical: INTEGER)
- -- internal margin. Works just like the margin attribute of the IUP_HBOX
- -- and IUP_VBOX containers, but uses a different name to avoid
- -- inheritance problems. Default value: "0x0".
- require
- horizontal >= 0
- vertical >= 0
- local
- margin: STRING
- do
- margin := horizontal.to_string
- margin.append_string("x")
- margin.append_string(vertical.to_string)
- iup_open.set_attribute(Current, "PADDING", margin)
- end
- get_padding: TUPLE[INTEGER, INTEGER]
- -- Return the value of the padding.
- local
- margin: STRING
- do
- margin := iup_open.get_attribute(Current, "PADDING")
- Result := components_of_size(margin)
- end
- is_pressed: BOOLEAN
- -- Returns the button state if pressed.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "PRESSED")
- Result := yesno_to_boolean(str)
- end
- set_rgb_press_color (red: INTEGER; green: INTEGER; blue: INTEGER)
- -- color used to indicate a press state. Default: "150 200 235".
- do
- iup_open.set_attribute(Current, "PSCOLOR", rgb_to_string(red, green, blue))
- end
- get_rgb_press_color: TUPLE[INTEGER, INTEGER, INTEGER]
- do
- Result := iup_open.get_rgb(Current, "PSCOLOR")
- end
- is_radio: BOOLEAN
- -- returns if the toggle is inside a radio. Valid only after the element
- -- is mapped and TOGGLE=True.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "RADIO")
- if is_yes_no(str) then
- Result := yesno_to_boolean(str)
- end
- end
-
- set_toggle (state: BOOLEAN)
- -- enabled the toggle behavior. Default: False.
- do
- iup_open.set_attribute(Current, "TOGGLE", boolean_to_yesno(state))
- end
- set_text_alignment (value: STRING)
- require
- is_valid_text_alignment(value)
- do
- iup_open.set_attribute(Current, "TEXTALIGNMENT", value)
- end
- get_value: STRING
- -- Toggle's state. Values can be "ON", "OFF" or "TOGGLE".
- do
- Result := iup_open.get_attribute(Current, "VALUE")
- end
- -- Operations
- set_on
- do
- iup_open.set_attribute(Current, "VALUE", "ON")
- end
- set_off
- do
- iup_open.set_attribute(Current, "VALUE", "OFF")
- end
- invert
- -- Invert the current state.
- do
- iup_open.set_attribute(Current, "VALUE", "TOGGLE")
- end
- -- Extra callbacks
- set_cb_flat_action (act: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING])
- -- Action generated when the button 1 (usually left) is selected. This
- -- callback is called only after the mouse is released and when it is
- -- released inside the button area.
- --
- -- ih: identifier of the element that activated the event.
- --
- -- Returns: IUP_CLOSE will be processed.
- local
- operation: INTEGER
- do
- cb_flat_action := act
- if cb_flat_action /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "FLAT_ACTION", "Fnff", operation)
- end
- set_cb_flat_button (act: FUNCTION[TUPLE[IUP_FLAT_BUTTON, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
- -- Action generated when any mouse button is pressed and when it is
- -- released. Both calls occur before the ACTION callback when button 1 is
- -- being used.
- -- IUP_CANVAS: identifies the element that activated the event.
- -- button: identifies the activated mouse button:
- --
- -- 1 - left mouse button (button 1);
- -- 2 - middle mouse button (button 2);
- -- 3 - right mouse button (button 3).
- --
- -- pressed: indicates the state of the button:
- --
- -- 0 - mouse button was released;
- -- 1 - mouse button was pressed.
- --
- -- x, y: position in the canvas where the event has occurred, in pixels.
- --
- -- status: status of the mouse buttons and some keyboard keys at the
- -- moment the event is generated. The following macros must be used for
- -- verification:
- --
- -- Returns: IUP_CLOSE will be processed. On some controls if IUP_IGNORE
- -- is returned the action is ignored (this is system dependent).
- local
- operation: INTEGER
- do
- cb_flat_button := act
- if cb_flat_button /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "FLAT_BUTTON_CB", "NONEEDED", operation)
- end
- set_cb_flat_focus (act: FUNCTION[TUPLE[IUP_FLAT_BUTTON, INTEGER], STRING])
- -- Called when the canvas gets or looses the focus. It is called after
- -- the common callbacks GETFOCUS_CB and KILL_FOCUS_CB.
- -- ih: identifier of the element that activated the event.
- -- focus: is non zero if the canvas is getting the focus, is zero if it
- -- is loosing the focus.
- local
- operation: INTEGER
- do
- cb_flat_focus := act
- if cb_focus /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "FLAT_FOCUS_CB", "NONEEDED", operation)
- end
- set_cb_flat_enter_window (act: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING])
- -- Action generated when the mouse enters the native element.
- local
- operation: INTEGER
- do
- cb_flat_enterwindow := act
- if cb_enterwindow /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "FLAT_ENTERWINDOW_CB", "NONEEDED", operation)
- end
- set_cb_flat_leave_window (act: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING])
- -- Action generated when the mouse leaves the native element.
- local
- operation: INTEGER
- do
- cb_flat_leavewindow := act
- if cb_leavewindow /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "FLAT_LEAVEWINDOW_CB", "NONEEDED", operation)
- end
- set_cb_value_changed (act: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING])
- -- Called after the value was interactively changed by the
- -- user. Called after the ACTION callback, but under the same context.
- local
- operation: INTEGER
- do
- cb_valuechanged := act
- if cb_valuechanged /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "VALUECHANGED_CB", "NONEEDED", operation)
- end
- feature {IUP}
- -- Callbacks
- execute_flat_action: STRING
- do
- Result := cb_flat_action.item([Current])
- end
- execute_flat_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
- do
- Result := cb_flat_button.item([Current, btn, pressed, x, y, status])
- end
- execute_flat_focus (focus: INTEGER): STRING
- do
- Result := cb_flat_focus.item([Current, focus])
- end
- execute_flat_enterwindow: STRING
- do
- Result := cb_flat_enterwindow.item([Current])
- end
- execute_flat_leavewindow: STRING
- do
- Result := cb_flat_leavewindow.item([Current])
- end
- execute_valuechanged: STRING
- do
- Result := cb_valuechanged.item([Current])
- end
- feature {}
- cb_flat_action: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING]
- cb_flat_button: FUNCTION[TUPLE[IUP_FLAT_BUTTON, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
- cb_flat_focus: FUNCTION[TUPLE[IUP_FLAT_BUTTON, INTEGER], STRING]
- cb_flat_enterwindow: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING]
- cb_flat_leavewindow: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING]
- cb_valuechanged: FUNCTION[TUPLE[IUP_FLAT_BUTTON], STRING]
- -- Internals
-
- int_flat_button (title: POINTER): POINTER
- external "plug_in"
- alias "{
- location: "${sys}/plugins"
- module_name: "iup"
- feature_name: "IupFlatButton"
- }"
- end
- -- Validations
- is_valid_vertical_alignment (value: STRING): BOOLEAN
- do
- if value.is_equal("ATOP") or
- value.is_equal("ACENTER") or
- value.is_equal("ABOTTOM") then
- Result := True
- else
- Result := False
- end
- end
- is_valid_horizontal_alignment (value: STRING): BOOLEAN
- do
- if value.is_equal("ALEFT") or
- value.is_equal("ACENTER") or
- value.is_equal("ARIGHT") then
- Result := True
- else
- Result := False
- end
- end
- is_valid_position (value: STRING): BOOLEAN
- do
- if value.is_equal("LEFT") or
- value.is_equal("RIGHT") or
- value.is_equal("TOP") or
- value.is_equal("BOTTOM") then
- Result := True
- else
- Result := False
- end
- end
- is_valid_text_alignment (value: STRING): BOOLEAN
- do
- if value.is_equal("ALEFT") or
- value.is_equal("ACENTER") or
- value.is_equal("ARIGHT") then
- Result := True
- else
- Result := False
- end
- end
- end -- class IUP_FLAT_BUTTON
- -- 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.
|