~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/xplt/src/play/mac/color.m

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * color.m
 
3
 * Color handling for Mac OS X.
 
4
 *
 
5
 * Copyright (c) 1999.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
#include "playm.h"
 
9
 
 
10
void
 
11
p_color(p_win *w, unsigned long color)
 
12
{ int change = 0;
 
13
  p_scr* s = w->s;
 
14
  View* view = w->view;
 
15
  CGContextRef cr = w->cr;
 
16
  if (w->parent) w = w->parent;
 
17
  if (p_signalling)
 
18
  { p_abort();
 
19
    return;
 
20
  }
 
21
  if (w->color != color) change = 1;
 
22
  /* p_color may be called before p_rect, without p_clip getting
 
23
   * called first. In that case, the focus is not yet locked on the
 
24
   * view. */
 
25
  if (s->lockedView != view)
 
26
  { CGAffineTransform tf = CGContextGetTextMatrix(cr);
 
27
    tf.a = +1.0;
 
28
    tf.d = -1.0; /* -1.0 so that text appears upright in a flipped view */
 
29
    CGContextSetTextMatrix(cr, tf);
 
30
    if (s->lockedView) [s->lockedView unlockFocus];
 
31
    [view lockFocus];
 
32
    s->lockedView = view;
 
33
    change = 1;
 
34
  }
 
35
  if (change) {
 
36
/* It seems that Cocoa doesn't support XOR drawing at this point.
 
37
    const int de_xor = (w->color == P_XOR);
 
38
    if (de_xor || color==P_XOR) {
 
39
      if (w->view)
 
40
        SetROP2(w->dc, de_xor? R2_COPYPEN : R2_NOT);
 
41
    }
 
42
*/
 
43
    w->color = color;
 
44
    if (!P_IS_RGB(color)) {
 
45
      w->components[0] = w->pixels[color][0];
 
46
      w->components[1] = w->pixels[color][1];
 
47
      w->components[2] = w->pixels[color][2];
 
48
      w->components[3] = w->pixels[color][3];
 
49
    } else {
 
50
      w->components[0] = P_R(color) / 255.0;
 
51
      w->components[1] = P_G(color) / 255.0;
 
52
      w->components[2] = P_B(color) / 255.0;
 
53
      w->components[3] = 1.0;
 
54
    }
 
55
    CGContextSetStrokeColorSpace(cr, s->colorspace);
 
56
    CGContextSetStrokeColor(cr, w->components);
 
57
    CGContextSetFillColorSpace(cr, s->colorspace);
 
58
    CGContextSetFillColor(cr, w->components);
 
59
  }
 
60
}