Mercurial > vim
comparison src/gui_photon.c @ 9013:22c29a515b53 v7.4.1792
commit https://github.com/vim/vim/commit/ab3022196ea4f1496e79b8ee85996e31c45d02f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 26 20:59:29 2016 +0200
patch 7.4.1792
Problem: Color name decoding is implemented several times.
Solution: Move it to term.c. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 26 Apr 2016 21:00:07 +0200 |
parents | bcef391c101c |
children | bb86514cad15 |
comparison
equal
deleted
inserted
replaced
9012:3390e71380fa | 9013:22c29a515b53 |
---|---|
1969 #endif | 1969 #endif |
1970 | 1970 |
1971 PtSetResource(gui.vimTextArea, Pt_ARG_FILL_COLOR, gui.back_pixel, 0); | 1971 PtSetResource(gui.vimTextArea, Pt_ARG_FILL_COLOR, gui.back_pixel, 0); |
1972 } | 1972 } |
1973 | 1973 |
1974 static int | |
1975 hex_digit(int c) | |
1976 { | |
1977 if (VIM_ISDIGIT(c)) | |
1978 return c - '0'; | |
1979 c = TOLOWER_ASC(c); | |
1980 if (c >= 'a' && c <= 'f') | |
1981 return c - 'a' + 10; | |
1982 return -1000; | |
1983 } | |
1984 | |
1985 | |
1986 /* | 1974 /* |
1987 * This should be split out into a separate file, | 1975 * This should be split out into a separate file, |
1988 * every port does basically the same thing. | 1976 * every port does basically the same thing. |
1989 * | 1977 * |
1990 * This is the gui_w32.c version (i think..) | 1978 * This is the gui_w32.c version (i think..) |
1992 */ | 1980 */ |
1993 | 1981 |
1994 guicolor_T | 1982 guicolor_T |
1995 gui_mch_get_color(char_u *name) | 1983 gui_mch_get_color(char_u *name) |
1996 { | 1984 { |
1997 int i; | 1985 return gui_get_color_cmn(name); |
1998 int r, g, b; | |
1999 | |
2000 | |
2001 typedef struct GuiColourTable | |
2002 { | |
2003 char *name; | |
2004 guicolor_T colour; | |
2005 } GuiColourTable; | |
2006 | |
2007 static GuiColourTable table[] = | |
2008 { | |
2009 {"Black", RGB(0x00, 0x00, 0x00)}, | |
2010 {"DarkGray", RGB(0xA9, 0xA9, 0xA9)}, | |
2011 {"DarkGrey", RGB(0xA9, 0xA9, 0xA9)}, | |
2012 {"Gray", RGB(0xC0, 0xC0, 0xC0)}, | |
2013 {"Grey", RGB(0xC0, 0xC0, 0xC0)}, | |
2014 {"LightGray", RGB(0xD3, 0xD3, 0xD3)}, | |
2015 {"LightGrey", RGB(0xD3, 0xD3, 0xD3)}, | |
2016 {"Gray10", RGB(0x1A, 0x1A, 0x1A)}, | |
2017 {"Grey10", RGB(0x1A, 0x1A, 0x1A)}, | |
2018 {"Gray20", RGB(0x33, 0x33, 0x33)}, | |
2019 {"Grey20", RGB(0x33, 0x33, 0x33)}, | |
2020 {"Gray30", RGB(0x4D, 0x4D, 0x4D)}, | |
2021 {"Grey30", RGB(0x4D, 0x4D, 0x4D)}, | |
2022 {"Gray40", RGB(0x66, 0x66, 0x66)}, | |
2023 {"Grey40", RGB(0x66, 0x66, 0x66)}, | |
2024 {"Gray50", RGB(0x7F, 0x7F, 0x7F)}, | |
2025 {"Grey50", RGB(0x7F, 0x7F, 0x7F)}, | |
2026 {"Gray60", RGB(0x99, 0x99, 0x99)}, | |
2027 {"Grey60", RGB(0x99, 0x99, 0x99)}, | |
2028 {"Gray70", RGB(0xB3, 0xB3, 0xB3)}, | |
2029 {"Grey70", RGB(0xB3, 0xB3, 0xB3)}, | |
2030 {"Gray80", RGB(0xCC, 0xCC, 0xCC)}, | |
2031 {"Grey80", RGB(0xCC, 0xCC, 0xCC)}, | |
2032 {"Gray90", RGB(0xE5, 0xE5, 0xE5)}, | |
2033 {"Grey90", RGB(0xE5, 0xE5, 0xE5)}, | |
2034 {"White", RGB(0xFF, 0xFF, 0xFF)}, | |
2035 {"DarkRed", RGB(0x80, 0x00, 0x00)}, | |
2036 {"Red", RGB(0xFF, 0x00, 0x00)}, | |
2037 {"LightRed", RGB(0xFF, 0xA0, 0xA0)}, | |
2038 {"DarkBlue", RGB(0x00, 0x00, 0x80)}, | |
2039 {"Blue", RGB(0x00, 0x00, 0xFF)}, | |
2040 {"LightBlue", RGB(0xAD, 0xD8, 0xE6)}, | |
2041 {"DarkGreen", RGB(0x00, 0x80, 0x00)}, | |
2042 {"Green", RGB(0x00, 0xFF, 0x00)}, | |
2043 {"LightGreen", RGB(0x90, 0xEE, 0x90)}, | |
2044 {"DarkCyan", RGB(0x00, 0x80, 0x80)}, | |
2045 {"Cyan", RGB(0x00, 0xFF, 0xFF)}, | |
2046 {"LightCyan", RGB(0xE0, 0xFF, 0xFF)}, | |
2047 {"DarkMagenta", RGB(0x80, 0x00, 0x80)}, | |
2048 {"Magenta", RGB(0xFF, 0x00, 0xFF)}, | |
2049 {"LightMagenta", RGB(0xFF, 0xA0, 0xFF)}, | |
2050 {"Brown", RGB(0x80, 0x40, 0x40)}, | |
2051 {"Yellow", RGB(0xFF, 0xFF, 0x00)}, | |
2052 {"LightYellow", RGB(0xFF, 0xFF, 0xE0)}, | |
2053 {"SeaGreen", RGB(0x2E, 0x8B, 0x57)}, | |
2054 {"Orange", RGB(0xFF, 0xA5, 0x00)}, | |
2055 {"Purple", RGB(0xA0, 0x20, 0xF0)}, | |
2056 {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)}, | |
2057 {"Violet", RGB(0xEE, 0x82, 0xEE)}, | |
2058 }; | |
2059 | |
2060 /* is name #rrggbb format? */ | |
2061 if (name[0] == '#' && STRLEN(name) == 7) | |
2062 { | |
2063 r = hex_digit(name[1]) * 16 + hex_digit(name[2]); | |
2064 g = hex_digit(name[3]) * 16 + hex_digit(name[4]); | |
2065 b = hex_digit(name[5]) * 16 + hex_digit(name[6]); | |
2066 if (r < 0 || g < 0 || b < 0) | |
2067 return INVALCOLOR; | |
2068 return RGB(r, g, b); | |
2069 } | |
2070 | |
2071 for (i = 0; i < ARRAY_LENGTH(table); i++) | |
2072 { | |
2073 if (STRICMP(name, table[i].name) == 0) | |
2074 return table[i].colour; | |
2075 } | |
2076 | |
2077 /* | |
2078 * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt". | |
2079 */ | |
2080 { | |
2081 #define LINE_LEN 100 | |
2082 FILE *fd; | |
2083 char line[LINE_LEN]; | |
2084 char_u *fname; | |
2085 | |
2086 fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); | |
2087 if (fname == NULL) | |
2088 return INVALCOLOR; | |
2089 | |
2090 fd = fopen((char *)fname, "rt"); | |
2091 vim_free(fname); | |
2092 if (fd == NULL) | |
2093 return INVALCOLOR; | |
2094 | |
2095 while (!feof(fd)) | |
2096 { | |
2097 int len; | |
2098 int pos; | |
2099 char *color; | |
2100 | |
2101 fgets(line, LINE_LEN, fd); | |
2102 len = STRLEN(line); | |
2103 | |
2104 if (len <= 1 || line[len-1] != '\n') | |
2105 continue; | |
2106 | |
2107 line[len-1] = '\0'; | |
2108 | |
2109 i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); | |
2110 if (i != 3) | |
2111 continue; | |
2112 | |
2113 color = line + pos; | |
2114 | |
2115 if (STRICMP(color, name) == 0) | |
2116 { | |
2117 fclose(fd); | |
2118 return (guicolor_T)RGB(r, g, b); | |
2119 } | |
2120 } | |
2121 | |
2122 fclose(fd); | |
2123 } | |
2124 | |
2125 | |
2126 return INVALCOLOR; | |
2127 } | 1986 } |
2128 | 1987 |
2129 void | 1988 void |
2130 gui_mch_set_fg_color(guicolor_T color) | 1989 gui_mch_set_fg_color(guicolor_T color) |
2131 { | 1990 { |