Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 28-Sep-2014 03:40:16

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Problem saving/retreiving color value from .xos file

I'm trying to save a color value to an .xos file with the editor package, and retrieve it with the client package, but something isn't working...
a related question...even through the colors in an object container contain alphabetic symbols, they are still integers in scol (albeit hexidecimal)...am I right there?


here is the xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<PLUGIN name="chatwindow" version="1.0" type="misc">

  <DESCRIPTION>Chat Window Plugit</DESCRIPTION>

  <HELP>Template plugIT help</HELP>

  <EDITOR>

    <SCRIPT path="./echatwindow.pkg" />

    <PARAM name="width" type="value" />
    <PARAM name="height" type="value" />
    <PARAM name="window_background_color_value" type="value" />

  </EDITOR>

  <CLIENT minstance="true">

    <SCRIPT path="./cchatwindow.pkg" />

    <ACTION name="Print Incoming Message">
    </ACTION>

    <EVENT name="Send Outgoing Message">
    </EVENT>

  </CLIENT>

</PLUGIN>

editor file

// prototype of the cbCloseEdit function in case you don't use params

//proto cbCloseEdit = fun [] [[S S] r1];;

//proto cbCloseEdit = fun [u0] [[S S] r1];;

// Close callback called on apply / Ok button, this callback return the parameters to save in the XOS project

fun cbCloseEdit(editorinterface)= 
   _hideconsole; 
	let editorinterface-> [ctrlwinw ctrlwinh window_background_color_button] in
  //get width value set in editor
  let ftoi getEdCtrlFloatValue ctrlwinw -> width in
  let ftoi getEdCtrlFloatValue ctrlwinh -> height in
  let getEdCtrlColorButtonColor window_background_color_button -> window_background_color in
  //change width value from integer to string and save in xos file
  ["width" itoa width]::
  ["height" itoa height]::
  ["window_background_color_value" itoa window_background_color]::
  nil;;





// Destroy callback called when the editor window is destroyed, this is useful to destroy added objects or resources

fun cbDestroyEdit()=

  0;;





// Init function called when a user the plugIT Editor

