View Full Version : Set pixels vs bitmap image
LoneRobot 09-05-2006, 10:36 AM I get fed up making images for buttons in UI's the whole time, and much of the time i just want a small color on the button to differentiate it from others.
hence -
B1 = bitmap 90 10 color: (color 75 75 75)
button btn18 "" width:90 height:10 images:#(B1, undefined, 1, 1, 1, 1, 1)
if i wanted to make a disabled state for the button, i would have to have a bitmap twice as wide to incorporate the disabled state color.
Can i make this with the set pixels part of bitmap? Are there issues in terms of efficiency doing things this way or is it better to use a jpg of a flat colour?
i know what you're thinking, there's nowt so efficient as a button with "button" written on it but i guess i just want to know the merits of each way.
|
|
Light
10-11-2006, 02:04 AM
Hey Peter,
To make the triangular button, I created the image in photoshop. Then I have extracted the coordinate information using getPixel for black colors. From there I used the same coordinates to make them black on a white background, which acts as a mask.
From there it's just a matter of creating a single colored bitmap like bitmap 1 1 color:black to actually create the button. In this case I set the color to the text color in the active ui, which ensures that it will be visible in dark colored UIs too.
Please let me know if you have any questions.
Light
LoneRobot
10-11-2006, 10:20 AM
Hey Light,
Thanks for your reply! What a great way of doing this. So the image is a kind of reference thing just until you can get the pixel information and store it as an array? I assume you run a separate script to generate the array of pixel information from the image and then store that permanently as your "arr" array.
Getting the text color is a neat idea, im always getting slight issues because i run a dark UI and everyone else seems to like grey. (i guess that makes me the freak)
Are there any memory or speed issues associated with this?
Thanks for your input Light, it is greatly appreciated.
Light
10-11-2006, 11:42 AM
You can get the pixels with a fn like this:
fn getPixelCoords file color =
(
local img = openBitmap file
local arr = #(); for i = 1 to img.width do join arr (for f = 1 to img.height where (getPixels img[i,f] 1)[1] == color collect [i,f])
arr
)
As for memory and speed issues, there isn't one for a very small and 2 colored image like this (where we only set the minority pixels on top of a bitmap where the color is of the majority), and using a 1x1 bitmap for the background color of the button enhances the speed even more.
Light
LoneRobot
10-11-2006, 11:59 AM
Brilliant! i cant wait to try this out. In the C4 struct you specify a 14x14 as the background (white) bitmap mask, but you mention that you can use a 1x1 background image for speed. but i guess its all hypothetical on bitmaps this small! thanks again for your help!
Light
10-11-2006, 12:03 PM
Mask is 14x14, which should be 1:1 ratio, but the image behind should be made of a single color, which is visible through the mask.
Make sense?:)
Light
LoneRobot
10-11-2006, 12:12 PM
got it! you are a setpixels god!
Light
10-11-2006, 12:23 PM
Please post the results when you are done, if you are allowed. Just wondering the UI you have in mind.
Thanks,
Light
LoneRobot
10-11-2006, 12:32 PM
Sure thing! I think mostly i've been inspired with the idea of consistency between UI background colors, in the past i'd have to make separate map files for each. So I'll post as soon as i work on something. I dont know about you, it seems to take me three times as long to make the UIs than it does to write the code!
Light
10-11-2006, 12:42 PM
I also spend a great deal of time designing and planning the UIs, as it really improves the tool's quality and workflow. But after when it is done, coding generally takes alot of time, especially since I am so keen to write things shorter, faster and cleaner.
Light
antonv
10-11-2006, 04:55 PM
Light, your method is great! I was using the method shown in mxs reference where you get all the pixel values in an image and store them then you create a bitmap from them... Got to change some stuf around now ;)
Anton
davestewart
10-12-2006, 09:43 AM
Hey Guys,
Interesting thread! I wrote a struct library while back that does all this with one or two lines of code! It may need some cleaning up to go public.
Basically, you assign a button's image like this:
iconUtils.setButtonIcon ro1.btn1 #load
iconUtils.setButtonIcon ro1.btn2 #save
iconUtils.setButtonIcon ro1.btn3 #refresh fg:green
iconUtils.setButtonIcon ro1.btn4 #cross fg:red
And you convert b/w icons to code like this:
iconUtils.getIconDefs "c:/temp/icons/*.bmp"
The last bit is essential, as it means you can easily add your own icons to the library. I'll have a look, add some comments and get something online.
Cheers,
Dave
Light
10-12-2006, 01:27 PM
Hey Dave,
It looks very interesting. I will be sure to take a look.
Light
LoneRobot
10-13-2006, 05:33 PM
Nice one Dave, looks promising. I'll look forward to seeing it. That is exactly the sort of thing which could save loads of time when designing and building UIs.
CGTalk Moderation
10-13-2006, 05:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.