mikshaw
Group: Members
Posts: 4856
Joined: July 2004 |
|
Posted: Jan. 10 2006,21:21 |
|
Here's my new colors reference widget. Thank you for your help.
Code Sample | #!/bin/flua
-- Color codes for Lua FLTK -- mikshaw 2005,2006 -- thanks to clacker and roberts for help
-- keep slider colors updated as values change function update_sliders() Color:set_color(100,slideR.value,slideG.value,slideB.value) slideR.selection_color = 100 slideG.selection_color = 100 slideB.selection_color = 100 slideR:redraw();slideG:redraw();slideB:redraw() end
-- default widget properties Fl_Widget.initializers = {textfont = 15, labelfont = 15,box=Boxtype.thin_up} Fl_Slider.initializers = {type=Slidertype.hor,align=Align.left,step=1,minimum=0,maximum=255,selection_color=0,callback=update_sliders} Fl_Box.initializers = {align=Align.right}
-- MAIN WINDOW ww = 480 wh = 365 w = Window{ww,wh,"Lua FLTK Colors"}
-- make a pretty window border frame = Box{1,1,ww-2,wh-2; box=Boxtype.engraved}
-- draw a column of numbered colors, 0-15 colors = {} for i = 0,15 do colors[i] = Box{30,15+i*20,80,20,tostring(i);color=i} end
-- draw a column of named colors cblack = Box{140,15,80,20,"black";color=Color.black} cred = Box{140,35,80,20,"red";color=Color.red} cgreen = Box{140,55,80,20,"green";color=Color.green} cyellow = Box{140,75,80,20,"yellow";color=Color.yellow} cblue = Box{140,95,80,20,"blue";color=Color.blue} cmagenta = Box{140,115,80,20,"magenta";color=Color.magenta} ccyan = Box{140,135,80,20,"cyan";color=Color.cyan} cwhite = Box{140,155,80,20,"white";color=Color.white} cselection = Box{140,315,80,20,"selection";color=Color.selection} cgray = Box{140,335,80,20,"gray (default)";color=Color.gray}
-- add a new color to the color table (orange) colors[16] = Color:set_color(16,255,165,0) new_color = Box{300,35,160,160,"New color (16): ";color=16,align=Align.top}
-- dropdown list of numbered colors retrieve_color = Choice{300,215,160,20;when=When.release + When.not_changed} for i = 0,16 do retrieve_color:add(Menu_Entry{"Get Color "..i}) end retrieve_color.value = 0 function retrieve_color.callback() slideR.value,slideG.value,slideB.value = Color:get_color(retrieve_color.value) update_sliders() end
-- color sliders, value 0-255 (see Fl_Slider.initializers for properties) slideR = Value_Slider{300,235,160,20,"R"} slideG = Value_Slider{300,255,160,20,"G"} slideB = Value_Slider{300,275,160,20,"B"}
-- changes the color of new color 16 and redraws it change_color = Button{300,295,160,20,"Apply to color 16"} function change_color.callback() Color:set_color(16,slideR.value,slideG.value,slideB.value) new_color:redraw() end
w:end_layout() w:show()
|
-------------- http://www.tldp.org/LDP/intro-linux/html/index.html
|