Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ 1 [2] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Colors in Flua?, welcoming any color-related input< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 10 2006,18:56 QUOTE

oooooh...that's exactly what i needed, thank you.
I noticed there was a way to add colors to the color table, but couldn't figure out what to use as a name.
Tried "orange = Color:set_color(Color.orange,255,165,0)", and of course that didn't work.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Jan. 10 2006,19:06 QUOTE

I was surprised how many colors you can have at once:

Code Sample
-- set up four colors
-- color table goes up to 255 slots?

temp = Color:set_color(17,255,165,0)
temp = Color:set_color(224,125,125,256)
temp = Color:set_color(258,25,25,125)
temp = Color:set_color(1001,25,125,125)

-- create a set of entries into the color table
-- 101 to 136 as a ramp of blue/red
-- 137 to 172 as a ramp of blue/green
for i = 1,36 do
   temp = Color:set_color(100+i,255-7*i,0,7*i)
end

for i = 1,36 do
   temp = Color:set_color(136+i,0,255-7*i,7*i)
end

w = Window{320,200,"Test Window"}
w.color = 17

--make a bunch of colored boxes
for i = 1,36 do
   myBox = Box{10*i,150,5,5}
   myBox.color = 100+i
   myBox.box = Boxtype.flat
end

for i = 1,36 do
   myBox = Box{10*i,160,5,5}
   myBox.color = 136+i
   myBox.box = Boxtype.flat
end

name = Input{76,10,210,25,"Name:"}
name.color = 224

myBox = Box{20,40,100,100}
myBox.color = Color.white
myBox.box = Boxtype.flat

myBox = Box{140,40,60,60}
myBox.color = 1001
myBox.box = Boxtype.flat

w:end_layout()
w:show()


You can also add your own color names for the numbers in the Color table:

Code Sample
temp = Color:set_color(17,255,165,0)
Color.orange = 17

myBox = Box{140,40,60,60}
myBox.color = Color.orange
myBox.box = Boxtype.flat
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Jan. 10 2006,21:21 QUOTE

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
Back to top
Profile PM WEB 
7 replies since Jan. 10 2006,03:24 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ 1 [2] >/
reply to topic new topic new poll
Quick Reply: Colors in Flua?

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code