/* *********************************************************************
This source file is a part of the standard library of Scol
For the latest info, see http://www.scolring.org
Copyright (c) 2015 Stephane Bisaro aka Iri.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
********************************************************************* */
/*
* 2d functions for Scol
* See http://redmine.scolring.org/projects/tutorials/wiki/Scol_usage
* for more informations
*/
/*! \file colorselect.pkg
* \author Scol team
* \version 0.1
* \copyright GNU Lesser General Public License 2.0 or later
* \brief Scol select 2d OS colors API
*
* Dependancies :
* - lib/std/stdlib.pkg
* - lib/2d/colors.pkg
* - lib/std/list.pkg
*
* \image html colorselect.png
**/
/* PRIVATE PART */
/*
* Use only the public functions !! See bottom.
* Otherwise, the behavior could be undefined
*/
struct COLORSELECT = [
cs_id : I,
cs_chn : Chn,
cs_win : ObjWin,
cs_mother : ObjWin,
cs_winR : ObjWin,
cs_winG : ObjWin,
cs_winB : ObjWin,
cs_txtShortDesc : ObjText,
cs_txtRed : ObjText,
cs_txtGreen : ObjText,
cs_txtBlue : ObjText,
cs_txtColor : ObjText,
cs_isInside : I,
cs_built : I, // 0 : not built, 1 : building, 2 : built, 3 : destroying
cs_applyClose : I, // 'apply' button closes also the dialog (1) or not (0, default)
cs_pos : [I I],
cs_size : [I I],
cs_margin : I,
cs_color : [I I I],
cs_enable : I,
cs_visible : I,
cs_buttonShow : I,
cs_title : S,
cs_shortdesc : S,
cs_cbApply : fun [I I I I] I,
cs_cbClose : fun [I] I
] mkCOLORSELECT;;
typeof ColorSelectList = [COLORSELECT r1];;
fun CS_SHOW () = WINDOW_HIDDEN;;
fun CS_HIDE () = WINDOW_UNHIDDEN;;
fun CS_MINWIDTH ()= 350;;
fun CS_MINHEIGHT ()= 250;;
fun CS_MARGIN ()= 5;;
proto colorselect_createShortDesc = fun [COLORSELECT] ObjText;;
fun colorselect_init (chn)=
let mkCOLORSELECT [
1+sizelist ColorSelectList chn
nil nil
nil nil nil
nil nil nil nil nil
0 0 0
[0 0] [CS_MINWIDTH CS_MINHEIGHT] CS_MARGIN [110 80 200] 1 1 1
"ColorSelect" "Choose a color and click on 'Apply' button"
nil nil
] -> cs in
set ColorSelectList = cs :: ColorSelectList;
sizelist ColorSelectList;;
fun colorselect_getFromID (id)=
nth_list ColorSelectList (sizelist ColorSelectList)-id;;
// getters and setters
fun coloselect_setWin (id, win)=
let colorselect_getFromID id -> cs in
if (cs == nil) || (cs.cs_built != 0) then
nil
else
(
set cs.cs_mother = win;
if (cs.cs_isInside) && (cs.cs_mother == nil) then
_fooS "WARNING ! ColorSelectSetWindow is called with a 'nil' parent and the 'inside' flag is set !";
id
);;
fun colorselect_setIsInside (id, is)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_isInside = is;
id
);;
fun colorslect_getIsInside (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
cs.cs_isInside;;
fun colorselect_setCbApply (id, cbfun)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_cbApply = cbfun;
if cs.cs_cbApply == nil then
_fooS "WARNING ! ColorSelectSetCbApply is called with a 'nil' argument ! No callback set !";
id
);;
fun colorselect_setCbClose (id, cbfun)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_cbClose = cbfun;
id
);;
fun colorselect_setApplyClose (id, flag)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_applyClose = flag;
id
);;
fun colorselect_getApplyClose (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
cs.cs_applyClose;;
fun colorselect_setPosition (id, x, y)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_pos = [x y];
if cs.cs_built == 2 then
_MVwindow cs.cs_win x y;
id
);;
fun coloselect_setSize (id, w, h)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set w = std_clamp w CS_MINWIDTH 9999;
set h = std_clamp h CS_MINHEIGHT 9999;
set cs.cs_size = [w h];
if cs.cs_built == 2 then
let cs.cs_pos -> [x y] in
_SIZEwindow cs.cs_win w h x y;
id
);;
fun colorselect_setTitle (id, title)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_title = title;
if cs.cs_built == 2 then
_SETwindowName cs.cs_win cs.cs_title;
id
);;
fun colorselect_setColor (id, r, g, b)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set r = std_clamp r 0 255;
set g = std_clamp g 0 255;
set b = std_clamp b 0 255;
set cs.cs_color = [r g b];
if cs.cs_built == 2 then
_PAINTwindow cs.cs_win;
id
);;
fun colorselect_getColor (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
cs.cs_color;;
fun colorselect_enable (id, state)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set state = std_clamp state 0 1;
set cs.cs_enable = state;
if cs.cs_built == 2 then
_ENwindow cs.cs_win cs.cs_enable;
id
);;
fun colorselect_enabled (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
cs.cs_enable;;
fun colorselect_show (id, state)=
let colorselect_getFromID id -> cs in
if (cs == nil) || ((state != CS_SHOW) && (state != CS_HIDE)) then
nil
else
(
set cs.cs_visible = state;
if cs.cs_built == 2 then
_SHOWwindow cs.cs_win cs.cs_visible;
id
);;
fun colorselect_shown (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
cs.cs_visible;;
fun colorselect_setShortDesc (id, txt)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set cs.cs_shortdesc = txt;
if cs.cs_built == 2 then
if cs.cs_shortdesc != nil then
(
if cs.cs_txtShortDesc == nil then
colorselect_createShortDesc cs
else
_SETtext cs.cs_txtShortDesc cs.cs_shortdesc
)
else
(
_DStext cs.cs_txtShortDesc;
set cs.cs_txtShortDesc = nil
);
id
);;
fun coloselect_setButtonShow (id, state)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set state = std_clamp state 0 1;
set cs.cs_buttonShow = state;
id
);;
fun coloselect_getButtonShow (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
cs.cs_buttonShow;;
fun colorselect_setMargin (id, m)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
(
set m = std_clamp m 0 999;
set cs.cs_margin = m;
id
);;
// callbacks
fun colorslect_cbPaint (o, cs)=
let cs.cs_color -> [r g b] in
let l2d_colorsConvertINT2HEXex r g b -> s in
let make_rgb r g b -> c in
let cs.cs_size -> [w h] in
(
_SETtext cs.cs_txtColor strcat "Current : " s;
_PAINTrectangle o cs.cs_margin h-(2*cs.cs_margin)-50+ if cs.cs_buttonShow then (-20) else 0 w-(2*cs.cs_margin) 50 DRAW_SOLID 1 0 DRAW_SOLID c;
0
);;
fun colorselect_cbPaintR (o, cs)=
_CLRwindow o;
let cs.cs_color -> [r g b] in
_PAINTrectangle o cs.cs_margin cs.cs_margin r 20 DRAW_SOLID 1 0 DRAW_SOLID 0x0000FF;
0;;
fun colorselect_cbPaintG (o, cs)=
_CLRwindow o;
let cs.cs_color -> [r g b] in
_PAINTrectangle o cs.cs_margin cs.cs_margin g 20 DRAW_SOLID 1 0 DRAW_SOLID 0x00FF00;
0;;
fun colorselect_cbPaintB (o, cs)=
_CLRwindow o;
let cs.cs_color -> [r g b] in
_PAINTrectangle o cs.cs_margin cs.cs_margin b 20 DRAW_SOLID 1 0 DRAW_SOLID 0xFF0000;
0;;
fun colorselect_cbClickR (o, cs, x, y, btn)=
if (btn != 0) && (x <= 255+cs.cs_margin) && (x >= cs.cs_margin) then
let cs.cs_color -> [r g b] in
let x-cs.cs_margin -> c in
(
_SETtext cs.cs_txtRed itoa c;
mutate cs.cs_color <- [c g b];
_PAINTwindow o;
_PAINTwindow cs.cs_win;
);
0;;
fun colorselect_cbClickG (o, cs, x, y, btn)=
if (btn != 0) && (x <= 255+cs.cs_margin) && (x >= cs.cs_margin) then
let cs.cs_color -> [r g b] in
let x-cs.cs_margin -> c in
(
_SETtext cs.cs_txtGreen itoa c;
mutate cs.cs_color <- [r c b];
_PAINTwindow o;
_PAINTwindow cs.cs_win;
);
0;;
fun colorselect_cbClickB (o, cs, x, y, btn)=
if (btn != 0) && (x <= 255+cs.cs_margin) && (x >= cs.cs_margin) then
let cs.cs_color -> [r g b] in
let x-cs.cs_margin -> c in
(
_SETtext cs.cs_txtBlue itoa c;
mutate cs.cs_color <- [r g c];
_PAINTwindow o;
_PAINTwindow cs.cs_win;
);
0;;
fun colorselect_cbWheelR (o, cs, x, y, dir, mask)=
let cs.cs_color -> [r g b] in
let if _keybdstate == 1 then 5 // shift
else if _keybdstate == 2 then 10 // control
else 1
-> delta in
(
set delta = delta * dir;
set r = r + delta;
if (r <= 255+cs.cs_margin) && (r >= cs.cs_margin) then
(
_SETtext cs.cs_txtRed itoa r;
mutate cs.cs_color <- [r g b]
)
else if r > 255+cs.cs_margin then
(
_SETtext cs.cs_txtRed "255";
mutate cs.cs_color <- [255 g b]
)
else if r < cs.cs_margin then
(
_SETtext cs.cs_txtRed "0";
mutate cs.cs_color <- [0 g b]
);
_PAINTwindow o;
_PAINTwindow cs.cs_win;
0
);;
fun colorselect_cbWheelG (o, cs, x, y, dir, mask)=
let cs.cs_color -> [r g b] in
let if _keybdstate == 1 then 5 // shift
else if _keybdstate == 2 then 10 // control
else 1
-> delta in
(
set delta = delta * dir;
set g = g + delta;
if (g <= 255+cs.cs_margin) && (g >= cs.cs_margin) then
(
_SETtext cs.cs_txtGreen itoa g;
mutate cs.cs_color <- [r g b]
)
else if g > 255+cs.cs_margin then
(
_SETtext cs.cs_txtGreen "255";
mutate cs.cs_color <- [r 255 b]
)
else if g < cs.cs_margin then
(
_SETtext cs.cs_txtGreen "0";
mutate cs.cs_color <- [r 0 b]
);
_PAINTwindow o;
_PAINTwindow cs.cs_win;
0
);;
fun colorselect_cbWheelB (o, cs, x, y, dir, mask)=
let cs.cs_color -> [r g b] in
let if _keybdstate == 1 then 5 // shift
else if _keybdstate == 2 then 10 // control
else 1
-> delta in
(
set delta = delta * dir;
set b = b + delta;
if (b <= 255+cs.cs_margin) && (b >= cs.cs_margin) then
(
_SETtext cs.cs_txtBlue itoa b;
mutate cs.cs_color <- [r g b]
)
else if b > 255+cs.cs_margin then
(
_SETtext cs.cs_txtBlue "255";
mutate cs.cs_color <- [r g 255]
)
else if b < cs.cs_margin then
(
_SETtext cs.cs_txtBlue "0";
mutate cs.cs_color <- [r g 0]
);
_PAINTwindow o;
_PAINTwindow cs.cs_win;
0
);;
fun colorselect_cbClose (o, cs)=
set cs.cs_built = 3;
exec cs.cs_cbClose with [cs.cs_id];
if cs.cs_win != nil then
_DSwindow cs.cs_win;
set ColorSelectList = std_lRemoveElt ColorSelectList cs;
set cs = nil;
0;;
fun colorselect_cbApply (o, cs)=
let cs.cs_color -> [r g b] in
exec cs.cs_cbApply with [cs.cs_id r g b];
if cs.cs_applyClose then
colorselect_cbClose o cs;
0;;
fun colorselect_cbCopy (o, cs)=
let cs.cs_color -> [r g b] in
_SETclipBoardData l2d_colorsConvertINT2HEXex r g b;
0;;
// build
fun colorselect_createShortDesc (cs)=
if cs.cs_shortdesc != nil then
let cs.cs_size -> [w h] in
set cs.cs_txtShortDesc = _CRtext cs.cs_chn cs.cs_win cs.cs_margin cs.cs_margin w-(2*cs.cs_margin) 20 ET_ALIGN_CENTER|ET_BORDER cs.cs_shortdesc;
cs.cs_txtShortDesc;;
fun colorselect_build (id)=
let colorselect_getFromID id -> cs in
if (cs == nil) || (cs.cs_built > 0) then
nil
else
let cs.cs_pos -> [x y] in
/*let if cs.cs_mother != nil then
let _GETwindowSizePosition cs.cs_mother -> [ww hw _ _] in
[ww hw 5]
else
[350 250 5]
-> [w h m] in*/
let cs.cs_size -> [w h] in
let cs.cs_color -> [r g b] in
let cs.cs_margin -> m in
(
set cs.cs_built = 1;
if !cs.cs_buttonShow then
set h = h-20-m;
set cs.cs_size = [w h];
set cs.cs_win = _CRwindow cs.cs_chn cs.cs_mother x y w h if cs.cs_isInside then WN_CHILDINSIDE else WN_MENU|WN_MINBOX|WN_NOSCOL cs.cs_title;
_CBwinDestroy cs.cs_win @colorselect_cbClose cs;
_CBwinPaint cs.cs_win @colorslect_cbPaint cs;
colorselect_createShortDesc cs;
// red
_CRtext cs.cs_chn cs.cs_win m 20+(2*m)+m 20 20 ET_ALIGN_CENTER "R:";
set cs.cs_winR = _CRwindow cs.cs_chn cs.cs_win (2*m)+20 20+(2*m) 255+(2*m) 30 WN_CHILDINSIDE "Red";
set cs.cs_txtRed = _CRtext cs.cs_chn cs.cs_win w-m-30 20+(2*m)+m 30 20 ET_ALIGN_CENTER itoa r;
_CBwinPaint cs.cs_winR @colorselect_cbPaintR cs;
_CBcursorMove cs.cs_winR @colorselect_cbClickR cs;
_CBwinClick cs.cs_winR @colorselect_cbClickR cs;
_CBwinWheel cs.cs_winR @colorselect_cbWheelR cs;
_PAINTwindow cs.cs_winR;
// green
_CRtext cs.cs_chn cs.cs_win m 50+(3*m)+(2*m) 20 20 ET_ALIGN_CENTER "G:";
set cs.cs_winG = _CRwindow cs.cs_chn cs.cs_win (2*m)+20 50+(3*m)+m 255+(2*m) 30 WN_CHILDINSIDE "Green";
set cs.cs_txtGreen = _CRtext cs.cs_chn cs.cs_win w-m-30 50+(3*m)+m 30 20 ET_ALIGN_CENTER itoa g;
_CBwinPaint cs.cs_winG @colorselect_cbPaintG cs;
_CBcursorMove cs.cs_winG @colorselect_cbClickG cs;
_CBwinClick cs.cs_winG @colorselect_cbClickG cs;
_CBwinWheel cs.cs_winG @colorselect_cbWheelG cs;
_PAINTwindow cs.cs_winG;
// blue
_CRtext cs.cs_chn cs.cs_win m 80+(5*m)+(2*m) 20 20 ET_ALIGN_CENTER "B:";
set cs.cs_winB = _CRwindow cs.cs_chn cs.cs_win (2*m)+20 80+(5*m)+m 255+(2*m) 30 WN_CHILDINSIDE "Blue";
set cs.cs_txtBlue = _CRtext cs.cs_chn cs.cs_win w-m-30 80+(5*m)+m 30 20 ET_ALIGN_CENTER itoa b;
_CBwinPaint cs.cs_winB @colorselect_cbPaintB cs;
_CBcursorMove cs.cs_winB @colorselect_cbClickB cs;
_CBwinClick cs.cs_winB @colorselect_cbClickB cs;
_CBwinWheel cs.cs_winB @colorselect_cbWheelB cs;
_PAINTwindow cs.cs_winB;
set cs.cs_txtColor = _CRtext cs.cs_chn cs.cs_win m 110+(8*m) w-(2*m) 20 ET_ALIGN_CENTER "";
// Buttons
if cs.cs_buttonShow then
(
_CBbutton
_CRbutton cs.cs_chn cs.cs_win m h-m-20 100 20 0 "Close"
@colorselect_cbClose
cs;
_CBbutton
_CRbutton cs.cs_chn cs.cs_win w-(2*m)-200 h-m-20 100 20 0 "Copy"
@colorselect_cbCopy
cs;
_CBbutton
_CRbutton cs.cs_chn cs.cs_win w-m-100 h-m-20 100 20 0 "Apply"
@colorselect_cbApply
cs;
);
_PAINTwindow cs.cs_win;
set cs.cs_built = 2;
id
);;
// destroy
fun colorselect_destroy (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
colorselect_cbClose cs.cs_win cs;;
// copy
fun colorslect_copySetting (id)=
let colorselect_getFromID id -> cs in
if cs == nil then
nil
else
let colorselect_init cs.cs_chn -> nid in
let colorselect_getFromID nid -> ncs in
if ncs == nil then
nil
else
(
set ncs.cs_mother = cs.cs_mother;
set ncs.cs_isInside = cs.cs_isInside;
set ncs.cs_applyClose = cs.cs_applyClose;
set ncs.cs_pos = cs.cs_pos;
set ncs.cs_size = cs.cs_size;
set ncs.cs_margin = cs.cs_margin;
set ncs.cs_color = cs.cs_color;
set ncs.cs_enable = cs.cs_enable;
set ncs.cs_visible = cs.cs_visible;
set ncs.cs_buttonShow = cs.cs_buttonShow;
set ncs.cs_title = cs.cs_title;
set ncs.cs_shortdesc = cs.cs_shortdesc;
set ncs.cs_cbApply = cs.cs_cbApply;
set ncs.cs_cbClose = cs.cs_cbClose;
nid
);;
/* PUBLIC PART */
/*! \brief Initializes a "color select" dialog box. This must always be
* called before other all.
*
* \ingroup _2dos_colorselect
* Prototype : fun [Chn] I
*
* \param Chn : the owner channel.
* \return I : an Id for a new dialog box, or nil if the given channel is nil.
*
* \see ColorSelectBuild to build the dialog
*
* \code{.unparsed}
* // This a simple test
*
* fun A (id, r, g, b)=
* _fooS sprintf "%d %d %d" [r g b];
* 0;;
*
* fun C (id)=
* _fooS sprintf "Close : %d %d %d" ColorSelectGetColor id;
* 0;;
*
* fun main ()=
* _showconsole;
*
* let _CRwindow _channel nil 250 140 500 600 WN_NORMAL "test" -> win in
* let ColorSelectInit _channel -> id in
* (
* ColorSelectSetCbApply id @A;
* ColorSelectSetCbClose id @C;
* ColorSelectSetWindow id win;
* ColorSelectSetIsInside id 1;
* ColorSelectSetPosition id 100 100;
* ColorSelectSetButtonShow id 1;
* ColorSelectBuild id;
*
* 0
* );;
* \endcode
**/
fun ColorSelectInit (chn)=
if std_objIsNil chn then
nil
else
colorselect_init chn;;
/*! \brief Sets the parent window of a "color select" dialog box.
*
* Once the dialog is built, this parameter canot be changed !
*
* If the 'inside' flag is set, this parent must be set by this function
* before to build the dialog.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I ObjWin] I
*
* \param I : the dialog ID.
* \param ObjWin : the parent window. Can be 'nil' (value by default).
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetWindow (iId, oWin)=
coloselect_setWin iId oWin;;
/*! \brief Sets if dialog is inside the parent window or not.
*
* Once the dialog is built, this parameter canot be changed !
*
* If the 'inside' flag is set, then the parent must be set too before
* to build the dialog.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : 1 : inside, 0 not inside (value by default).
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetIsInside (iId, iIsInside)=
colorselect_setIsInside iId iIsInside;;
/*! \brief Gets if dialog is inside the parent window or not.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID.
* \return I : the current flag if success, or nil if error.
**/
fun ColorSelectGetIsInside (iId)=
colorslect_getIsInside iId;;
/*! \brief Sets the 'Apply' callback.
*
* This callback is not set by default. It should be defined before the
* first click on 'Apply' button by the user else nothing happens.
*
* The callback can be changed even after the dialog build.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I fun [I I I I] I] I
*
* \param I : the dialog ID.
* \param fun [I I I I] I : the function which is called when the user clicks
* on the 'Apply' button. These arguements are :
* - the ID dialog
* - the red component (0..255)
* - the green component (0..255)
* - the blue component (0..255)
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetCbApply (iId, funCb)=
colorselect_setCbApply iId funCb;;
/*! \brief Sets the 'Close' callback.
*
* This callback is not set by default.
*
* The callback can be changed even after the dialog build. If no button
* is displayed ( ColorSelectSetButtonShow ), ColorSelectGetColor may be
* used to retreive the last selected color by the user when the dialog
* is destroyed.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I fun [I] I] I
*
* \param I : the dialog ID.
* \param fun [I] I : the function which is called when the dialog is closed.
* The arguements is :
* - the ID dialog
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetCbClose (iId, funCb)=
colorselect_setCbClose iId funCb;;
/*! \brief Sets if a click on the 'Apply' button closes the dialog too.
*
* The value can be changed even after the dialog build.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : 1 : to close the dialog too, 0 else (value by default).
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetApplyBehavior (iId, iClose)=
colorselect_setApplyClose iId iClose;;
/*! \brief Sets if a click on the 'Apply' button closes the dialog too.
*
* The value can be changed even after the dialog build.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : 1 : to close the dialog too, 0 else (value by default).
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectGetApplyBehavior (iId)=
colorselect_getApplyClose iId;;
/*! \brief Sets the position of the dialog from the parent if set or from
* the screen.
*
* The value can be changed even after the dialog build. In this last case,
* the dialog is moved (inside its parent or on the screen if no parent set).
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I I] I
*
* \param I : the dialog ID.
* \param I : the 'x' coordinate (0 by default).
* \param I : the 'y' coordinate (0 by default).
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetPosition (iId, iX, iY)=
colorselect_setPosition iId iX iY;;
/*! \brief Sets the size of the dialog.
*
* The value can be changed even after the dialog build. In this last case,
* the dialog is resized (inside its parent or on the screen if no parent set).
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I I] I
*
* \param I : the dialog ID.
* \param I : the new width.
* \param I : the new height.
* \return I : the same ID if success, or nil if error.
*
* \see ColorSelectGetDefaults to retreive the default values.
**/
fun ColorSelectSetSize (iId, iWidth, iHeight)=
coloselect_setSize iId iWidth iHeight;;
/*! \brief Sets the title of the dialog.
*
* The value can be changed even after the dialog build. In this last case,
* the title is changed too (if the dialog is inside of a window, nothing is done).
*
* \ingroup _2dos_colorselect
* Prototype : fun [I S] I
*
* \param I : the dialog ID.
* \param S : the title. By default, it's "ColorSelect".
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetTitle (iId, szTitle)=
colorselect_setTitle iId szTitle;;
/*! \brief Sets the current color of the dialog sliders.
*
* The value can be changed even after the dialog build. In this last case,
* the dialog is repaint with the new color.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I I I] I
*
* \param I : the dialog ID.
* \param I : the red component (0..255).
* \param I : the green component (0..255).
* \param I : the blue component (0..255).
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetColor (iId, iRed, iGreen, iBlue)=
colorselect_setColor iId iRed iGreen iBlue;;
/*! \brief Gets the current color of the dialog sliders.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] [I I I]
*
* \param I : the dialog ID.
* \return [I I I] : the three RGB components (0..255 for each) if success, or nil if error.
**/
fun ColorSelectGetColor (iId)=
colorselect_getColor iId;;
/*! \brief Enables / Disables a dialog color box.
*
* The value can be changed even after the dialog build.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : 1 to enable, 0 to disable
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectEnable (iId, iState)=
colorselect_enable iId iState;;
/*! \brief Returns if a color dialog box is enabled or disabled.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID.
* \return I : 1 if enabled or 0 if disabled if success, or nil if error.
**/
fun ColorSelectEnabled (iId)=
colorselect_enabled iId;;
/*! \brief Showes / Hides a dialog color box.
*
* The value can be changed even after the dialog build.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : CS_SHOW to show, CS_HIDE to hide
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectShow (iId, iState)=
colorselect_show iId iState;;
/*! \brief Returns if a color dialog box is shown or hidden.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID.
* \return I : CS_SHOW if shown or CS_HIDE if hidden if success, or nil if error.
**/
fun ColorSelectShown (iId)=
colorselect_shown iId;;
/*! \brief Sets the short description of the dialog.
*
* The value can be changed even after the dialog build. In this last case,
* the content is changed too. If the new content is nil, the text fiel
* will be destroyed (it will be created again if a not nil content is set)
* but other graphical elements keep theirs positions.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I S] I
*
* \param I : the dialog ID.
* \param S : the short description. "Choose a color and click on 'Apply' button"
* is the default description.
* \return I : the same ID if success, or nil if error.
**/
fun ColorSelectSetShortDesc (iId, szDesc)=
colorselect_setShortDesc iId szDesc;;
/*! \brief Include or not the "Cancel" and the "Apply" buttons.
*
* Once the dialog is built, this parameter canot be changed !
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : 1 to show/include them (value by default), else 0
* \return I : the same ID if success, or nil if error.
*
* \see ColorSelectGetColor to retreive the last selected color by the user
* if the button "Apply" is not added.
**/
fun ColorSelectSetButtonShow (iId, iState)=
coloselect_setButtonShow iId iState;;
/*! \brief Returns if the "Cancel" and "Apply" buttons are shown.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID.
* \return I : 1 if shown else 0 if success, or nil if error.
**/
fun ColorSelectGetButtonShow (iId)=
coloselect_getButtonShow iId;;
/*! \brief Set the 'margin' around each graphical element.
*
* Once the dialog is built, this parameter canot be changed !
*
* \ingroup _2dos_colorselect
* Prototype : fun [I I] I
*
* \param I : the dialog ID.
* \param I : a positive value (5 by default)
* \return I : the same ID if success, or nil if error.
*
* \see ColorSelectGetDefaults to retreive the default value
**/
fun ColorSelectSetMargin (iId, iMargin)=
colorselect_setMargin iId iMargin;;
/*! \brief Returns the default size and the default 'margin'.
*
* \ingroup _2dos_colorselect
* Prototype : fun [] [I I I]
*
* \return [I I I] : the width, the height, the 'margin' defaults.
*
* \see ColorSelectSetSize
* \see ColorSelectSetMargin
**/
fun ColorSelectGetDefaults ()=
[CS_MINWIDTH CS_MINHEIGHT CS_MARGIN];;
/*! \brief Build the color dialog.
*
* This can only be called once until the dialog has been destroyed.
* In the most cases, the setters should be called before this.
*
* ColorSelectInit \b must \b always called before to build the dialog !
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID to build.
* \return I : the same ID if success, or nil if error.
*
* \see ColorSelectInit to initialize the dialog
**/
fun ColorSelectBuild (iId)=
colorselect_build iId;;
/*! \brief Destroy the color dialog without user action.
*
* Once destroyed, the setting are lost. It is callable even if the dialog
* has not been built.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID to build.
* \return I : 0 if success, or nil if error.
*
* \see ColorSelectInit to initialize the dialog
* \see ColorSelectSaveSetting to save the setting before the destroying.
**/
fun ColorSelectDestroy (iId)=
colorselect_destroy iId;;
/*! \brief Save the current setting of a dialog to initialize a new dialog.
*
* This can be called even after the dialog build.
*
* \ingroup _2dos_colorselect
* Prototype : fun [I] I
*
* \param I : the dialog ID to build.
* \return I : the new dialog id if success, or nil if error.
*
* \see ColorSelectInit to initialize the dialog
**/
fun ColorSelectSaveSetting (iId)=
colorslect_copySetting iId;;