News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
feedback please
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: feedback please

Also having trouble with this one. The original had changed color index 15 in order to display a color chosen with fl_color_chooser(). That was annoying to me, and more annoying after I included the rgb and hex values in the tooltips of the colored boxes. I started using fl_rgb_color() to change the color of the color_chooser button so the initial 256 indexed colors wouldn't be bothered, and that seemed to work well until I noticed something weird.

There seems to be a bug in the way fl_rgb_color() is applying the colors in the red spectrum. Regardless of which color is chosen from the red side of the picker, the button always ends up being colored 128 0 0. The fl_color_cube button seems to receive the proper color from that chosen in the color picker, so I suspect either a bug in fl_rgb_color, or I'm not using it right.

EDIT: So far it looks like fl_rgb_color succeeds as long as the R value is less than 128. The G and B values can be whatever you want, but anything over 127 for R will cause the function to return 128 0 0. I'm surprised this hasn't come up before...no mention of it from a web search...so maybe something went weird in the murgaLua bindings?

Code:
w=fltk:Fl_Double_Window(500,400,"colors.lua")

-- make a 16x16 array of 20px boxes, 10px from the left edge
colors = {}
row=20;switch=15;bw=20;left=10
for i = 0,255 do
  colors[i]=fltk:Fl_Box(left+bw,row,bw,bw)
  colors[i]:color(i)
  colors[i]:box(fltk.FL_THIN_UP_BOX)
  local r,g,b=Fl:get_color(i,r,g,b) -- get RGB values of current color
  -- show color index, rgb, and html values in tooltip
  colors[i]:tooltip("Color index: "..i.."\nRGB: "..r.." "..g.." "..b.."\nHTML: "..string.format("#%.2X%.2X%.2X",r,g,b))
  left=left+bw -- next box will be placed 20px to the right
  if i == switch then -- if we have reached 16 boxes
    switch = switch+16  -- next switch position will be in 16 loops
    row = row+bw        -- move to next row
    left = 10           -- move back to first column
  end
end


colormap=fltk:Fl_Button(380,20,100,80,"fl_show_colormap")
colormap:align(fltk.FL_ALIGN_BOTTOM)
colormap:callback(
function(colormap_cb)
-- pick an indexed color and apply it to the button
  local newcolor=fltk.fl_show_colormap(colormap:color())
  colormap:color(newcolor)
  colormap:label("FLTK Color "..newcolor)
  w:redraw()
end
)

colorchooser=fltk:Fl_Button(380,125,100,80,"fl_color_chooser")
colorchooser:align(fltk.FL_ALIGN_BOTTOM)
colorchooser:callback(
function(colorchooser_cb)
  local color_ok,r,g,b -- initialize local variables
  r,g,b=Fl:get_color(colorchooser:color(),r,g,b)
  color_ok,r,g,b=fltk.fl_color_chooser("starting color: "..r.." "..g.." "..b,r,g,b)
  if color_ok == 1 then -- color_ok represents the first value (exit status) returned by fl_color_chooser
    hexcolor=string.format("#%.2X%.2X%.2X",r,g,b) -- convert the rgb values to hex
    colorchooser:color(fltk.fl_rgb_color(r,g,b)) -- apply rgb color to button
    -- set the color_cube box color
    color_cube:color(fltk.fl_color_cube(r * (fltk.FL_NUM_RED - 1) / 255,g * (fltk.FL_NUM_GREEN - 1) / 255,b * (fltk.FL_NUM_BLUE - 1) / 255))
    color_cube:label("fl_color_cube: "..color_cube:color())
    colorchooser:label("Color "..colorchooser:color().."\nRGB "..r.." "..g.." "..b.."\nHTML "..hexcolor)
    w:redraw()
  end
end
)

color_cube=fltk:Fl_Box(380,260,100,80,"fl_color_cube")
color_cube:align(fltk.FL_ALIGN_BOTTOM)
color_cube:box(fltk.FL_UP_BOX)

w:show()
Fl:run()

This post was last modified: 06-30-2009 03:09 AM by mikshaw.

06-30-2009 01:13 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
feedback please - mikshaw - 06-29-2009, 11:51 AM
RE: feedback please - mikshaw - 06-30-2009 01:13 AM
RE: feedback please - jpjacobs - 06-30-2009, 06:01 AM
RE: feedback please - mikshaw - 06-30-2009, 12:28 PM
RE: feedback please - jpjacobs - 07-01-2009, 04:21 AM
RE: feedback please - MrBill - 07-02-2009, 03:34 AM
RE: feedback please - mikshaw - 07-02-2009, 12:33 PM
RE: feedback please - jpjacobs - 11-29-2010, 10:08 PM
RE: feedback please - mikshaw - 11-30-2010, 01:55 PM
RE: feedback please - JohnMurga - 12-06-2010, 07:05 AM
RE: feedback please - mikshaw - 12-06-2010, 08:08 AM
RE: feedback please - jpjacobs - 12-06-2010, 10:05 AM
RE: feedback please - mikshaw - 12-07-2010, 01:37 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: