rssColorpicker (cpicker)
Category: | script |
---|---|
Author(s): | Aibo |
Downloads: | 4262 |
Rate: | You need to be logged in to vote |
Rating: | 3.7 (37 Votes) |
Description:
This is a photoshop-like (simplified) HSV colorpicker window.
I know similar stuff has been made in dxscoreboard resource, but i always wanted a standalone colopicker.
This resource provides 2 exported functions:
exports.cpicker:openPicker(id, color, title)
returns true if picker was created successfully
or false if a picker for that ID is already open.
arguments:
id - element/string/whatever - stuff that will be returned in event for you to know for which element the picker was opened
color - optional, if set to hex color, will open picker with that color selected
title - optional, sets picker window title
exports.cpicker:closePicker(id)
closes the corresponding colorpicker window (same as "Cancel" button)
returns true if picker for supplied ID existed,
false otherwise
------
when "OK" pressed in picker, it triggers a client-side event "onColorPickerOK":
example usage:
-- simple editbox
local edit = guiCreateEdit(0, 0, 0.1, 0.05, "", true)
addEventHandler("onClientGUIDoubleClick", edit,
function()
-- adding a handler, so when editbox double-clicked, it'll open a colorpicker window:
exports.cpicker:openPicker(source, "#FFAA00", "Pick a color for some editbox:")
end)
-- this will be triggered when "OK" is pressed in colorpicker
addEventHandler("onColorPickerOK", root,
function(element, hex, r, g, b)
-- the following arguments are passed in the event:
-- element - contains whatever you passed when opened the picker
-- hex - hex code of picked color (in the form of "#RRGGBB")
-- r,g,b - r,g,b values of picked color
--
guiSetText(element, hex) -- set the picked hex value to the editbox
end)
---
UPDATE: "onColorPickerChange" event:
the same arguments passed to this event as "onColorPickerOK", example usage:
addEventHandler("onColorPickerChange", root,
function(element, hex, r, g, b)
-- assuming you've passed the vehicle element when opening colorpicker:
setVehicleColor(element, r, g, b)
end)
I know similar stuff has been made in dxscoreboard resource, but i always wanted a standalone colopicker.
This resource provides 2 exported functions:
exports.cpicker:openPicker(id, color, title)
returns true if picker was created successfully
or false if a picker for that ID is already open.
arguments:
id - element/string/whatever - stuff that will be returned in event for you to know for which element the picker was opened
color - optional, if set to hex color, will open picker with that color selected
title - optional, sets picker window title
exports.cpicker:closePicker(id)
closes the corresponding colorpicker window (same as "Cancel" button)
returns true if picker for supplied ID existed,
false otherwise
------
when "OK" pressed in picker, it triggers a client-side event "onColorPickerOK":
example usage:
-- simple editbox
local edit = guiCreateEdit(0, 0, 0.1, 0.05, "", true)
addEventHandler("onClientGUIDoubleClick", edit,
function()
-- adding a handler, so when editbox double-clicked, it'll open a colorpicker window:
exports.cpicker:openPicker(source, "#FFAA00", "Pick a color for some editbox:")
end)
-- this will be triggered when "OK" is pressed in colorpicker
addEventHandler("onColorPickerOK", root,
function(element, hex, r, g, b)
-- the following arguments are passed in the event:
-- element - contains whatever you passed when opened the picker
-- hex - hex code of picked color (in the form of "#RRGGBB")
-- r,g,b - r,g,b values of picked color
--
guiSetText(element, hex) -- set the picked hex value to the editbox
end)
---
UPDATE: "onColorPickerChange" event:
the same arguments passed to this event as "onColorPickerOK", example usage:
addEventHandler("onColorPickerChange", root,
function(element, hex, r, g, b)
-- assuming you've passed the vehicle element when opening colorpicker:
setVehicleColor(element, r, g, b)
end)
Version history
Version | Publish Date | Changes | |
---|---|---|---|
1.0.4 | 2011-11-28 07:19:50 | * fixed closePicker function name | Download |
1.0.3 | 2011-11-28 07:09:41 | * added multiple instances (more than 1 picker can be open at the same time) * therefore moved to OOP (i'm not a pro in that, so in case of any bugs - please report) |
Download |
1.0.2 | 2011-11-24 13:15:24 | * added "onColorPickerChange" client-side event (triggered every time color changes) | Download |
1.0.1 | 2011-11-24 12:17:35 | First public release | Download |