source: trunk/src/pe2lx/cursor.cpp

Last change on this file was 97, checked in by phaller, 26 years ago

Add: added cvs variable $Id$ to source files.

File size: 6.3 KB
Line 
1/* $Id: cursor.cpp,v 1.3 1999-06-10 17:08:52 phaller Exp $ */
2
3/*
4 * PE2LX cursor conversion code
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_GPIBITMAPS
13#define INCL_BITMAPFILEFORMAT
14#define INCL_DOSFILEMGR /* File Manager values */
15#define INCL_DOSERRORS /* DOS Error values */
16#define INCL_DOSPROCESS /* DOS Process values */
17#define INCL_DOSMISC /* DOS Miscellanous values */
18#define INCL_WIN
19#include <os2.h>
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <iostream.h>
24#include <string.h>
25#include "pefile.h"
26#include "lx.h"
27#include "icon.h"
28#include "cursor.h"
29#include "misc.h"
30
31
32//******************************************************************************
33//******************************************************************************
34OS2Cursor::OS2Cursor(int id,
35 CursorComponent *curHdr,
36 int size)
37 : id(0),
38 next(NULL),
39 cursorhdr(NULL),
40 cursorsize(0),
41 prevoffset(0)
42{
43 OS2Cursor *cursor = OS2Cursor::cursors;
44 RGBQUAD *rgb;
45 RGB *os2rgb;
46 WINBITMAPINFOHEADER *bhdr = (WINBITMAPINFOHEADER *)(curHdr+1);
47 int i, bwsize, bmpsize;
48
49 if(cursor != NULL)
50 {
51 while(cursor->next != NULL)
52 {
53 cursor = cursor->next;
54 }
55 cursor->next = this;
56 }
57 else
58 cursors = this;
59
60 this->id = id;
61
62 cout << "Cursor with id " << id << endl;
63 cout << "Cursor size " << size << endl;
64 bmpsize = size - sizeof(CursorComponent) - (1<<bhdr->biBitCount)*sizeof(RGBQUAD);
65 cursorsize = sizeof(BITMAPFILEHEADER) + bmpsize + (1<<bhdr->biBitCount)*sizeof(RGB);
66
67 cursorhdr = (BITMAPFILEHEADER *)malloc(cursorsize);
68 cursorhdr->usType = BFT_POINTER;
69 cursorhdr->cbSize = sizeof(BITMAPFILEHEADER);
70 cursorhdr->xHotspot = curHdr->xHotspot;
71
72 /* @@@PH y-hotspot is upside down ! */
73 cursorhdr->yHotspot = (bhdr->biHeight >> 1) - 1 /* height div 2 */
74 - curHdr->yHotspot; /* subtract hot.y */
75
76 cout << "Cursor Hot.x : " << curHdr->xHotspot << endl;
77 cout << "Cursor Hot.y : " << curHdr->yHotspot << endl;
78
79 cursorhdr->offBits = sizeof(BITMAPFILEHEADER) + 2*sizeof(RGB);
80 cursorhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
81 cursorhdr->bmp.cx = (USHORT)bhdr->biWidth;
82 cursorhdr->bmp.cy = (USHORT)(bhdr->biHeight);
83 cursorhdr->bmp.cPlanes = bhdr->biPlanes;
84 cursorhdr->bmp.cBitCount = bhdr->biBitCount;
85 cout << "Cursor size : " << bhdr->biSizeImage << endl;
86 cout << "Cursor Width : " << bhdr->biWidth << endl;
87//height for both the XOR and AND bitmap (color & BW)
88 cout << "Height : " << bhdr->biHeight << endl;
89 cout << "Cursor Bitcount: " << bhdr->biBitCount << endl;
90 cout << "Cursor Compress: " << bhdr->biCompression << endl;
91
92 os2rgb = (RGB *)(cursorhdr+1);
93 rgb = (RGBQUAD *)(bhdr+1);
94 for(i=0;i<(1<<bhdr->biBitCount);i++) {
95 os2rgb->bRed = rgb->red;
96 os2rgb->bBlue = rgb->blue;
97 os2rgb->bGreen = rgb->green;
98 os2rgb++;
99 rgb++;
100 }
101
102 if(bhdr->biSizeImage > bmpsize || bhdr->biSizeImage == 0) {
103 bwsize = bhdr->biWidth*(bhdr->biHeight);
104
105 switch(bhdr->biBitCount) {
106 case 1:
107 bwsize /= 8;
108 break;
109 case 4:
110 bwsize /= 2;
111 break;
112 case 8:
113 break;
114 case 16:
115 bwsize *= 2;
116 break;
117 case 24:
118 bwsize *= 3;
119 break;
120 case 32:
121 bwsize *= 4;
122 break;
123 }
124 }
125 else bwsize = bhdr->biSizeImage;
126
127 //write XOR and AND mask
128 memcpy((char *)os2rgb, (char *)rgb, bwsize);
129}
130//******************************************************************************
131//******************************************************************************
132void OS2Cursor::SetCursorHdrOffset(int offset)
133{
134 cursorhdr->offBits += offset - prevoffset;
135 //remember in case cursors are used in multiple groups
136 //(can't imagine this ever happening, but you never know)
137 prevoffset = offset;
138}
139//******************************************************************************
140//******************************************************************************
141OS2Cursor::~OS2Cursor()
142{
143 if(cursorhdr) free(cursorhdr);
144}
145//******************************************************************************
146//******************************************************************************
147int OS2Cursor::QueryCursorSize()
148{
149 return(cursorsize);
150}
151//******************************************************************************
152//******************************************************************************
153#ifdef __WATCOMC__
154#pragma off (unreferenced)
155#endif
156BITMAPFILEHEADER *OS2Cursor::GetCursorHeader(int wWidth, int wHeight, int wPlanes, int wBitCount)
157#ifdef __WATCOMC__
158#pragma on (unreferenced)
159#endif
160{
161//SvL: 20-11-'97: already filled in
162#if 0
163 cursorhdr->bmp.cx = wWidth;
164 cursorhdr->bmp.cy = wHeight;
165 cursorhdr->bmp.cPlanes = wPlanes;
166 cursorhdr->bmp.cBitCount = wBitCount;
167#endif
168 return(cursorhdr);
169}
170//******************************************************************************
171//******************************************************************************
172OS2Cursor *OS2Cursor::GetCursor(int id)
173{
174 OS2Cursor *cursor = OS2Cursor::cursors;
175
176 while(cursor != NULL) {
177 if(cursor->id == id) {
178 return(cursor);
179 }
180 cursor = cursor->next;
181 }
182 return(NULL);
183}
184//******************************************************************************
185//******************************************************************************
186void OS2Cursor::DestroyAll()
187{
188 OS2Cursor *cursor = OS2Cursor::cursors, *next;
189
190 while(cursor != NULL) {
191 next = cursor->next;
192 delete(cursor);
193 cursor = next;
194 }
195}
196//******************************************************************************
197//******************************************************************************
198OS2Cursor *OS2Cursor::cursors = NULL;
Note: See TracBrowser for help on using the repository browser.