# ============================================================================== # This file contains the following functions: # Public # RangeSet_askIfDarkBg # RangeSet_IsDarkBg # RangeSet_mapToDark # RangeSet_set_color # RangeSet_QuickColor # ============================================================================== NEDIT_require_macro_file("extensions.nm") NEDIT_require_macro_file("RSextensions.nm") NEDIT_require_macro_file("RSselect.nm") # ------------------------------------------------------------------------------ # RangeSet_mapToDark(color [, mul, div]): takes some "standard" color names and # returns dark versions of them if background_is_dark() returns true. Also # accepts hexadecimal color specifications of the form #rrggbb and # multiplies each color's value by mul/div (by default 1/2). This division # is avoided if the specification is an unrecognised color or if it starts # with "=" (in which case the "=" is removed). # ------------------------------------------------------------------------------ define RangeSet_mapToDark { mul = 1 div = 2 if ($n_args == 3) { mul = $2 div = $3 } if (mul > div) RangeSet_mapToDark_mult_factors_bad() # if the color spec starts with "=", strip off the "=" and return the rest if (search_string($1, "=", 0) == 0) return substring($1, 1) if (background_is_dark()) { # special fixed values if ($1 == "red") return "#7f0000" else if ($1 == "blue") return "#000080" else if ($1 == "green") return "#006000" else if ($1 == "cyan") return "#006090" else if ($1 == "magenta") return "#7f007f" else if ($1 == "yellow") return "#7f7000" else if ($1 == "brown") return "#421f1b" else if ($1 == "orange") return "#7f4f00" else if ($1 == "white") return "#7f7f7f" else if ($1 == "gray") return "#404040" else if ($1 == "black") return "#000000" if (search_string($1, "^(?i#[0-9a-f]{6})$", 0, "regex") == 0) { r = hex_to_int(substring($1, 1, 3)) * mul / div g = hex_to_int(substring($1, 3, 5)) * mul / div b = hex_to_int(substring($1, 5, 7)) * mul / div rr = int_to_hex(r, 2) gg = int_to_hex(g, 2) bb = int_to_hex(b, 2) return "#" rr gg bb } } # default value is the color passed in return $1 } # ------------------------------------------------------------------------------ # RangeSet_set_color(name[, color [, mul, div]]): sets the range set color, or # clears it. This uses RangeSet_set_color_basic(), overriding the version # in RSextensions.nm. Factors mul and div, if supplied, are passed to # RangeSet_mapToDark(). Returns the range set identifier. # ------------------------------------------------------------------------------ define RangeSet_set_color { if ($n_args == 1) return RangeSet_set_color_basic($1) else if ($n_args == 2) return RangeSet_set_color_basic($1, RangeSet_mapToDark($2)) else if ($n_args == 4) return RangeSet_set_color_basic($1, RangeSet_mapToDark($2, $3, $4)) else return RangeSet_set_color_bad() } # ------------------------------------------------------------------------------ # RangeSet_QuickColor([rs]): prompts the user for a color for the given range # set named rs from a fixed list. It will create the range set if it # doesn't already exist. If name is empty, it will prompt for a non-empty # name. It returns the name used, failing with the empty string. # ------------------------------------------------------------------------------ define RangeSet_QuickColor { rs = "" if ($n_args) rs = $1 col = "" list = "red\n" \ "blue\n" \ "green\n" \ "cyan\n" \ "magenta\n" \ "yellow\n" \ "brown\n" \ "orange\n" \ "white\n" \ "gray\n" \ "black\n" if (rs == "") { col = RangeSet_list_ask("Range set and color", "(Other)\n" list) rs = $RANGESET_SELECTED if (rs == "") return "" } if (col == "" || col == "(Other)") { if (col == "") { col = list_dialog("Color for range set \""rs"\"", "(Other)\n" list, \ "OK", "Other", "(None)", "Cancel") button = $list_dialog_button if (col == "(Other)") button = 2 } else button = 2 if (button < 1 || button > 3) return "" if (col == "" && button == 1) return "" if (button == 1) RangeSet_set_color(rs, col) else if (button == 2) { col = string_dialog("Color for range set \""rs"\"", \ "OK", "(None)", "Cancel") button = $string_dialog_button if (button == 2) # "Other" RangeSet_set_color(rs) else if (col == "" || $string_dialog_button != 1) return "" else RangeSet_set_color_basic(rs, col) } else # button == 3 # "(None)" RangeSet_set_color(rs) } else RangeSet_set_color(rs, col) return rs }