fun dynamicedit(winstr, inst, viewstr) =
  //get width value from .xos file

  let atof (getPluginInstanceParam inst "width") -> width in
  //if width not set, set it to 800
  let if width == nil then 800.0 else width -> width in 
  //get window_ background_color
  let atoi (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
  let if window_background_color == nil then 1 else window_background_color-> window_background_color in
  let atof (getPluginInstanceParam inst "height") -> height in
  //if width not set, set it to 800
  let if height == nil then 400.0 else height -> height in 
  let if height <. 150.0 then 150.0 else height -> height in 
  // size of the window
  let [400 290] -> [iw ih] in
  let 10 -> ypos in
  //create window width label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 120 20 "Window width" nil -> labelwinw in

  //create window width float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinw in
  //create window height label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 35) + 2 120 20 "Window Height" nil -> labelwinh in
 //create window height float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinh in 
 //create background color control  labbel
 let crEdCtrlLabel winstr 10 (set ypos = ypos + 55) + 2 160 20 "Window Background Color" nil -> window_background_color_label in
 //create background color control
 let crEdCtrlColorButton winstr 180 ypos 165 20 window_background_color 1 EDWIN_RESIZE_MW nil -> window_background_color_button in
  (
  
    // resize the editor window
    setEdWindowSize winstr iw ih;
    _showconsole;
    _fooI  window_background_color; 
    
    [mkfun1 @cbCloseEdit [ctrlwinw ctrlwinh window_background_color_button]  @cbDestroyEdit];
  );;

client file:

//struct definition
  struct Chatwindow = [
  CHATwindow_plugin_instance           				: PInstance,
  CHATwindow_window_object_container					: ObjContainer,  
  CHATwindow_parent_chat_window							: ObjWin,
  CHATwindow_chat_font										: ObjFont,
  CHATwindow_ongoing_chat_textfield						: CompText,
  CHATwindow_chat_entry_textfield						: CompText
  				
  ]mkChatwindow;;
  
 fun printmessage(constr, value)=
	_ADDcompText constr.CHATwindow_ongoing_chat_textfield strcatn value:: "":: "\n"::nil constr.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_END;
	_PAINTcontainer constr.CHATwindow_window_object_container;
 0;;
 
 fun cbprintmessage(inst, from, action, param, reply, constr)=
 	printmessage constr param;
 	0;;
 

fun cbDestroy(inst, from, action, param, reply, constr)=
	_DScompText constr.CHATwindow_ongoing_chat_textfield;
	_DScompText constr.CHATwindow_chat_entry_textfield;
	_DSfont constr.CHATwindow_chat_font;
	_DScontainer constr.CHATwindow_window_object_container;
	_DSwindow constr.CHATwindow_parent_chat_window;

0;;

fun deleteOb(inst, constr)=

  cbDestroy inst nil nil nil nil constr;

  0;;

//add text to ongoing_chat_textfield here
fun addtext(textobject, user_parameter,type,value)=
	//update contents of chat interface
	let ""-> empty_text_value in
		(
			_ADDcompText user_parameter.CHATwindow_ongoing_chat_textfield strcatn value:: "":: "\n"::nil user_parameter.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_END;
			_PAINTcontainer user_parameter.CHATwindow_window_object_container;
  			_SETcompText textobject "" user_parameter.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_BEGIN; 

			_PAINTcontainer user_parameter.CHATwindow_window_object_container;
			 _DMSevent this (getPluginInstanceEvent user_parameter.CHATwindow_plugin_instance "Send Outgoing Message") value nil;
			0;
		);
0;;
///create plugit function
fun newOb(inst)=
   //get width value from .xos file
   let atoi (getPluginInstanceParam inst "width") -> width in
   let atoi (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
   //get height value from .xos file
   let atoi (getPluginInstanceParam inst "height") -> height in
	let _CRwindow _channel DMSwin 0 0 width height WN_TOPMOST "A window"  -> thisparentchatwindow in
	let _CRcontainerFromObjWin _channel thisparentchatwindow 0 0 width height CO_CHILDINSIDE window_background_color "hackerwindow" -> thiscontainer in
	let _CRfont _channel 12 0 0 "Lucida Console"-> thisfont in
	let  _CRcompText _channel thiscontainer  nil [0 (height-50)] OBJ_ENABLE|OBJ_VISIBLE|CT_LEFT|CT_WORDWRAP|CT_EDITLINE 0 width 50  "text entry field" 		thisfont [0x00FFFF 0 0 0xFFFF00] [0xFFFFFF 50] nil nil   -> thistextentryfield in
	let _CRcompText _channel thiscontainer nil [0 0] OBJ_ENABLE|OBJ_VISIBLE|CT_LEFT|CT_LABEL|CT_WORDWRAP|CT_LABEL|CT_SELECT OBJ_CONTAINER_KEYDOWN width (set height= height-50)  strcat "ongoing chat text here"  "\n" thisfont [0x00FFFF 0 0 0xFFFF00] [0xFFFFFF 50] nil nil-> thisongoingchatfield in
	let itoa window_background_color-> colorstring in
	
	let mkChatwindow [inst thiscontainer thisparentchatwindow thisfont thisongoingchatfield thistextentryfield]->constr in
		(

			_showconsole;
			_fooS colorstring;
			_CBcompTextValidation constr.CHATwindow_chat_entry_textfield @addtext constr  CT_VALIDENTER;
			_PAINTcontainer constr.CHATwindow_window_object_container;
			PluginRegisterAction inst "Print Incoming Message" mkfun6 @cbprintmessage constr;
			//PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr;

			setPluginInstanceCbDel inst mkfun2 @deleteOb constr;

		);
0;;



fun IniPlug(file)=

  PlugRegister @newOb nil;

  setPluginEditor @dynamicedit;

  0;;
  
  
  

should I be defining a callback for the color button in the editor? I used the material plugit as a reference, although I couldn't find any callbacks for the color buttons (perhaps they don't need them?)

the colors are not being saved, regardless of what color I pick, and the color that is retrieved is not being transferred to the objectcontainer that contains that color value. hmm

thx for your help!

Offline

#2 28-Sep-2014 13:09:30

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: Problem saving/retreiving color value from .xos file

Hi,

window_background_color is never set when you select a color.
In your code, this is only a variable which set from the .xos file during the loading.

Probably, you should use getEdCtrlColorButtonColor to retreive the last selected color.
If no value is defined in the .xos file, it will be nil and the container will not be painted..

In the close function :

// ...
  ["width" itoa width]::
  ["height" itoa height]::
  ["window_background_color_value" itoh getEdCtrlColorButtonColor window_background_color_button]::
  nil;;

getEdCtrlColorButtonColor : http://redmine.scolring.org/projects/op … 2dglib.pkg (line 10881)

hebdemnobad wrote:

a related question...even through the colors in an object container contain alphabetic symbols, they are still integers in scol (albeit hexidecimal)...am I right there?

0x1245AD is an integer (in hexadecimal)
"12345AD" is a string
htoi "12345AD" is an integer (in hexadecimal)
atoi "12345AD" is another integer !! Be carefull !
12345AD is an error.

atoi : http://www.scolring.org/files/doc_html/atoi.html
htoi : http://www.scolring.org/files/doc_html/htoi.html
itoh : http://www.scolring.org/files/doc_html/itoh.html

Offline

#3 28-Sep-2014 13:55:34

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

thx for your response Iri, I didn't know about hexidecimal strings. I'm still having the problem of setting and retreiving the background color that appears in the plugit interface....here's the editor file:

// prototype of the cbCloseEdit function in case you don't use params

//proto cbCloseEdit = fun [] [[S S] r1];;

//proto cbCloseEdit = fun [u0] [[S S] r1];;

// Close callback called on apply / Ok button, this callback return the parameters to save in the XOS project

fun cbCloseEdit(editorinterface)= 
   _hideconsole; 
	let editorinterface-> [ctrlwinw ctrlwinh window_background_color_button] in
  //get width value set in editor
  let ftoi getEdCtrlFloatValue ctrlwinw -> width in
  let ftoi getEdCtrlFloatValue ctrlwinh -> height in
  //change width value from integer to string and save in xos file
  ["width" itoa width]::
  ["height" itoa height]::
  ["window_background_color_value" itoh getEdCtrlColorButtonColor window_background_color_button]::
  nil;;





// Destroy callback called when the editor window is destroyed, this is useful to destroy added objects or resources

fun cbDestroyEdit()=

  0;;





// Init function called when a user the plugIT Editor

fun dynamicedit(winstr, inst, viewstr) =
  //get width value from .xos file

  let atof (getPluginInstanceParam inst "width") -> width in
  //if width not set, set it to 800
  let if width == nil then 800.0 else width -> width in 
  //get window_ background_color
  let htoi   (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
  let if window_background_color == nil then 0x000000 else window_background_color-> window_background_color in
  let atof (getPluginInstanceParam inst "height") -> height in
  //if width not set, set it to 800
  let if height == nil then 400.0 else height -> height in 
  let if height <. 150.0 then 150.0 else height -> height in 
  // size of the window
  let [400 290] -> [iw ih] in
  let 10 -> ypos in
  //create window width label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 120 20 "Window width" nil -> labelwinw in

  //create window width float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinw in
  //create window height label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 35) + 2 120 20 "Window Height" nil -> labelwinh in
 //create window height float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinh in 
 //create background color control  labbel
 let crEdCtrlLabel winstr 10 (set ypos = ypos + 55) + 2 160 20 "Window Background Color" nil -> window_background_color_label in
 //create background color control
 let crEdCtrlColorButton winstr 180 ypos 165 20 window_background_color 1 EDWIN_RESIZE_MW nil -> window_background_color_button in
  (
  
    // resize the editor window
    setEdWindowSize winstr iw ih;
    _showconsole;
    _fooI  window_background_color; 
    
    [mkfun1 @cbCloseEdit [ctrlwinw ctrlwinh window_background_color_button]  @cbDestroyEdit];
  );;

Offline

#4 28-Sep-2014 14:09:37

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: Problem saving/retreiving color value from .xos file

_fooI always displays an integer in hexadecimal.
_fooId always displays an integer in decimal.

Offline

#5 28-Sep-2014 16:30:14

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

iri wrote:

_fooI always displays an integer in hexadecimal.
_fooId always displays an integer in decimal.

thx, although that doesn't address the problem (but I always welcome your reminders...)

here is the difference between what the color button in the editor interface shows and the color of the objectcontainer....something isn't getting saved/retrieved in the right format....
funny color behavior

And sometimes when I pick a color from the color button, the client file interprets it as 'nil' and sets the background to black:funny color nil

and lastly, if I pick a color, save it to the editor, and then open up the editor again, the color has changed....
does this have something to do with changing hexidecimal to rgba values?

I have reposted the client, editor, and xml files (updated) to http://ifam.net/openspace/chatwindow/chatwindow.zip

Last edited by hebdemnobad (28-Sep-2014 16:31:57)

Offline

#6 28-Sep-2014 16:44:21

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

the ematcolor editor file doesn't use hexidecimal values...it saves colors by changing integers to  strings (itoa inthe cbcloseedit function) and retrieves colors by changing them from strings into integers, atoi (in the dynamicedit function).

the objectcontainer uses colors in hexidecimal format, so perhaps I should be changing from the color picker rgb format to hexidecimal and back again?

should I be using these? (from http://redmine.scolring.org/projects/op … 480a1bdd8)

G2DformatHexaColor (s)
Add missed colors in hexa format. 
G2DformatHexaColorI (c)
format color to hexadecimal value 

Last edited by hebdemnobad (28-Sep-2014 16:49:46)

Offline

#7 28-Sep-2014 17:34:08

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

I tried using G2DformatHexaColor  without success...since the editor file doesn't have to translate the integer into hex format, I only used the G2DformatHexaColor  in the client file since the objectcontainer uses hex formatted colors.

client file

//struct definition
  struct Chatwindow = [
  CHATwindow_plugin_instance           				: PInstance,
  CHATwindow_window_object_container					: ObjContainer,  
  CHATwindow_parent_chat_window							: ObjWin,
  CHATwindow_chat_font										: ObjFont,
  CHATwindow_ongoing_chat_textfield						: CompText,
  CHATwindow_chat_entry_textfield						: CompText
  				
  ]mkChatwindow;;
  
 fun printmessage(constr, value)=
	_ADDcompText constr.CHATwindow_ongoing_chat_textfield strcatn value:: "":: "\n"::nil constr.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_END;
	_PAINTcontainer constr.CHATwindow_window_object_container;
 0;;
 
 fun cbprintmessage(inst, from, action, param, reply, constr)=
 	printmessage constr param;
 	0;;
 

fun cbDestroy(inst, from, action, param, reply, constr)=
	_DScompText constr.CHATwindow_ongoing_chat_textfield;
	_DScompText constr.CHATwindow_chat_entry_textfield;
	_DSfont constr.CHATwindow_chat_font;
	_DScontainer constr.CHATwindow_window_object_container;
	_DSwindow constr.CHATwindow_parent_chat_window;

0;;

fun deleteOb(inst, constr)=
	_hideconsole; 

  cbDestroy inst nil nil nil nil constr;

  0;;

//add text to ongoing_chat_textfield here
fun addtext(textobject, user_parameter,type,value)=
	//update contents of chat interface
	let ""-> empty_text_value in
		(
			_ADDcompText user_parameter.CHATwindow_ongoing_chat_textfield strcatn value:: "":: "\n"::nil user_parameter.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_END;
			_PAINTcontainer user_parameter.CHATwindow_window_object_container;
  			_SETcompText textobject "" user_parameter.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_BEGIN; 

			_PAINTcontainer user_parameter.CHATwindow_window_object_container;
			 _DMSevent this (getPluginInstanceEvent user_parameter.CHATwindow_plugin_instance "Send Outgoing Message") value nil;
			0;
		);
0;;
///create plugit function
fun newOb(inst)=
   //get width value from .xos file
   let atoi (getPluginInstanceParam inst "width") -> width in
   //let htoi  (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
   //turn background color string to integer
   let atoi  (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
   //convert background color interger into hex format string
   let G2DformatHexaColorI window_background_color-> window_background_color in
   //convert background color hex format string to Interger of hex color value
   let atoi window_background_color-> window_background_color in
   //get height value from .xos file
   let atoi (getPluginInstanceParam inst "height") -> height in
	let _CRwindow _channel DMSwin 0 0 width height WN_TOPMOST "A window"  -> thisparentchatwindow in
	let _CRcontainerFromObjWin _channel thisparentchatwindow 0 0 width height CO_CHILDINSIDE window_background_color "hackerwindow" -> thiscontainer in
	let _CRfont _channel 12 0 0 "Lucida Console"-> thisfont in
	let  _CRcompText _channel thiscontainer  nil [0 (height-50)] OBJ_ENABLE|OBJ_VISIBLE|CT_LEFT|CT_WORDWRAP|CT_EDITLINE 0 width 50  "text entry field" 		thisfont [0x00FFFF 0 0 0xFFFF00] [0xFFFFFF 50] nil nil   -> thistextentryfield in
	let _CRcompText _channel thiscontainer nil [0 0] OBJ_ENABLE|OBJ_VISIBLE|CT_LEFT|CT_LABEL|CT_WORDWRAP|CT_LABEL|CT_SELECT OBJ_CONTAINER_KEYDOWN width (set height= height-50)  strcat "ongoing chat text here"  "\n" thisfont [0x00FFFF 0 0 0xFFFF00] [0xFFFFFF 50] nil nil-> thisongoingchatfield in
	let itoa window_background_color-> colorstring in
	
	let mkChatwindow [inst thiscontainer thisparentchatwindow thisfont thisongoingchatfield thistextentryfield]->constr in
		(

			_showconsole;
			_fooS "the background color is \n";
			_fooS colorstring;
			_CBcompTextValidation constr.CHATwindow_chat_entry_textfield @addtext constr  CT_VALIDENTER;
			_PAINTcontainer constr.CHATwindow_window_object_container;
			PluginRegisterAction inst "Print Incoming Message" mkfun6 @cbprintmessage constr;
			//PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr;

			setPluginInstanceCbDel inst mkfun2 @deleteOb constr;

		);
0;;



fun IniPlug(file)=

  PlugRegister @newOb nil;

  setPluginEditor @dynamicedit;

  0;;
  
  
  

I tried using itoa to save the color value and atoi to retreive it in the editor file, as it in the material plugit editor file
editor file, but the colors are not remembered correctly in the editor itself (if i pick a color and hit ok, closing the editor, when I open the editor up again, the color button is a different color...perhaps rgb values are being reversed in some way or somehow mixed up?)

so there are two problems: saving a color to a string and then not getting the same color when i retrieve it when i open the editor
and the second is that the client does not display the color I set in the editor while it is still open (using the apply button) and sometimes thinks a color is nil when I have picked something that is not nil.

// prototype of the cbCloseEdit function in case you don't use params

//proto cbCloseEdit = fun [] [[S S] r1];;

//proto cbCloseEdit = fun [u0] [[S S] r1];;

// Close callback called on apply / Ok button, this callback return the parameters to save in the XOS project

fun cbCloseEdit(editorinterface)= 
  let editorinterface-> [ctrlwinw ctrlwinh window_background_color_button] in
  //get width value set in editor
  let ftoi getEdCtrlFloatValue ctrlwinw -> width in
  let ftoi getEdCtrlFloatValue ctrlwinh -> height in
  //change width value from integer to string and save in xos file
  ["width" itoa width]::
  ["height" itoa height]::
  //["window_background_color_value" (itoh getEdCtrlColorButtonColor window_background_color_button)]::
  ["window_background_color_value" (itoa getEdCtrlColorButtonColor window_background_color_button)]::
  nil;;





// Destroy callback called when the editor window is destroyed, this is useful to destroy added objects or resources

fun cbDestroyEdit()=

  0;;





// Init function called when a user the plugIT Editor

fun dynamicedit(winstr, inst, viewstr) =
  //get width value from .xos file

  let atof (getPluginInstanceParam inst "width") -> width in
  //if width not set, set it to 800
  let if width == nil then 800.0 else width -> width in 
  //get window_ background_color
  let atoi   (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
  //let G2DformatHexaColorI window_background_color-> window_background_color in
  let if window_background_color == nil then 0x000000 else window_background_color-> window_background_color in
  let atof (getPluginInstanceParam inst "height") -> height in
  //if width not set, set it to 800
  let if height == nil then 400.0 else height -> height in 
  let if height <. 150.0 then 150.0 else height -> height in 
  // size of the window
  let [400 290] -> [iw ih] in
  let 10 -> ypos in
  //create window width label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 120 20 "Window width" nil -> labelwinw in

  //create window width float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinw in
  //create window height label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 35) + 2 120 20 "Window Height" nil -> labelwinh in
 //create window height float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinh in 
 //create background color control  labbel
 let crEdCtrlLabel winstr 10 (set ypos = ypos + 55) + 2 160 20 "Window Background Color" nil -> window_background_color_label in
 //create background color control
 let crEdCtrlColorButton winstr 180 ypos 165 20 window_background_color 1 EDWIN_RESIZE_MW nil -> window_background_color_button in
  (
  
    // resize the editor window
    setEdWindowSize winstr iw ih; 
    
    [mkfun1 @cbCloseEdit [ctrlwinw ctrlwinh window_background_color_button]  @cbDestroyEdit];
  );;

Last edited by hebdemnobad (28-Sep-2014 17:37:02)

Offline

#8 28-Sep-2014 23:07:27

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: Problem saving/retreiving color value from .xos file

hi

try in rgb only http://redmine.scolring.org/projects/op … 6e0af44f31
// 1 for RGBA colors, 0 for RGB

Offline

#9 29-Sep-2014 01:51:43

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

Thx I got it working. Will post code tomorrow.

Offline

#10 29-Sep-2014 15:27:46

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

smile

editor:

// prototype of the cbCloseEdit function in case you don't use params

//proto cbCloseEdit = fun [] [[S S] r1];;

//proto cbCloseEdit = fun [u0] [[S S] r1];;

// Close callback called on apply / Ok button, this callback return the parameters to save in the XOS project

fun cbCloseEdit(editorinterface)= 
  let editorinterface-> [ctrlwinw ctrlwinh window_background_color_button] in
  //get width value set in editor
  let ftoi getEdCtrlFloatValue ctrlwinw -> width in
  let ftoi getEdCtrlFloatValue ctrlwinh -> height in
  //change width value from integer to string and save in xos file
  ["width" itoa width]::
  ["height" itoa height]::
  //["window_background_color_value" (itoh getEdCtrlColorButtonColor window_background_color_button)]::
  ["window_background_color_value" (itoh getEdCtrlColorButtonColor window_background_color_button)]::
  nil;;





// Destroy callback called when the editor window is destroyed, this is useful to destroy added objects or resources

fun cbDestroyEdit()=

  0;;





// Init function called when a user the plugIT Editor

fun dynamicedit(winstr, inst, viewstr) =
  //get width value from .xos file

  let atof (getPluginInstanceParam inst "width") -> width in
  //if width not set, set it to 800
  let if width == nil then 800.0 else width -> width in 
  //get window_ background_color
  let htoi   (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
  //let G2DformatHexaColorI window_background_color-> window_background_color in
  let if window_background_color == nil then 0x000000 else window_background_color-> window_background_color in
  let atof (getPluginInstanceParam inst "height") -> height in
  //if width not set, set it to 800
  let if height == nil then 400.0 else height -> height in 
  let if height <. 150.0 then 150.0 else height -> height in 
  // size of the window
  let [400 290] -> [iw ih] in
  let 10 -> ypos in
  //create window width label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 25) + 2 120 20 "Window width" nil -> labelwinw in

  //create window width float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinw in
  //create window height label
  let crEdCtrlLabel winstr 10 (set ypos = ypos + 35) + 2 120 20 "Window Height" nil -> labelwinh in
 //create window height float control
  let crEdCtrlFloat winstr 130 ypos 100 20 width 0.0 12000.0 1.0 0 nil EDWIN_RESIZE_MW -> ctrlwinh in 
 //create background color control  labbel
 let crEdCtrlLabel winstr 10 (set ypos = ypos + 55) + 2 160 20 "Window Background Color" nil -> window_background_color_label in
 //create background color control
 let crEdCtrlColorButton winstr 180 ypos 165 20 window_background_color 0 EDWIN_RESIZE_MW nil -> window_background_color_button in
  (
  
    // resize the editor window
    setEdWindowSize winstr iw ih; 
    
    [mkfun1 @cbCloseEdit [ctrlwinw ctrlwinh window_background_color_button]  @cbDestroyEdit];
  );;

client:

//struct definition
  struct Chatwindow = [
  CHATwindow_plugin_instance           				: PInstance,
  CHATwindow_window_object_container					: ObjContainer,  
  CHATwindow_parent_chat_window							: ObjWin,
  CHATwindow_chat_font										: ObjFont,
  CHATwindow_ongoing_chat_textfield						: CompText,
  CHATwindow_chat_entry_textfield						: CompText
  				
  ]mkChatwindow;;
  
 fun printmessage(constr, value)=
	_ADDcompText constr.CHATwindow_ongoing_chat_textfield strcatn value:: "":: "\n"::nil constr.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_END;
	_PAINTcontainer constr.CHATwindow_window_object_container;
 0;;
 
 fun cbprintmessage(inst, from, action, param, reply, constr)=
 	printmessage constr param;
 	0;;
 

fun cbDestroy(inst, from, action, param, reply, constr)=
	_DScompText constr.CHATwindow_ongoing_chat_textfield;
	_DScompText constr.CHATwindow_chat_entry_textfield;
	_DSfont constr.CHATwindow_chat_font;
	_DScontainer constr.CHATwindow_window_object_container;
	_DSwindow constr.CHATwindow_parent_chat_window;

0;;

fun deleteOb(inst, constr)=
	_hideconsole; 

  cbDestroy inst nil nil nil nil constr;

  0;;

//add text to ongoing_chat_textfield here
fun addtext(textobject, user_parameter,type,value)=
	//update contents of chat interface
	let ""-> empty_text_value in
		(
			_ADDcompText user_parameter.CHATwindow_ongoing_chat_textfield strcatn value:: "":: "\n"::nil user_parameter.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_END;
			_PAINTcontainer user_parameter.CHATwindow_window_object_container;
  			_SETcompText textobject "" user_parameter.CHATwindow_chat_font [0x00FFFF 0 0 0xFFFF00] CT_BEGIN; 

			_PAINTcontainer user_parameter.CHATwindow_window_object_container;
			 _DMSevent this (getPluginInstanceEvent user_parameter.CHATwindow_plugin_instance "Send Outgoing Message") value nil;
			0;
		);
0;;
///create plugit function
fun newOb(inst)=
   //get width value from .xos file
   let atoi (getPluginInstanceParam inst "width") -> width in
   let htoi  (getPluginInstanceParam inst "window_background_color_value") -> window_background_color in
   //get height value from .xos file
   let atoi (getPluginInstanceParam inst "height") -> height in
	let _CRwindow _channel DMSwin 0 0 width height WN_TOPMOST "A window"  -> thisparentchatwindow in
	let _CRcontainerFromObjWin _channel thisparentchatwindow 0 0 width height CO_CHILDINSIDE window_background_color "hackerwindow" -> thiscontainer in
	let _CRfont _channel 12 0 0 "Lucida Console"-> thisfont in
	let  _CRcompText _channel thiscontainer  nil [0 (height-50)] OBJ_ENABLE|OBJ_VISIBLE|CT_LEFT|CT_WORDWRAP|CT_EDITLINE 0 width 50  "text entry field" 		thisfont [0x00FFFF 0 0 0xFFFF00] [0xFFFFFF 50] nil nil   -> thistextentryfield in
	let _CRcompText _channel thiscontainer nil [0 0] OBJ_ENABLE|OBJ_VISIBLE|CT_LEFT|CT_LABEL|CT_WORDWRAP|CT_LABEL|CT_SELECT OBJ_CONTAINER_KEYDOWN width (set height= height-50)  strcat "ongoing chat text here"  "\n" thisfont [0x00FFFF 0 0 0xFFFF00] [0xFFFFFF 50] nil nil-> thisongoingchatfield in
	let itoa window_background_color-> colorstring in
	
	let mkChatwindow [inst thiscontainer thisparentchatwindow thisfont thisongoingchatfield thistextentryfield]->constr in
		(

			_showconsole;
			_fooS "the background color is \n";
			_fooS colorstring;
			_CBcompTextValidation constr.CHATwindow_chat_entry_textfield @addtext constr  CT_VALIDENTER;
			_PAINTcontainer constr.CHATwindow_window_object_container;
			PluginRegisterAction inst "Print Incoming Message" mkfun6 @cbprintmessage constr;
			//PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr;

			setPluginInstanceCbDel inst mkfun2 @deleteOb constr;

		);
0;;



fun IniPlug(file)=

  PlugRegister @newOb nil;

  setPluginEditor @dynamicedit;

  0;;
  
  
  

lots of colors

Last edited by hebdemnobad (29-Sep-2014 15:31:31)

Offline

#11 29-Sep-2014 15:30:04

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: Problem saving/retreiving color value from .xos file

smile

Offline

#12 29-Sep-2014 15:33:14

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

so is it correct arkeon that the os3d plugit color button and map use rgba or rgb format and I will have to convert back and forth from hex to interger if I am using scol components that use hex intergers for colors (like containers, comptext, other non-os3d specific parts of scol api?)

Offline

#13 29-Sep-2014 15:36:12

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: Problem saving/retreiving color value from .xos file

hmm hmm not sure I don't remember all this parts, but there is all the needed functions in G2Dlib for color conversions

Offline

#14 29-Sep-2014 15:39:03

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: Problem saving/retreiving color value from .xos file

arkeon wrote:

hmm hmm not sure I don't remember all this parts, but there is all the needed functions in G2Dlib for color conversions

I see....it turned out I didn't need the G2 api, just itoh and htoi and itoa and atoi. But maybe it will be useful.
I'm really enjoying this plugit programming, hopefully other people can think up other uses for this modest project. I will add most parameters (for font type (I will need a bit of orientation for getting the font list and integrating it in the editor, as well as saving and retrieving the list), the window parameters, etc.

Offline

#15 29-Sep-2014 17:18:31

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: Problem saving/retreiving color value from .xos file

The font must exist on the client system, so you usually use system default ones.
"arial", "tahoma", "system" ...

Offline

Board footer

Powered by FluxBB