Jump to content

set colors to your gui easily


Vector

Recommended Posts

Hi, I want to show you how to change for example, the color of the text of an edit box or a memo,

or how to set the color for the text in the title of a window e.t.c (looks cool :) )

I created the next resource: https://community.multitheftauto.com/index.php?p=resources&s=details&id=7491

You can use the exported functions to achieve this.

I´ll explain how to use the functions:

-> guiSetColor () <-

1ºst parameter is the gui element you want to change the text/background color.

- if it is a window, the color of the text inside the title bar will be changed.

- if it is a button, checkbox, editbox, radiobutton, memo, combobox or text label the normal color of the

object´s text will be changed.

- if it is a static image, the image itself will be mixed (blended) with that color.

- the rest of the gui objects does not support this function.

Before the first parameter, you can specify the R-G-B components to set the color, or you can specify

one single parameter (a string), representing the color you want to set.

example.

  
local _window = guiCreateWindow (0.3, 0.3, 0.35, 0.25, "guicols example", true); -- this creates the window. 
exports.guicols:guiSetColor (_window,  0, 255, 0); -- this changes title bar text color to green. 
-- or this ... 
exports.guicols:guiSetColor (_window, "green"); 
  

see the images below to know what is the result.

the next predefined colors are provided:

  
"white", "silver", "gray", "black", "red", "maroon", "yellow", "olive", "lime", "green", "aqua", "teal", "blue", 
"navy", "fuchsia", "purple", "orange", "pink", "brown",  "aero", "amber", "aquamarine", "blond", "bronze", 
"burlywood", "celeste" 
  

another example.

  
-- this will create a memo in the center of the screen. 
local memo = guiCreateMemo (300, 300, 150, 70, "This is a multiline edit box. you can change the color of this text",  false); 
-- this will set the color of it´s text to orange. 
exports.guicols:guiSetColor (memo, "orange"); 
-- see the images below 
  

other example ...

  
local img = guiCreateStaticImage (300, 300, 128, 128, "img.png", false); 
local img2 = guiCreateStaticImage (500, 300, 128, 128, "img.png", false); 
local img3 = guiCreateStaticImage (700, 300, 128, 128, "img.png", false); 
  
exports.guicols:guiSetColor (img2, "pink");                  -- blend first image with pink color. 
exports.guicols:guiSetColor (img3, "aquamarine");       -- blend second image with aquamarine color. 
-- see the images below. 
  

-> guiSetSelectedTextColor () <-

this function has the same parameters as guiSetColor ()

this function can only be used on memos and edit boxes.

this just change the color of the selected text in the edit box or the memo.

example.

  
local memo = guiCreateMemo (400, 300, 150, 70, "This is just another memo", false); 
exports.guicols:guiSetColor (memo, "blue");   -- this will set to blue the text that is not selected. 
exports.guicols:guiSetSelectedTextColor (memo, "red");  -- this will set to red the text that is selected. 
  

the last function ..

-> guiSetDisabledColor () <-

this function has the same parameters than guiSetSelectedTextColor () and guiSetColor ()

this function is only supported for the next gui objects: check boxes and radio buttons.

this function set the color of the text of this objects when they are disabled via guiSetEnabled

here is an example.

  
-- this creates a radio button. 
local radio_button = guiCreateRadioButton (300, 400, 150, 20, "This is a radio button!", false);  
-- this will be the color of the text of the radio button when it´s enabled.  
exports.guicols:guiSetColor (radio_button, "navy"); 
-- and this set the color of the text of the radio button when it´s disabled. 
exports.guiCols:guiSetDisabledColor (radio_button, "celeste"); 
  

hope you like it. :D

windowgreen.png

memoornage.png

staticimage.png

anothermemo.png

Link to comment
  • 6 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...