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

« back to all changes in this revision

Viewing changes to Lib/xplt/src/play/win/cursors.c

  • 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
 * cursors.c -- $Id: cursors.c,v 1.1 2003/03/08 15:26:49 travo Exp $
 
3
 * p_cursor for MS Windows
 
4
 *
 
5
 * Copyright (c) 1999.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
/* is this really necessary to get OCR_NORMAL?? (==32512) */
 
9
#define OEMRESOURCE
 
10
 
 
11
#include "playw.h"
 
12
 
 
13
/* need to create P_S, P_E, P_W, P_ROTATE, P_DEATH, P_HAND cursors
 
14
 * -- may as well do P_N as well for consistent look
 
15
 *
 
16
 * notes:
 
17
 * (1) the 326-byte \windows\cursors\*.cur files are 32x32 bitmaps
 
18
 *     stored most significant bit first, least significant byte first,
 
19
 *     top-to-bottom order
 
20
 * (2) SM_CXCURSOR = SM_CYCURSOR = 32 on my Win95 box
 
21
 * (3) AND mask: 0 where cursor drawn, 1 where not
 
22
 * (4) XOR mask: 0 black/screen, 1 white/invert  (where AND bit 0/1)
 
23
 * (5) CreateBitmap documentation states that each scan line
 
24
 *     of a bitmap should be word (2-byte) aligned
 
25
 */
 
26
 
 
27
typedef struct w_curshape w_curshape;
 
28
struct w_curshape {
 
29
  int xhot, yhot;
 
30
  unsigned char amsk[32], xmsk[32];
 
31
};
 
32
 
 
33
static w_curshape w_narrow = {
 
34
  7, 1,
 
35
  { 0xfe, 0xff, 0xfc, 0x7f, 0xf8, 0x3f, 0xf0, 0x1f,
 
36
    0xe0, 0x0f, 0xe0, 0x0f, 0xf8, 0x3f, 0xf8, 0x3f,
 
37
    0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f,
 
38
    0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f },
 
39
  { 0x01, 0x00, 0x02, 0x80, 0x04, 0x40, 0x08, 0x20,
 
40
    0x10, 0x10, 0x1d, 0x70, 0x05, 0x40, 0x05, 0x40,
 
41
    0x05, 0x40, 0x05, 0x40, 0x05, 0x40, 0x05, 0x40,
 
42
    0x05, 0x40, 0x05, 0x40, 0x05, 0x40, 0x05, 0x40 } };
 
43
 
 
44
static w_curshape w_sarrow = {
 
45
  7, 14,
 
46
  { 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f,
 
47
    0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f,
 
48
    0xf8, 0x3f, 0xf8, 0x3f, 0xe0, 0x0f, 0xe0, 0x0f,
 
49
    0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, 0xff },
 
50
  { 0x05, 0x40, 0x05, 0x40, 0x05, 0x40, 0x05, 0x40,
 
51
    0x05, 0x40, 0x05, 0x40, 0x05, 0x40, 0x05, 0x40,
 
52
    0x05, 0x40, 0x05, 0x40, 0x1d, 0x70, 0x10, 0x10,
 
53
    0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01, 0x00 } };
 
