diff options
| author | Alan Third | 2021-08-14 16:11:30 +0100 |
|---|---|---|
| committer | Alan Third | 2021-12-22 20:48:19 +0000 |
| commit | 0f427befe82f88237bdccbd528baf76f6d6485b0 (patch) | |
| tree | dffb5221ec905df3e78f147adbd4fced22e77118 /src/nsfns.m | |
| parent | 5b0121b708986c836fa970b800387363806a035a (diff) | |
| download | emacs-0f427befe82f88237bdccbd528baf76f6d6485b0.tar.gz emacs-0f427befe82f88237bdccbd528baf76f6d6485b0.zip | |
Simplify NS color handling
* src/image.c (RGB_TO_ULONG):
(ARGB_TO_ULONG):
(RED_FROM_ULONG):
(RED16_FROM_ULONG):
(GREEN16_FROM_ULONG):
(BLUE16_FROM_ULONG): Define these here for NS too.
* src/nsfns.m (ns_set_foreground_color):
(ns_set_background_color): Use new EmacsColor methods.
* src/nsterm.h (struct ns_color_table): Replace this struct with a
built-in Objective C type.
(RGB_TO_ULONG):
(ARGB_TO_ULONG):
(ALPHA_FROM_ULONG):
(RED_FROM_ULONG):
(GREEN_FROM_ULONG):
(BLUE_FROM_ULONG):
(RED16_FROM_ULONG):
(GREEN16_FROM_ULONG):
(BLUE16_FROM_ULONG): These are no longer needed in the NS specific code.
(struct ns_display_info): Use an NSMutableArray instead of a custom struct.
* src/nsterm.m ([NSColor colorWithUnsignedLong:hasAlpha:]):
([NSColor unsignedLong]): New methods.
(ns_lookup_indexed_color):
(ns_index_color): Use the NSMutableArray lookup table.
(ns_term_init):
(ns_color_index_to_rgba):
(ns_query_color): Use the new EmacsColor methods.
(ns_initialize_display_info):
(ns_delete_display): Initialize and release the NSMutableArray lookup table.
Diffstat (limited to 'src/nsfns.m')
| -rw-r--r-- | src/nsfns.m | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index 81019fce09d..365df7fc1e8 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -236,7 +236,6 @@ static void | |||
| 236 | ns_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | 236 | ns_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
| 237 | { | 237 | { |
| 238 | NSColor *col; | 238 | NSColor *col; |
| 239 | EmacsCGFloat r, g, b, alpha; | ||
| 240 | 239 | ||
| 241 | /* Must block_input, because ns_lisp_to_color does block/unblock_input | 240 | /* Must block_input, because ns_lisp_to_color does block/unblock_input |
| 242 | which means that col may be deallocated in its unblock_input if there | 241 | which means that col may be deallocated in its unblock_input if there |
| @@ -253,12 +252,7 @@ ns_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 253 | [f->output_data.ns->foreground_color release]; | 252 | [f->output_data.ns->foreground_color release]; |
| 254 | f->output_data.ns->foreground_color = col; | 253 | f->output_data.ns->foreground_color = col; |
| 255 | 254 | ||
| 256 | [col getRed: &r green: &g blue: &b alpha: &alpha]; | 255 | FRAME_FOREGROUND_PIXEL (f) = [col unsignedLong]; |
| 257 | FRAME_FOREGROUND_PIXEL (f) = | ||
| 258 | ARGB_TO_ULONG ((unsigned long) (alpha * 0xff), | ||
| 259 | (unsigned long) (r * 0xff), | ||
| 260 | (unsigned long) (g * 0xff), | ||
| 261 | (unsigned long) (b * 0xff)); | ||
| 262 | 256 | ||
| 263 | if (FRAME_NS_VIEW (f)) | 257 | if (FRAME_NS_VIEW (f)) |
| 264 | { | 258 | { |
| @@ -277,7 +271,7 @@ ns_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 277 | struct face *face; | 271 | struct face *face; |
| 278 | NSColor *col; | 272 | NSColor *col; |
| 279 | NSView *view = FRAME_NS_VIEW (f); | 273 | NSView *view = FRAME_NS_VIEW (f); |
| 280 | EmacsCGFloat r, g, b, alpha; | 274 | EmacsCGFloat alpha; |
| 281 | 275 | ||
| 282 | block_input (); | 276 | block_input (); |
| 283 | if (ns_lisp_to_color (arg, &col)) | 277 | if (ns_lisp_to_color (arg, &col)) |
| @@ -291,12 +285,8 @@ ns_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) | |||
| 291 | [f->output_data.ns->background_color release]; | 285 | [f->output_data.ns->background_color release]; |
| 292 | f->output_data.ns->background_color = col; | 286 | f->output_data.ns->background_color = col; |
| 293 | 287 | ||
| 294 | [col getRed: &r green: &g blue: &b alpha: &alpha]; | 288 | FRAME_BACKGROUND_PIXEL (f) = [col unsignedLong]; |
| 295 | FRAME_BACKGROUND_PIXEL (f) = | 289 | alpha = [col alphaComponent]; |
| 296 | ARGB_TO_ULONG ((unsigned long) (alpha * 0xff), | ||
| 297 | (unsigned long) (r * 0xff), | ||
| 298 | (unsigned long) (g * 0xff), | ||
| 299 | (unsigned long) (b * 0xff)); | ||
| 300 | 290 | ||
| 301 | if (view != nil) | 291 | if (view != nil) |
| 302 | { | 292 | { |