File: macxsgraph.c

package info (click to toggle)
xlispstat 3.52.14-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,560 kB
  • ctags: 12,676
  • sloc: ansic: 91,357; lisp: 21,759; sh: 1,525; makefile: 521; csh: 1
file content (68 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* macxsgraph - Macintosh lisp low level graphics functions            */
/* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
/* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
/* You may give out copies of this software; for conditions see the    */
/* file COPYING included with this distribution.                       */
 
#include "xlisp.h"
#include "xlstat.h"
#include "xlgraph.h"

#define MULTIPLIER 65535

/* external variables */
extern LVAL k_initial;

static RGBColor ListToRGB(LVAL x)
{
  RGBColor color;

  if (! consp(x) || llength(x) != 3) xlerror("not a color list", x);
  color.red   = MULTIPLIER * makefloat(car(x)); x = cdr(x);
  color.green = MULTIPLIER * makefloat(car(x)); x = cdr(x);
  color.blue  = MULTIPLIER * makefloat(car(x));
  return(color);
}
  
static LVAL RGBToList(RGBColor color)
{
  LVAL result, rp;
  
  xlsave1(result);
  result = rp = mklist(3, NIL);
  rplaca(rp, cvflonum((FLOTYPE) (((double) color.red)   / MULTIPLIER)));
  rp = cdr(rp);
  rplaca(rp, cvflonum((FLOTYPE) (((double) color.green) / MULTIPLIER)));
  rp = cdr(rp);
  rplaca(rp, cvflonum((FLOTYPE) (((double) color.blue)  / MULTIPLIER)));
  xlpop();
  return(result);
}

LVAL xspick_color(void)
{
  Point where;
  char *prompt;
  RGBColor in_color, out_color;
  int ok;
  LVAL arg;
  Str255 pbuf;
  
  if (! StScreenHasColor()) return(NIL);
  
  in_color.red = 0; 
  in_color.green = 0;
  in_color.blue = 0;
  if (moreargs()) {
    prompt = (char *) getstring(xlgastring());
    if (xlgetkeyarg(k_initial, &arg)) in_color = ListToRGB(arg);
  }
  else prompt = "Pick a color";
  
  where.h = 0; where.v = 0;
  CintoPstring(prompt, pbuf, sizeof pbuf, FALSE);
  NotifyIfInBackground();
  ok = GetColor(where, pbuf, &in_color, &out_color);
  
  return((ok) ? RGBToList(out_color) : NIL);
}