54
 
 
55
static w_curshape w_earrow = {
 
56
  14, 7,
 
57
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf,
 
58
    0xff, 0xc7, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00,
 
59
    0x00, 0x01, 0x00, 0x03, 0xff, 0xc7, 0xff, 0xcf,
 
60
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
 
61
  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
 
62
    0x00, 0x28, 0xff, 0xe4, 0x00, 0x02, 0xff, 0xe1,
 
63
    0x00, 0x02, 0xff, 0xe4, 0x00, 0x28, 0x00, 0x30,
 
64
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
 
65
 
 
66
static w_curshape w_warrow = {
 
67
  1, 7,
 
68
  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0xff,
 
69
    0xe3, 0xff, 0xc0, 0x00, 0x80, 0x00, 0x00, 0x00,
 
70
    0x80, 0x00, 0xc0, 0x00, 0xe3, 0xff, 0xf3, 0xff,
 
71
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
 
72
  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00,
 
73
    0x14, 0x00, 0x27, 0xff, 0x40, 0x00, 0x87, 0xff,
 
74
    0x40, 0x00, 0x27, 0xff, 0x14, 0x00, 0x0c, 0x00,
 
75
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
 
76
 
 
77
static w_curshape w_rotate = {
 
78
  7, 7,
 
79
  { 0x38, 0x1f, 0x10, 0x0f, 0x00, 0x07, 0x00, 0x03,
 
80
    0x03, 0xe3, 0x00, 0xf3, 0x00, 0xff, 0x00, 0xff,
 
81
    0xff, 0x00, 0xff, 0x00, 0xcf, 0x80, 0xc7, 0xc0,
 
82
    0xc0, 0x00, 0xe0, 0x00, 0xf0, 0x08, 0xf8, 0x1c },
 
83
  { 0xc7, 0xe0, 0xa8, 0x10, 0x90, 0x08, 0x83, 0xe4,
 
84
    0xb4, 0x14, 0xb3, 0x0c, 0x81, 0x00, 0xff, 0x00,
 
85
    0x00, 0xff, 0x00, 0x81, 0x30, 0x4d, 0x28, 0x2d,
 
86
    0x27, 0xc1, 0x10, 0x09, 0x08, 0x15, 0x07, 0xe3 } };
 
87
 
 
88
static w_curshape w_death = {
 
89
  7, 11,
 
90
  { 0xf0, 0x3f, 0xe0, 0x1f, 0xc0, 0x0f, 0x80, 0x07,
 
91
    0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x1f, 0x70, 0x3e,
 
92
    0x70, 0x38, 0x30, 0x30, 0x08, 0x63, 0x87, 0x87,
 
93
    0xf8, 0x7f, 0x80, 0x1c, 0x00, 0x00, 0x0f, 0xc1 },
 
94
  { 0x08, 0x40, 0x10, 0x20, 0x20, 0x10, 0x4c, 0xc8,
 
95
    0x4c, 0xc8, 0x20, 0x10, 0x10, 0x20, 0x88, 0x41,
 
96
    0x08, 0x43, 0x48, 0x49, 0xb4, 0x94, 0x40, 0x08,
 
97
    0x00, 0x00, 0x60, 0x01, 0x0f, 0xc1, 0x70, 0x3a } };
 
98
 
 
99
static w_curshape w_hand = {
 
100
  3, 2,
 
101
  { 0xfe, 0x7f, 0xe4, 0x0f, 0xc0, 0x07, 0xc0, 0x05,
 
102
    0xe0, 0x00, 0xe0, 0x00, 0x80, 0x00, 0x00, 0x00,
 
103
    0x00, 0x01, 0x80, 0x01, 0xc0, 0x01, 0xc0, 0x03,
 
104
    0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x07, 0xf8, 0x07 },
 
105
  { 0x00, 0x00, 0x01, 0x80, 0x19, 0xb0, 0x19, 0xb0,
 
106
    0x0d, 0xb2, 0x0d, 0xb6, 0x17, 0xf6, 0x67, 0xfe,
 
107
    0x77, 0xfc, 0x3f, 0xfc, 0x1f, 0xfc, 0x1f, 0xf8,
 
108
    0x0f, 0xf8, 0x07, 0xf0, 0x03, 0xf0, 0x03, 0xf0 } };
 
109
 
 
110
static w_curshape *w_curs[7] = {
 
111
  &w_narrow, &w_sarrow, &w_earrow, &w_warrow, &w_rotate, &w_death, &w_hand };
 
112
static unsigned char *w_cursbits = 0;
 
113
 
 
114
HCURSOR
 
115
w_cursor(int cursor)
 
116
{
 
117
  HCURSOR c = 0;
 
118
  int i = cursor - 3;
 
119
  if (i>3) {
 
120
    if (i>6) i -= 3;
 
121
    else i -= 7;
 
122
  }
 
123
  if (i>=0 && i<7) {
 
124
    w_curshape *cs = w_curs[i];
 
125
    int w = GetSystemMetrics(SM_CXCURSOR);    /* bits per scan line */
 
126
    int h = GetSystemMetrics(SM_CYCURSOR);  /* number of scan lines */
 
127
    int wb = ((w+15)/16)*2;        /* number of bytes per scan line */
 
128
    unsigned char *and_msk = w_cursbits, *xor_msk;
 
129
    int j, k;
 
130
    w_cursbits = 0;
 
131
    if (and_msk) HeapFree(GetProcessHeap(), 0, and_msk);
 
132
    w_cursbits = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS,
 
133
                          2*wb*h);
 
134
    and_msk = w_cursbits;
 
135
    xor_msk = and_msk + wb*h;
 
136
    for (j=k=0 ; j<h ; j++,k+=wb) {
 
137
      if (j < 16) {
 
138
        for (i=0 ; i<wb ; i++) {
 
139
          if (i<2) {
 
140
            and_msk[k+i] = cs->amsk[2*j+i];
 
141
            xor_msk[k+i] = cs->xmsk[2*j+i];
 
142
          } else {
 
143
            and_msk[k+i] = 0xff;
 
144
            xor_msk[k+i] = 0;
 
145
          }
 
146
        }
 
147
      } else {
 
148
        for (i=0 ; i<wb ; i++) {
 
149
          and_msk[k+i] = 0xff;
 
150
          xor_msk[k+i] = 0;
 
151
        }
 
152
      }
 
153
    }
 
154
    c = CreateCursor(w_app_instance, cs->xhot, cs->yhot, w, h,
 
155
                    and_msk, xor_msk);
 
156
    w_cursbits = 0;
 
157
    HeapFree(GetProcessHeap(), 0, and_msk);
 
158
  } else {
 
159
    c = LoadCursor(0, IDC_ARROW);
 
160
    /* c = LoadImage(0, MAKEINTRESOURCE(OCR_NORMAL),
 
161
     *              IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR); */
 
162
  }
 
163
  return c;
 
164
}