SetColor()<- with a string?
BlitzMax Forums/BlitzMax Beginners Area/SetColor()<- with a string?
| ||
Well I've been trying to make a methode within a function to set the color of my text box but then it gave me an error which I think means I have to separate the red, green and blue... Let's see:Method SGFX( img:String, col1:String, col2:String, col3:String ) image = img col1 = color1 col2 = color2 col3 = color3 End Method so then poof error Method Update() ' Drawing SetColor(color1) DrawRect x, y, w, h If I have to put a code to separate the R G B from the string in the loop won't that inder game performance? Since I don't need to recheck the color unless it's changed.. hmm but then again .. ohh ohh i could set an if statement to only separate the R G B whenever it changes thus not always redoing the code thus not indering my game's performance!? :O Another question how would I manipulate a string to read the numbers at start to "," and then the next tilll the other "," and then the next one till end of string? ("0,0,0") into separate variable that i could call colorR, colorG, colorB.. Thanks for the help. |
| ||
but then it gave me an error which I think means I have to separate the red, green and blue... What error did it give you? You're using strings for colour which, I believe, should be INT. The Setcolor command is Function SetColor( red,green,blue ) Description Set current color. Information The SetColor command affects the color of Plot, DrawRect, DrawLine, DrawText, DrawImage and DrawPoly. The red, green and blue parameters should be in the range of 0 to 255. which would be.. Setcolor (255,0,255) 'for that nasty pink colour. |
| ||
It says cannot convert to int. And if I did set it to int, I probably wouldn't be able to put any , in it no? |
| ||
Errr... no. The setcolor command takes an int so you need to give it an int. At the moment you're giving it a string. I probably wouldn't be able to put any , in it no? what do you mean by this? If you have the values in string variables then cast them to int. Maybe you should add some example code. |
| ||
Here's my complete type, basicly what you just showed me is the thing I thought of doing but then I need a RGB field for the 3 Color Field.. so I was thinking of processing the 3 colors(red,green,blue) in the same string so it would take less field or less space but then again your way is more practicle. I tend to over complicate things. Then with your way I could make methodes such as bgColor( red, green, blue) bdColor( red, green, blue) txtColor( red, green, blue) bgImage(location)... it might take more space but it will be alot more practicle so if I don't need to set a color I just dont set one. My full type would look like this: Type Tbutton Field text :String Field clicked :Int ' Structure [ x, y, w, h ] Field x :Float Field y :Float Field w :Int Field h :Int ' Image if any, Color1=BG, Color2=Borders, Color3=Text Field image :String Field color1 :Int Field color2 :String Field color3 :String Method Create( xstart:Float, ystart:Float, wstart:Int, hstart:Int, tstart:String ) x = xstart y = ystart w = wstart h = hstart text = tstart End Method Method SGFX( img:String, col1:String, col2:String, col3:String ) image = img col1 = color1 col2 = color2 col3 = color3 End Method Method Update() ' Drawing SetColor(color1) DrawRect x, y, w, h SetColor(color2) DrawLine( x, y, x+w, y) ' top DrawLine( x, y+h, x+w, y+h) ' bottom DrawLine( x, y, x, y+h) ' left DrawLine( x+w, y, x+w, y+h) ' right SetColor(color3) DrawText text, x+3, y End Method End Type |
| ||
OK. Out of interest why do you do this : ' Image if any, Color1=BG, Color2=Borders, Color3=Text Field image :String Field color1 :Int Field color2 :String Field color3 :String Why not call the fields background_color (or even bg_color) , Border_Color and text_color? In addition this doesn't seem right. Method SGFX( img:String, col1:String, col2:String, col3:String ) image = img col1 = color1 col2 = color2 col3 = color3 End Method You could save the ARGB as an int and then have a function to convert to RGB values. but I don't normally bother with that. |
| ||
Yeah old code is no good anymore. I just re-wrote a few things and instead of using color1-2-3... I've made it simpler by using ur ways and just make:Field bg_red:Int, bg_green:Int, bg_blue:Int Field bd_red:Int, bd_green:Int, bd_blue:Int Field tx_red:Int, tx_green:Int, tx_blue:Int and using: Method bgColor( red:Int, green:Int, blue:Int ) bg_red = red bg_green = green bg_blue = blue End Method Method bdColor( red:Int, green:Int, blue:Int ) bd_red = red bd_green = green bd_blue = blue End Method Method txColor( red:Int, green:Int, blue:Int ) tx_red = red tx_green = green tx_blue = blue End Method |