source: dev/ProjectEditor/IconEditor_Main.cpp@ 3

Last change on this file since 3 was 3, checked in by dai_9181, 17 years ago
File size: 46.5 KB
Line 
1#include "Common.h"
2
3#define ZOOMED_XPOS 100
4#define PIXEL_WIDTH 10
5
6RGBQUAD TransparentRgbq={230,230,255}; //blue,green,red(透明色)
7COLORREF TransparentClrRef=RGB(255,230,230); //red,green,blue(透明色)
8
9void IconEdit_SelectImage(int WndNum);
10
11void LimitRectFormat(int WndNum,RECT *pRect){
12 //はみ出した場合は範囲内におさめる
13 extern MDIINFO MdiInfo[MAX_WNDNUM];
14 if(pRect->left<0) pRect->left=0;
15 if(pRect->top<0) pRect->top=0;
16 if(pRect->left>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth)
17 pRect->left=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth-1;
18 if(pRect->top>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2)
19 pRect->top=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2-1;
20
21 if(pRect->right<0) pRect->right=0;
22 if(pRect->bottom<0) pRect->bottom=0;
23 if(pRect->right>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth)
24 pRect->right=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth-1;
25 if(pRect->bottom>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2)
26 pRect->bottom=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2-1;
27}
28void GetZoomedPos(POINT *pPos){
29 pPos->x=pPos->x*PIXEL_WIDTH+ZOOMED_XPOS;
30 pPos->y*=PIXEL_WIDTH;
31}
32void SetZoomedPixel(HDC hdc,int WndNum,int x,int y){
33 extern MDIINFO MdiInfo[MAX_WNDNUM];
34 POINT pos;
35
36 if(x<0||y<0||
37 x>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth||
38 y>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2)
39 return;
40
41 pos.x=x;
42 pos.y=y;
43 GetZoomedPos(&pos);
44 Rectangle(hdc,pos.x,pos.y,pos.x+11,pos.y+11);
45}
46DWORD GetColorCode(int WndNum,COLORREF ColorRef){
47 extern MDIINFO MdiInfo[MAX_WNDNUM];
48 int i,i2;
49 RGBQUAD *pRgbq;
50
51 //透明色の場合
52 if(ColorRef==TransparentClrRef) return -1;
53
54 //カラーテーブルを取得
55 pRgbq=(RGBQUAD *)(MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+sizeof(BITMAPINFOHEADER));
56
57 i2=(int)pow((double)2,(double)MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biBitCount);
58 for(i=0;i<i2;i++){
59 if(ColorRef==RGB(pRgbq[i].rgbRed,pRgbq[i].rgbGreen,pRgbq[i].rgbBlue)) break;
60 }
61 if(i==i2) i=0;
62
63 return i;
64}
65HGLOBAL IconEdit_GetChildInfoClipboardData(int WndNum){
66 //////////////////////////////////////////////
67 // 選択中のイメージをクリップボードへ保存する
68 //////////////////////////////////////////////
69
70 extern MDIINFO MdiInfo[MAX_WNDNUM];
71 HDC hDC;
72 HBITMAP hBmp;
73 SIZE size;
74 int sw;
75
76 //何も選択されていない場合は0を返す
77 sw=0;
78 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==0) return 0;
79 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==1){
80 IconEdit_SelectImage(WndNum);
81 sw=1;
82 }
83
84 size.cx=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left+1;
85 size.cy=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top+1;
86
87 hDC=CreateCompatibleDC(MdiInfo[WndNum].MdiIconEditInfo->memdc);
88 hBmp=CreateCompatibleBitmap(
89 MdiInfo[WndNum].MdiIconEditInfo->memdc,
90 size.cx,
91 size.cy);
92 SelectObject(hDC,hBmp);
93
94 BitBlt(hDC,0,0,size.cx,size.cy,
95 MdiInfo[WndNum].MdiIconEditInfo->memdc,
96 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left,
97 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top,
98 SRCCOPY);
99
100 DeleteDC(hDC);
101
102 if(sw){
103 DeleteObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
104 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=1;
105 }
106
107 return hBmp;
108}
109void IconEdit_PasteChildInfoClipboardData(int WndNum,HBITMAP hBmp){
110 ////////////////////////////////////
111 // クリップボードの内容を貼り付ける
112 ////////////////////////////////////
113
114 extern MDIINFO MdiInfo[MAX_WNDNUM];
115 HDC hDC,hDC2;
116 BITMAP Bitmap;
117
118 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==2)
119 IconEdit_PasteImage(WndNum);
120
121 GetObject(hBmp,sizeof(Bitmap),&Bitmap);
122
123 hDC=CreateCompatibleDC(MdiInfo[WndNum].MdiIconEditInfo->memdc);
124 MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp=
125 CreateCompatibleBitmap(MdiInfo[WndNum].MdiIconEditInfo->memdc,Bitmap.bmWidth,Bitmap.bmHeight);
126 SelectObject(hDC,MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
127 hDC2=CreateCompatibleDC(MdiInfo[WndNum].MdiIconEditInfo->memdc);
128 SelectObject(hDC2,hBmp);
129
130 BitBlt(hDC,0,0,Bitmap.bmWidth,Bitmap.bmHeight,
131 hDC2,0,0,SRCCOPY);
132
133 DeleteDC(hDC);
134 DeleteDC(hDC2);
135
136 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left=0;
137 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top=0;
138 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right=Bitmap.bmWidth-1;
139 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom=Bitmap.bmHeight-1;
140
141 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hMain,NULL,0);
142
143 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=2;
144}
145
146void IconEdit_SelectImage(int WndNum){
147 extern MDIINFO MdiInfo[MAX_WNDNUM];
148 SIZE size;
149 HDC hDC;
150
151 size.cx=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left+1;
152 size.cy=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top+1;
153
154 hDC=CreateCompatibleDC(MdiInfo[WndNum].MdiIconEditInfo->memdc);
155 MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp=
156 CreateCompatibleBitmap(MdiInfo[WndNum].MdiIconEditInfo->memdc,size.cx,size.cy);
157 SelectObject(hDC,MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
158 BitBlt(hDC,0,0,size.cx,size.cy,
159 MdiInfo[WndNum].MdiIconEditInfo->memdc,
160 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left,
161 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top,
162 SRCCOPY);
163 DeleteDC(hDC);
164
165 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=2;
166}
167void IconEdit_PasteImage(int WndNum){
168 extern HANDLE hHeap;
169 extern MDIINFO MdiInfo[MAX_WNDNUM];
170 int i,i2,i3,x,y,y2,selecting_x,selecting_y;
171 DWORD dwRgbq;
172
173 //コピー先
174 RGBQUAD *pRgbq;
175 BYTE *pBuffer,*pMaskBuf;
176 BITMAPINFOHEADER *pBmpInfoHdr;
177
178 //コピー元
179 BITMAP Bitmap;
180 BITMAPINFO SelectingBitmapInfo;
181 COLORREF *pSelectingBuffer;
182
183 //変更情報
184 IconEdit_NoticeChanging(WndNum);
185
186 GetObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp,sizeof(BITMAP),&Bitmap);
187 pSelectingBuffer=(COLORREF *)HeapAlloc(hHeap,0,Bitmap.bmWidth*Bitmap.bmHeight*sizeof(COLORREF));
188 SelectingBitmapInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
189 SelectingBitmapInfo.bmiHeader.biWidth=Bitmap.bmWidth;
190 SelectingBitmapInfo.bmiHeader.biHeight=Bitmap.bmHeight;
191 SelectingBitmapInfo.bmiHeader.biPlanes=1;
192 SelectingBitmapInfo.bmiHeader.biBitCount=32;
193 SelectingBitmapInfo.bmiHeader.biCompression=BI_RGB;
194 GetDIBits(MdiInfo[WndNum].MdiIconEditInfo->memdc,
195 MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp,
196 0,Bitmap.bmHeight,
197 pSelectingBuffer,&SelectingBitmapInfo,DIB_RGB_COLORS);
198
199 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum];
200
201 //カラーテーブルを取得
202 pRgbq=(RGBQUAD *)(MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+sizeof(BITMAPINFOHEADER));
203
204 //ビットバッファを取得
205 pBuffer=MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+
206 sizeof(BITMAPINFOHEADER);
207 if(pBmpInfoHdr->biBitCount<=8)
208 pBuffer+=sizeof(DWORD)*(int)pow((double)2,(double)pBmpInfoHdr->biBitCount);
209
210 //マスクバッファを取得
211 pMaskBuf=pBuffer+pBmpInfoHdr->biBitCount*pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8;
212
213 for(y=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom;y>=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top;y--){
214 for(x=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left;x<=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right;x++){
215 if(x<0||y<0||
216 x>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth||
217 y>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2){
218 //範囲外の場合
219 continue;
220 }
221
222 selecting_x=x-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left;
223 selecting_y=y-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top;
224 dwRgbq=pSelectingBuffer[(Bitmap.bmHeight-1-selecting_y)*Bitmap.bmWidth+selecting_x];
225
226 if(pBmpInfoHdr->biBitCount==4||pBmpInfoHdr->biBitCount==8){
227 i=(pBmpInfoHdr->biHeight/2-1-y)*pBmpInfoHdr->biWidth+x;
228 if(dwRgbq==*(DWORD *)&TransparentRgbq){
229 //////////////////
230 // 透明色にセット
231 if(pBmpInfoHdr->biWidth==16){
232 //一行の4バイト境界を考慮
233 y2=(pBmpInfoHdr->biHeight/2-1)-y;
234 pMaskBuf[(i+pBmpInfoHdr->biWidth*y2)/8]|=0x01<<(8-(i%8+1));
235 }
236 else pMaskBuf[i/8]|=0x01<<(8-(i%8+1));
237
238 /////////////////
239 // 色を0にセット
240 i3=(int)pow((double)2,(double)pBmpInfoHdr->biBitCount);
241 for(i2=0;i2<i3;i2++){
242 if(dwRgbq==((DWORD *)pRgbq)[i2]) break;
243 }
244 switch(pBmpInfoHdr->biBitCount){
245 case 4: //16色
246 if(i%2==0) *(pBuffer+i/2)&=0x0F;
247 else *(pBuffer+i/2)&=0xF0;
248 break;
249 case 8: //256色
250 pBuffer[i]=0;
251 break;
252 }
253 }
254 else{
255 ////////////////////
256 // 無透明色にセット
257 if(pBmpInfoHdr->biWidth==16){
258 //一行の4バイト境界を考慮
259 y2=(pBmpInfoHdr->biHeight/2-1)-y;
260 pMaskBuf[(i+pBmpInfoHdr->biWidth*y2)/8]&=~(0x01<<(8-(i%8+1)));
261 }
262 else pMaskBuf[i/8]&=~(0x01<<(8-(i%8+1)));
263
264 //////////////
265 // 色をセット
266 i3=(int)pow((double)2,(double)pBmpInfoHdr->biBitCount);
267 for(i2=0;i2<i3;i2++){
268 if(dwRgbq==((DWORD *)pRgbq)[i2]) break;
269 }
270 switch(pBmpInfoHdr->biBitCount){
271 case 4: //16色
272 if(i%2==0){
273 *(pBuffer+i/2)&=0x0F;
274 *(pBuffer+i/2)|=i2<<4;
275 }
276 else{
277 *(pBuffer+i/2)&=0xF0;
278 *(pBuffer+i/2)|=i2;
279 }
280 break;
281 case 8: //256色
282 pBuffer[i]=i2;
283 break;
284 }
285 }
286 }
287 }
288 }
289 HeapDefaultFree(pSelectingBuffer);
290
291 DeleteObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
292 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=0;
293
294 DrawIconToMemBmp(WndNum,0);
295 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hMain,NULL,0);
296}
297
298void DrawIconToMemBmp(int WndNum,RECT *pRect){
299 extern MDIINFO MdiInfo[MAX_WNDNUM];
300 HPEN hPen,hOldPen;
301 HBRUSH hBrush,hOldBrush;
302 int i,i2,i3,x,y,y2;
303 POINT pos;
304 RGBQUAD *pRgbq;
305 COLORREF ColorRef;
306 BYTE *pBuffer,*pMaskBuf;
307 BITMAPINFOHEADER *pBmpInfoHdr;
308
309 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum];
310
311 hPen=CreatePen(PS_SOLID,0,RGB(200,200,200));
312 hOldPen=(HPEN)SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hPen);
313
314 //カラーテーブルを取得
315 pRgbq=(RGBQUAD *)(MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+sizeof(BITMAPINFOHEADER));
316
317 //ビットバッファを取得
318 pBuffer=MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+
319 sizeof(BITMAPINFOHEADER);
320 if(pBmpInfoHdr->biBitCount<=8)
321 pBuffer+=sizeof(DWORD)*(int)pow((double)2,(double)pBmpInfoHdr->biBitCount);
322
323 //マスクバッファを取得
324 pMaskBuf=pBuffer+pBmpInfoHdr->biBitCount*pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8;
325
326 i=0; //標準ピクセルのバイトカウンタ
327 i3=0; //透明ピクセルのバイトカウンタ
328 for(y=pBmpInfoHdr->biHeight/2-1;y>=0;y--){
329 for(x=0;x<pBmpInfoHdr->biWidth;x++,i++,i3++){
330 if(pRect){
331 //メモリへの再描画が必要ない場合を検証(実行速度向上のため)
332 if(!(pRect->left<=x&&x<=pRect->right&&
333 pRect->top<=y&&y<=pRect->bottom)) continue;
334 }
335
336 //////////////////////
337 // マスクビットの確認
338 if(pBmpInfoHdr->biWidth==16){
339 //一行の4バイト境界を考慮
340 y2=(pBmpInfoHdr->biHeight/2-1)-y;
341 i2=(pMaskBuf[(i+pBmpInfoHdr->biWidth*y2)/8]>>(8-(i%8+1)))&0x01;
342 }
343 else i2=(pMaskBuf[i/8]>>(8-(i%8+1)))&0x01;
344 if(i2){
345 hBrush=CreateSolidBrush(TransparentClrRef);
346 hOldBrush=(HBRUSH)SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hBrush);
347 pos.x=x;
348 pos.y=y;
349 GetZoomedPos(&pos);
350 Rectangle(MdiInfo[WndNum].MdiIconEditInfo->memdc,
351 pos.x,
352 pos.y,
353 pos.x+11,
354 pos.y+11);
355 SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hOldBrush);
356 DeleteObject(hBrush);
357
358 SetPixel(MdiInfo[WndNum].MdiIconEditInfo->memdc,x,y,TransparentClrRef);
359 continue;
360 }
361
362 ////////////////
363 // 通常ピクセル
364 switch(pBmpInfoHdr->biBitCount){
365 case 4: //16色
366 i2=*(pBuffer+i/2);
367 if(i%2==0) i2>>=4;
368 i2&=0x0F;
369 ColorRef=RGB(pRgbq[i2].rgbRed,pRgbq[i2].rgbGreen,pRgbq[i2].rgbBlue);
370 break;
371 case 8: //256色
372 i2=pBuffer[i];
373 ColorRef=RGB(pRgbq[i2].rgbRed,pRgbq[i2].rgbGreen,pRgbq[i2].rgbBlue);
374 break;
375 }
376 hBrush=CreateSolidBrush(ColorRef);
377 hOldBrush=(HBRUSH)SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hBrush);
378 pos.x=x;
379 pos.y=y;
380 GetZoomedPos(&pos);
381 Rectangle(MdiInfo[WndNum].MdiIconEditInfo->memdc,
382 pos.x,
383 pos.y,
384 pos.x+11,
385 pos.y+11);
386 SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hOldBrush);
387 DeleteObject(hBrush);
388
389 SetPixel(MdiInfo[WndNum].MdiIconEditInfo->memdc,x,y,ColorRef);
390 }
391 }
392
393 SelectObject(MdiInfo[WndNum].MdiIconEditInfo->memdc,hOldPen);
394 DeleteObject(hPen);
395}
396
397void PixelChange(int WndNum,int x,int y,DWORD ColorCode){
398 extern MDIINFO MdiInfo[MAX_WNDNUM];
399 int i;
400 int y2;
401 BYTE *pBuffer,*pMaskBuf;
402 BITMAPINFOHEADER *pBmpInfoHdr;
403
404 if(x<0||y<0) return;
405 if(x>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth||
406 y>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2)
407 return;
408
409 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum];
410
411 pBuffer=MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+
412 sizeof(BITMAPINFOHEADER);
413 pBuffer+=sizeof(DWORD)*(int)pow((double)2,(double)pBmpInfoHdr->biBitCount);
414
415 pMaskBuf=pBuffer+pBmpInfoHdr->biBitCount*pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8;
416
417 if(x>=pBmpInfoHdr->biWidth||y>=pBmpInfoHdr->biHeight/2) return;
418 y2=(pBmpInfoHdr->biHeight/2-1)-y;
419 i=pBmpInfoHdr->biWidth*y2+x;
420
421 //////////////////
422 // マスクピクセル
423 if(ColorCode==-1){
424 //透明色に指定
425 if(pBmpInfoHdr->biWidth==16){
426 //一行の4バイト境界を考慮
427 pMaskBuf[(i+pBmpInfoHdr->biWidth*y2)/8]|=0x01<<(8-(i%8+1));
428 }
429 else pMaskBuf[i/8]|=0x01<<(8-(i%8+1));
430
431 ColorCode=0;
432 }
433 else{
434 //無透明色に指定
435 if(pBmpInfoHdr->biWidth==16){
436 //一行の4バイト境界を考慮
437 pMaskBuf[(i+pBmpInfoHdr->biWidth*y2)/8]&=~(0x01<<(8-(i%8+1)));
438 }
439 else pMaskBuf[i/8]&=~(0x01<<(8-(i%8+1)));
440 }
441
442 ////////////////
443 // 通常ピクセル
444 switch(pBmpInfoHdr->biBitCount){
445 case 4:
446 ////////
447 // 16色
448 if(i%2) *(pBuffer+i/2)=(*(pBuffer+i/2)&0xF0)|(BYTE)ColorCode;
449 else *(pBuffer+i/2)=(*(pBuffer+i/2)&0x0F)|(BYTE)ColorCode<<4;
450 break;
451 case 8:
452 /////////
453 // 256色
454 pBuffer[i]=(BYTE)ColorCode;
455 break;
456 }
457}
458COLORREF IconEdit_GetPixel(int WndNum,int x,int y){
459 extern MDIINFO MdiInfo[MAX_WNDNUM];
460 int i,i2;
461 int y2;
462 BYTE *pBuffer,*pMaskBuf;
463 BITMAPINFOHEADER *pBmpInfoHdr;
464 RGBQUAD *pRgbq;
465 COLORREF ColorRef;
466
467 if(x<0||y<0) return 0;
468 if(x>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth||
469 y>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2)
470 return 0;
471
472 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum];
473
474 //カラーテーブルを取得
475 pRgbq=(RGBQUAD *)(MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+sizeof(BITMAPINFOHEADER));
476
477 //通常バッファを取得
478 pBuffer=MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]+
479 sizeof(BITMAPINFOHEADER)+
480 sizeof(DWORD)*(int)pow((double)2,(double)pBmpInfoHdr->biBitCount);
481
482 //マスクバッファを取得
483 pMaskBuf=pBuffer+pBmpInfoHdr->biBitCount*pBmpInfoHdr->biWidth*(pBmpInfoHdr->biHeight/2)/8;
484
485 if(x>=pBmpInfoHdr->biWidth||y>=pBmpInfoHdr->biHeight/2) return 0;
486 y2=(pBmpInfoHdr->biHeight/2-1)-y;
487 i=pBmpInfoHdr->biWidth*y2+x;
488
489 //////////////////
490 // マスクピクセル
491 if(pBmpInfoHdr->biWidth==16){
492 //一行の4バイト境界を考慮
493 if((pMaskBuf[(i+pBmpInfoHdr->biWidth*y2)/8]>>(8-(i%8+1)))&0x01)
494 return TransparentClrRef;
495 }
496 else{
497 if((pMaskBuf[i/8]>>(8-(i%8+1)))&0x01)
498 return TransparentClrRef;
499 }
500
501 ////////////////
502 // 通常ピクセル
503 switch(pBmpInfoHdr->biBitCount){
504 case 4: //16色
505 if(i%2) i2=*(pBuffer+i/2)&0x0F;
506 else i2=(*(pBuffer+i/2)>>4)&0x0F;
507 ColorRef=RGB(pRgbq[i2].rgbRed,pRgbq[i2].rgbGreen,pRgbq[i2].rgbBlue);
508 break;
509 case 8: //256色
510 i2=pBuffer[i];
511 ColorRef=RGB(pRgbq[i2].rgbRed,pRgbq[i2].rgbGreen,pRgbq[i2].rgbBlue);
512 break;
513 }
514 return ColorRef;
515}
516void IconEdit_DrawLine(int WndNum,int x1,int y1,int x2,int y2,DWORD ColorCode){
517 extern MDIINFO MdiInfo[MAX_WNDNUM];
518 int dx,dy,s,step;
519
520 dx=abs(x2-x1);
521 dy=abs(y2-y1);
522 if(dx>dy){
523 if(x1>x2){
524 step=(y1>y2)?1:-1;
525 s=x1;
526 x1=x2;
527 x2=s;
528 y1=y2;
529 }
530 else step=(y1<y2)?1:-1;
531
532 PixelChange(WndNum,x1,y1,ColorCode);
533
534 s=dx>>1;
535 while(++x1<=x2){
536 if((s-=dy)<0){
537 s+=dx;
538 y1+=step;
539 }
540
541 PixelChange(WndNum,x1,y1,ColorCode);
542 }
543 }
544 else{
545 if(y1>y2){
546 step=(x1>x2)?1:-1;
547 s=y1;
548 y1=y2;
549 y2=s;
550 x1=x2;
551 }
552 else step=(x1<x2)?1:-1;
553
554 PixelChange(WndNum,x1,y1,ColorCode);
555
556 s=dy>>1;
557 while(++y1<=y2){
558 if((s-=dx)<0){
559 s+=dy;
560 x1+=step;
561 }
562
563 PixelChange(WndNum,x1,y1,ColorCode);
564 }
565 }
566}
567void IconEdit_FloodFill(int WndNum,int x,int y,COLORREF FilledColor,DWORD ColorCode){
568 extern MDIINFO MdiInfo[MAX_WNDNUM];
569
570 if(x<0||y<0) return;
571 if(x>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biWidth||
572 y>=MdiInfo[WndNum].MdiIconEditInfo->pBmpHdr[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum]->biHeight/2)
573 return;
574
575 PixelChange(WndNum,x,y,ColorCode);
576
577 if(IconEdit_GetPixel(WndNum,x,y+1)==FilledColor)
578 IconEdit_FloodFill(WndNum,x,y+1,FilledColor,ColorCode);
579 if(IconEdit_GetPixel(WndNum,x+1,y)==FilledColor)
580 IconEdit_FloodFill(WndNum,x+1,y,FilledColor,ColorCode);
581 if(IconEdit_GetPixel(WndNum,x,y-1)==FilledColor)
582 IconEdit_FloodFill(WndNum,x,y-1,FilledColor,ColorCode);
583 if(IconEdit_GetPixel(WndNum,x-1,y)==FilledColor)
584 IconEdit_FloodFill(WndNum,x-1,y,FilledColor,ColorCode);
585}
586void IconEdit_DrawRectangle(int WndNum,int x1,int y1,int x2,int y2,DWORD ColorCode,DWORD FillClrCode,BOOL bFill){
587 RectNaturalFormat(&x1,&y1,&x2,&y2);
588
589 IconEdit_DrawLine(WndNum,x1,y1,x1,y2,ColorCode);
590 IconEdit_DrawLine(WndNum,x2,y1,x2,y2,ColorCode);
591 IconEdit_DrawLine(WndNum,x1+1,y1,x2-1,y1,ColorCode);
592 IconEdit_DrawLine(WndNum,x1+1,y2,x2-1,y2,ColorCode);
593
594 if(bFill){
595 int x,y;
596 for(x=x1+1;x<x2;x++){
597 for(y=y1+1;y<y2;y++) PixelChange(WndNum,x,y,FillClrCode);
598 }
599 }
600}
601void IconEdit_DrawEllipse(int WndNum,int x1,int y1,int x2,int y2,DWORD ColorCode){
602 extern MDIINFO MdiInfo[MAX_WNDNUM];
603 RECT rect,rc2;
604
605 rect.left=x1;
606 rect.top=y1;
607 rect.right=x2;
608 rect.bottom=y2;
609 RectNaturalFormat(&rect,&rc2);
610
611 int xc,yc,rx,ry;
612 int x,y,r;
613
614 rx=(rc2.right-rc2.left)/2;
615 ry=(rc2.bottom-rc2.top)/2;
616 xc=rc2.left+rx;
617 yc=rc2.top+ry;
618 if(rx==0&&ry==0){
619 if(rc2.bottom-rc2.top==1&&rc2.bottom-rc2.top==1)
620 IconEdit_DrawRectangle(WndNum,x1,y1,x2,y2,ColorCode,0,0);
621 else IconEdit_DrawLine(WndNum,x1,y1,x2,y2,ColorCode);
622 return;
623 }
624
625 int bX,bY;
626 if((rc2.right-rc2.left)%2) bX=1;
627 else bX=0;
628 if((rc2.bottom-rc2.top)%2) bY=1;
629 else bY=0;
630
631 if(rx>ry){
632 x=r=rx;
633 y=0;
634 while(x>=y){
635 x1=x*ry/rx;
636 y1=y*ry/rx;
637
638 PixelChange(WndNum,xc+x+bX,yc+y1+bY,ColorCode);
639 PixelChange(WndNum,xc+x+bX,yc-y1,ColorCode);
640 PixelChange(WndNum,xc-x,yc+y1+bY,ColorCode);
641 PixelChange(WndNum,xc-x,yc-y1,ColorCode);
642 PixelChange(WndNum,xc+y+bX,yc+x1+bY,ColorCode);
643 PixelChange(WndNum,xc+y+bX,yc-x1,ColorCode);
644 PixelChange(WndNum,xc-y,yc+x1+bY,ColorCode);
645 PixelChange(WndNum,xc-y,yc-x1,ColorCode);
646
647 if((r-=(y++<<1)+1)<=0) r+=(x-- -1)<<1;
648 }
649 }
650 else{
651 x=r=ry;
652 y=0;
653 while(x>=y){
654 x1=x*rx/ry;
655 y1=y*rx/ry;
656
657 PixelChange(WndNum,xc+x1+bX,yc+y+bY,ColorCode);
658 PixelChange(WndNum,xc+x1+bX,yc-y,ColorCode);
659 PixelChange(WndNum,xc-x1,yc+y+bY,ColorCode);
660 PixelChange(WndNum,xc-x1,yc-y,ColorCode);
661 PixelChange(WndNum,xc+y1+bX,yc+x+bY,ColorCode);
662 PixelChange(WndNum,xc+y1+bX,yc-x,ColorCode);
663 PixelChange(WndNum,xc-y1,yc+x+bY,ColorCode);
664 PixelChange(WndNum,xc-y1,yc-x,ColorCode);
665
666 if((r-=(y++<<1)+1)<=0) r+=(x-- -1)<<1;
667 }
668 }
669}
670
671void IconEdit_EraseRect(int WndNum,RECT *pRect){
672 extern MDIINFO MdiInfo[MAX_WNDNUM];
673
674 //変更情報
675 IconEdit_NoticeChanging(WndNum);
676
677 IconEdit_DrawRectangle(WndNum,
678 pRect->left,
679 pRect->top,
680 pRect->right,
681 pRect->bottom,
682 GetColorCode(WndNum,MdiInfo[WndNum].MdiIconEditInfo->SubColor),
683 GetColorCode(WndNum,MdiInfo[WndNum].MdiIconEditInfo->SubColor),1);
684
685 DrawIconToMemBmp(WndNum,0);
686 InvalidateRect(MdiInfo[WndNum].MdiIconEditInfo->hMain,NULL,0);
687}
688
689void IconEdit_DrawFrame(HWND hwnd,int WndNum,RECT *pRect){
690 extern MDIINFO MdiInfo[MAX_WNDNUM];
691 HDC hdc;
692 HPEN hPen,hOldPen;
693 HBRUSH hOldBrush;
694 RECT rect;
695 POINT pos;
696
697 //////////////////////
698 // 選択フレームの描画
699
700 hdc=GetDC(hwnd);
701
702 //以前の選択フレームを消去
703 BITMAPINFOHEADER *pBmpInfoHdr;
704 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum];
705 pos.x=pBmpInfoHdr->biWidth;
706 pos.y=pBmpInfoHdr->biHeight/2;
707 GetZoomedPos(&pos);
708 BitBlt(hdc,0,0,pos.x,pos.y,MdiInfo[WndNum].MdiIconEditInfo->memdc,0,0,SRCCOPY);
709
710
711 hPen=CreatePen(PS_DOT,0,RGB(0,0,0));
712 SetBkMode(hdc,TRANSPARENT);
713 hOldPen=(HPEN)SelectObject(hdc,hPen);
714 hOldBrush=(HBRUSH)SelectObject(hdc,GetStockObject(NULL_BRUSH));
715
716 pos.x=pRect->left;
717 pos.y=pRect->top;
718 GetZoomedPos(&pos);
719 rect.left=pos.x;
720 rect.top=pos.y;
721
722 pos.x=pRect->right+1;
723 pos.y=pRect->bottom+1;
724 GetZoomedPos(&pos);
725 rect.right=pos.x+1;
726 rect.bottom=pos.y+1;
727
728 Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
729 SelectObject(hdc,hOldBrush);
730 SelectObject(hdc,hOldPen);
731 DeleteObject(hPen);
732
733 ReleaseDC(hwnd,hdc);
734}
735void IconEdit_DrawSelectingRect(HDC hdc,int WndNum){
736 extern MDIINFO MdiInfo[MAX_WNDNUM];
737 int i2,i3;
738 HPEN hPen,hOldPen;
739 HBRUSH hOldBrush;
740 COLORREF rgb;
741 RECT rect;
742
743 rect.left=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left*PIXEL_WIDTH+ZOOMED_XPOS;
744 rect.top=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top*PIXEL_WIDTH;
745 rect.right=(MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right+1)*PIXEL_WIDTH+ZOOMED_XPOS+1;
746 rect.bottom=(MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom+1)*PIXEL_WIDTH+1;
747
748 SetBkMode(hdc,TRANSPARENT);
749
750 //主線
751 hOldBrush=(HBRUSH)SelectObject(hdc,GetStockObject(NULL_BRUSH));
752 hPen=CreatePen(PS_SOLID,0,RGB(0,0,0));
753 hOldPen=(HPEN)SelectObject(hdc,hPen);
754 Rectangle(hdc,
755 rect.left+2, rect.top+2,
756 rect.right-2, rect.bottom-2);
757 SelectObject(hdc,hOldPen);
758 DeleteObject(hPen);
759 hPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
760 hOldPen=(HPEN)SelectObject(hdc,hPen);
761 Rectangle(hdc,
762 rect.left+1, rect.top+1,
763 rect.right-1, rect.bottom-1);
764 SelectObject(hdc,hOldPen);
765 DeleteObject(hPen);
766 SelectObject(hdc,hOldBrush);
767
768 rgb=RGB(255,60,30);
769 hPen=CreatePen(PS_SOLID,0,rgb);
770 hOldPen=(HPEN)SelectObject(hdc,hPen);
771
772 hOldBrush=(HBRUSH)SelectObject(hdc,GetStockObject(WHITE_BRUSH));
773
774 Rectangle(hdc,
775 rect.left,rect.top,
776 rect.left+5,rect.top+5);
777 Rectangle(hdc,
778 rect.left,rect.bottom-5,
779 rect.left+5,rect.bottom);
780 Rectangle(hdc,
781 rect.right-5,rect.top,
782 rect.right,rect.top+5);
783 Rectangle(hdc,
784 rect.right-5,rect.bottom-5,
785 rect.right,rect.bottom);
786
787 i2=(rect.right-rect.left)/2;
788 i3=(rect.bottom-rect.top)/2;
789 Rectangle(hdc,
790 rect.left+i2-2,rect.top,
791 rect.left+i2+3,rect.top+5);
792 Rectangle(hdc,
793 rect.left+i2-2,rect.bottom-5,
794 rect.left+i2+3,rect.bottom);
795 Rectangle(hdc,
796 rect.left,rect.top+i3-2,
797 rect.left+5,rect.top+i3+3);
798 Rectangle(hdc,
799 rect.right-5,rect.top+i3-2,
800 rect.right,rect.top+i3+3);
801
802 SelectObject(hdc,hOldBrush);
803
804 SelectObject(hdc,hOldPen);
805 DeleteObject(hPen);
806}
807void DrawZoomedBitmap(HDC hdc,int WndNum,POINT *pPos){
808 extern HANDLE hHeap;
809 extern MDIINFO MdiInfo[MAX_WNDNUM];
810 int x,y;
811 RGBQUAD rgbq;
812 HPEN hPen,hOldPen;
813 POINT pos;
814
815 BITMAP Bitmap;
816 BITMAPINFO SelectingBitmapInfo;
817 COLORREF *pSelectingBuffer;
818
819 GetObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp,sizeof(BITMAP),&Bitmap);
820 pSelectingBuffer=(COLORREF *)HeapAlloc(hHeap,0,Bitmap.bmWidth*Bitmap.bmHeight*sizeof(COLORREF));
821 SelectingBitmapInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
822 SelectingBitmapInfo.bmiHeader.biWidth=Bitmap.bmWidth;
823 SelectingBitmapInfo.bmiHeader.biHeight=Bitmap.bmHeight;
824 SelectingBitmapInfo.bmiHeader.biPlanes=1;
825 SelectingBitmapInfo.bmiHeader.biBitCount=32;
826 SelectingBitmapInfo.bmiHeader.biCompression=BI_RGB;
827 GetDIBits(MdiInfo[WndNum].MdiIconEditInfo->memdc,
828 MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp,
829 0,Bitmap.bmHeight,
830 pSelectingBuffer,&SelectingBitmapInfo,DIB_RGB_COLORS);
831
832 hPen=CreatePen(PS_SOLID,0,RGB(200,200,200));
833 hOldPen=(HPEN)SelectObject(hdc,hPen);
834
835 for(y=Bitmap.bmHeight-1;y>=0;y--){
836 for(x=0;x<Bitmap.bmWidth;x++){
837 memcpy(&rgbq,
838 &pSelectingBuffer[(Bitmap.bmHeight-y-1)*Bitmap.bmWidth+x],
839 sizeof(RGBQUAD));
840
841 HBRUSH hBrush,hOldBrush;
842 hBrush=CreateSolidBrush(RGB(rgbq.rgbRed,rgbq.rgbGreen,rgbq.rgbBlue));
843 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
844
845 pos.x=pPos->x+x;
846 pos.y=pPos->y+y;
847 GetZoomedPos(&pos);
848 Rectangle(hdc,pos.x,pos.y,pos.x+11,pos.y+11);
849
850 SelectObject(hdc,hOldBrush);
851 DeleteObject(hBrush);
852 }
853 }
854
855 SelectObject(hdc,hOldPen);
856 DeleteObject(hPen);
857
858 HeapDefaultFree(pSelectingBuffer);
859}
860int IconEdit_GetStateOfDraggingFrame(int WndNum,int x,int y){
861 extern MDIINFO MdiInfo[MAX_WNDNUM];
862 POINT pos;
863 RECT rect;
864
865 pos.x=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left;
866 pos.y=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top;
867 GetZoomedPos(&pos);
868 rect.left=pos.x;
869 rect.top=pos.y;
870 pos.x=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right+1;
871 pos.y=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom+1;
872 GetZoomedPos(&pos);
873 rect.right=pos.x;
874 rect.bottom=pos.y;
875
876 if(rect.left<x&&x<rect.right&&
877 rect.top<y&&y<rect.bottom) return FRAME_INSIDE;
878 return 0;
879}
880void DrawSelectingImage(HDC hdc,int WndNum){
881 /////////////////////////////////
882 // 選択されているイメージを表示
883
884 extern MDIINFO MdiInfo[MAX_WNDNUM];
885 HDC hDC2;
886 SIZE size;
887 POINT pos;
888
889 size.cx=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left;
890 size.cy=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom-MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top;
891 hDC2=CreateCompatibleDC(MdiInfo[WndNum].MdiIconEditInfo->memdc);
892 SelectObject(hDC2,MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
893 BitBlt(hdc,
894 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left,
895 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top,
896 size.cx,size.cy,
897 hDC2,0,0,SRCCOPY);
898 DeleteDC(hDC2);
899
900 //拡大選択イメージを表示
901 pos.x=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left;
902 pos.y=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top;
903 DrawZoomedBitmap(hdc,WndNum,&pos);
904}
905void TempLine(HDC hdc,int WndNum,int x1,int y1,int x2,int y2,COLORREF ColorRef){
906 extern MDIINFO MdiInfo[MAX_WNDNUM];
907 int dx,dy,s,step;
908 HPEN hPen,hOldPen;
909 HBRUSH hBrush,hOldBrush;
910
911 hPen=CreatePen(PS_SOLID,0,RGB(200,200,200));
912 hOldPen=(HPEN)SelectObject(hdc,hPen);
913 hBrush=CreateSolidBrush(ColorRef);
914 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
915
916 dx=abs(x2-x1);
917 dy=abs(y2-y1);
918 if(dx>dy){
919 if(x1>x2){
920 step=(y1>y2)?1:-1;
921 s=x1;
922 x1=x2;
923 x2=s;
924 y1=y2;
925 }
926 else step=(y1<y2)?1:-1;
927
928 SetZoomedPixel(hdc,WndNum,x1,y1);
929
930 s=dx>>1;
931 while(++x1<=x2){
932 if((s-=dy)<0){
933 s+=dx;
934 y1+=step;
935 }
936
937 SetZoomedPixel(hdc,WndNum,x1,y1);
938 }
939 }
940 else{
941 if(y1>y2){
942 step=(x1>x2)?1:-1;
943 s=y1;
944 y1=y2;
945 y2=s;
946 x1=x2;
947 }
948 else step=(x1<x2)?1:-1;
949
950 SetZoomedPixel(hdc,WndNum,x1,y1);
951
952 s=dy>>1;
953 while(++y1<=y2){
954 if((s-=dx)<0){
955 s+=dy;
956 x1+=step;
957 }
958
959 SetZoomedPixel(hdc,WndNum,x1,y1);
960 }
961 }
962
963 SelectObject(hdc,hOldBrush);
964 SelectObject(hdc,hOldPen);
965 DeleteObject(hPen);
966 DeleteObject(hBrush);
967}
968void TempRectangle(HDC hdc,int WndNum,int x1,int y1,int x2,int y2,COLORREF ColorRef,COLORREF FillClrRef,BOOL bFill){
969 extern MDIINFO MdiInfo[MAX_WNDNUM];
970 int x,y;
971 HPEN hPen,hOldPen;
972 HBRUSH hBrush,hOldBrush;
973 RECT rect,rc2;
974
975 hPen=CreatePen(PS_SOLID,0,ColorRef);
976 hOldPen=(HPEN)SelectObject(hdc,hPen);
977 if(!bFill) hBrush=(HBRUSH)GetStockObject(NULL_BRUSH);
978 else hBrush=CreateSolidBrush(FillClrRef);
979 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
980 Rectangle(hdc,x1,y1,x2,y2);
981 SelectObject(hdc,hOldBrush);
982 SelectObject(hdc,hOldPen);
983 DeleteObject(hPen);
984 if(bFill) DeleteObject(hBrush);
985
986 rect.left=x1;
987 rect.top=y1;
988 rect.right=x2;
989 rect.bottom=y2;
990 RectNaturalFormat(&rect,&rc2);
991
992 hPen=CreatePen(PS_SOLID,0,RGB(200,200,200));
993 hOldPen=(HPEN)SelectObject(hdc,hPen);
994 hBrush=CreateSolidBrush(ColorRef);
995 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
996
997 x=rc2.left;
998 for(y=rc2.top;y<=rc2.bottom;y++)
999 SetZoomedPixel(hdc,WndNum,x,y);
1000
1001 x=rc2.right;
1002 for(y=rc2.top;y<=rc2.bottom;y++)
1003 SetZoomedPixel(hdc,WndNum,x,y);
1004
1005 y=rc2.top;
1006 for(x=rc2.left+1;x<rc2.right;x++)
1007 SetZoomedPixel(hdc,WndNum,x,y);
1008
1009 y=rc2.bottom;
1010 for(x=rc2.left+1;x<rc2.right;x++)
1011 SetZoomedPixel(hdc,WndNum,x,y);
1012
1013 SelectObject(hdc,hOldBrush);
1014 DeleteObject(hBrush);
1015
1016 if(bFill){
1017 hBrush=CreateSolidBrush(FillClrRef);
1018 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
1019 for(x=rc2.left+1;x<rc2.right;x++){
1020 for(y=rc2.top+1;y<rc2.bottom;y++) SetZoomedPixel(hdc,WndNum,x,y);
1021 }
1022 SelectObject(hdc,hOldBrush);
1023 DeleteObject(hBrush);
1024 }
1025
1026 SelectObject(hdc,hOldPen);
1027 DeleteObject(hPen);
1028}
1029void TempEllipse(HDC hdc,int WndNum,int x1,int y1,int x2,int y2,COLORREF ColorRef){
1030 extern MDIINFO MdiInfo[MAX_WNDNUM];
1031 HPEN hPen,hOldPen;
1032 HBRUSH hBrush,hOldBrush;
1033 RECT rect,rc2;
1034
1035 rect.left=x1;
1036 rect.top=y1;
1037 rect.right=x2;
1038 rect.bottom=y2;
1039 RectNaturalFormat(&rect,&rc2);
1040
1041 int xc,yc,rx,ry;
1042 int x,y,r;
1043
1044 rx=(rc2.right-rc2.left)/2;
1045 ry=(rc2.bottom-rc2.top)/2;
1046 xc=rc2.left+rx;
1047 yc=rc2.top+ry;
1048 if(rx==0&&ry==0){
1049 if(rc2.bottom-rc2.top==1&&rc2.bottom-rc2.top==1)
1050 TempRectangle(hdc,WndNum,x1,y1,x2,y2,ColorRef,0,0);
1051 else TempLine(hdc,WndNum,x1,y1,x2,y2,ColorRef);
1052 return;
1053 }
1054
1055 int bX,bY;
1056 if((rc2.right-rc2.left)%2) bX=1;
1057 else bX=0;
1058 if((rc2.bottom-rc2.top)%2) bY=1;
1059 else bY=0;
1060
1061 hPen=CreatePen(PS_SOLID,0,RGB(200,200,200));
1062 hOldPen=(HPEN)SelectObject(hdc,hPen);
1063 hBrush=CreateSolidBrush(ColorRef);
1064 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
1065
1066 if(rx>ry){
1067 x=r=rx;
1068 y=0;
1069 while(x>=y){
1070 x1=x*ry/rx;
1071 y1=y*ry/rx;
1072
1073 SetZoomedPixel(hdc,WndNum,xc+x+bX,yc+y1+bY);
1074 SetZoomedPixel(hdc,WndNum,xc+x+bX,yc-y1);
1075 SetZoomedPixel(hdc,WndNum,xc-x,yc+y1+bY);
1076 SetZoomedPixel(hdc,WndNum,xc-x,yc-y1);
1077 SetZoomedPixel(hdc,WndNum,xc+y+bX,yc+x1+bY);
1078 SetZoomedPixel(hdc,WndNum,xc+y+bX,yc-x1);
1079 SetZoomedPixel(hdc,WndNum,xc-y,yc+x1+bY);
1080 SetZoomedPixel(hdc,WndNum,xc-y,yc-x1);
1081
1082 SetPixel(hdc,xc+x+bX,yc+y1+bY,ColorRef);
1083 SetPixel(hdc,xc+x+bX,yc-y1,ColorRef);
1084 SetPixel(hdc,xc-x,yc+y1+bY,ColorRef);
1085 SetPixel(hdc,xc-x,yc-y1,ColorRef);
1086 SetPixel(hdc,xc+y+bX,yc+x1+bY,ColorRef);
1087 SetPixel(hdc,xc+y+bX,yc-x1,ColorRef);
1088 SetPixel(hdc,xc-y,yc+x1+bY,ColorRef);
1089 SetPixel(hdc,xc-y,yc-x1,ColorRef);
1090
1091 if((r-=(y++<<1)+1)<=0) r+=(x-- -1)<<1;
1092 }
1093 }
1094 else{
1095 x=r=ry;
1096 y=0;
1097 while(x>=y){
1098 x1=x*rx/ry;
1099 y1=y*rx/ry;
1100
1101 SetZoomedPixel(hdc,WndNum,xc+x1+bX,yc+y+bY);
1102 SetZoomedPixel(hdc,WndNum,xc+x1+bX,yc-y);
1103 SetZoomedPixel(hdc,WndNum,xc-x1,yc+y+bY);
1104 SetZoomedPixel(hdc,WndNum,xc-x1,yc-y);
1105 SetZoomedPixel(hdc,WndNum,xc+y1+bX,yc+x+bY);
1106 SetZoomedPixel(hdc,WndNum,xc+y1+bX,yc-x);
1107 SetZoomedPixel(hdc,WndNum,xc-y1,yc+x+bY);
1108 SetZoomedPixel(hdc,WndNum,xc-y1,yc-x);
1109
1110 SetPixel(hdc,xc+x1+bX,yc+y+bY,ColorRef);
1111 SetPixel(hdc,xc+x1+bX,yc-y,ColorRef);
1112 SetPixel(hdc,xc-x1,yc+y+bY,ColorRef);
1113 SetPixel(hdc,xc-x1,yc-y,ColorRef);
1114 SetPixel(hdc,xc+y1+bX,yc+x+bY,ColorRef);
1115 SetPixel(hdc,xc+y1+bX,yc-x,ColorRef);
1116 SetPixel(hdc,xc-y1,yc+x+bY,ColorRef);
1117 SetPixel(hdc,xc-y1,yc-x,ColorRef);
1118
1119 if((r-=(y++<<1)+1)<=0) r+=(x-- -1)<<1;
1120 }
1121 }
1122
1123 SelectObject(hdc,hOldBrush);
1124 SelectObject(hdc,hOldPen);
1125 DeleteObject(hPen);
1126 DeleteObject(hBrush);
1127}
1128LRESULT CALLBACK IconEditWindowProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
1129 extern MDIINFO MdiInfo[MAX_WNDNUM];
1130 int WndNum,dx,dy;
1131 BOOL bRedrawMemBmp;
1132 HDC hdc;
1133 POINT pos,p2;
1134 RECT rect,rc2;
1135 COLORREF ColorRef,MainClrRef,SubClrRef;
1136 static DWORD dwDrag; //左クリック時は1、右クリック時は2、それ以外は0
1137 static int NowDragging;
1138 static POINT LastPos;
1139 static RECT OldRect;
1140
1141 switch(message){
1142 case WM_LBUTTONDOWN:
1143 case WM_RBUTTONDOWN:
1144 if(dwDrag) return 0;
1145
1146 pos.x=(short)(LOWORD(lParam)-ZOOMED_XPOS)/PIXEL_WIDTH;
1147 pos.y=(short)HIWORD(lParam)/PIXEL_WIDTH;
1148
1149 SetFocus(hwnd);
1150 WndNum=GetWndNum(GetParent(hwnd));
1151
1152 SetCapture(hwnd);
1153 if(message==WM_LBUTTONDOWN){
1154 dwDrag=1;
1155 MainClrRef=MdiInfo[WndNum].MdiIconEditInfo->MainColor;
1156 SubClrRef=MdiInfo[WndNum].MdiIconEditInfo->SubColor;
1157 }
1158 else{
1159 dwDrag=2;
1160 MainClrRef=MdiInfo[WndNum].MdiIconEditInfo->SubColor;
1161 SubClrRef=MdiInfo[WndNum].MdiIconEditInfo->MainColor;
1162 }
1163
1164 if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_SELECT){
1165 if(dwDrag==2){
1166 dwDrag=0;
1167 ReleaseCapture();
1168 break;
1169 }
1170
1171 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel){
1172 NowDragging=IconEdit_GetStateOfDraggingFrame(WndNum,LOWORD(lParam),HIWORD(lParam));
1173 if(NowDragging==0){
1174 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==1){
1175 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=0;
1176 InvalidateRect(hwnd,NULL,0);
1177 }
1178 else if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==2)
1179 IconEdit_PasteImage(WndNum);
1180
1181 NowDragging=SELECTING_FRAME;
1182 }
1183 else if(NowDragging==FRAME_INSIDE){
1184 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==1){
1185 IconEdit_SelectImage(WndNum);
1186 IconEdit_EraseRect(WndNum,&MdiInfo[WndNum].MdiIconEditInfo->DraggingRect);
1187 }
1188
1189 OldRect=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect;
1190 }
1191 }
1192 else{
1193 NowDragging=SELECTING_FRAME;
1194 SetCursor(LoadCursor(NULL,IDC_CROSS));
1195 }
1196
1197 LastPos=pos;
1198 InvalidateRect(hwnd,NULL,0);
1199 }
1200 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_PEN){
1201 //変更情報
1202 IconEdit_NoticeChanging(WndNum);
1203
1204 PixelChange(WndNum,pos.x,pos.y,GetColorCode(WndNum,MainClrRef));
1205 LastPos=pos;
1206
1207 rect.left=pos.x;
1208 rect.top=pos.y;
1209 rect.right=pos.x;
1210 rect.bottom=pos.y;
1211 DrawIconToMemBmp(WndNum,&rect);
1212 InvalidateRect(hwnd,NULL,0);
1213
1214 SetCursor(LoadCursor(hResInst,MAKEINTRESOURCE(IDC_CURSOR_PEN)));
1215 }
1216 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILL){
1217 //変更情報
1218 IconEdit_NoticeChanging(WndNum);
1219
1220 hdc=GetDC(hwnd);
1221 ColorRef=GetPixel(hdc,pos.x,pos.y);
1222 ReleaseDC(hwnd,hdc);
1223 if(ColorRef!=MainClrRef){
1224 IconEdit_FloodFill(WndNum,pos.x,pos.y,ColorRef,GetColorCode(WndNum,MainClrRef));
1225
1226 DrawIconToMemBmp(WndNum,0);
1227 InvalidateRect(hwnd,NULL,0);
1228 }
1229 SetCursor(LoadCursor(hResInst,MAKEINTRESOURCE(IDC_CURSOR_FILL)));
1230 }
1231 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_LINE||
1232 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_RECTANGLE||
1233 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT||
1234 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT2||
1235 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_ELLIPSE){
1236 hdc=GetDC(hwnd);
1237 TempLine(hdc,WndNum,pos.x,pos.y,pos.x,pos.y,MainClrRef);
1238 ReleaseDC(hwnd,hdc);
1239
1240 LastPos=pos;
1241
1242 SetCursor(LoadCursor(NULL,IDC_CROSS));
1243 }
1244 return 0;
1245 case WM_LBUTTONUP:
1246 case WM_RBUTTONUP:
1247 if(dwDrag==0) return 0;
1248 if(dwDrag==1&&message==WM_RBUTTONUP||
1249 dwDrag==2&&message==WM_LBUTTONUP) return 0;
1250
1251 WndNum=GetWndNum(GetParent(hwnd));
1252
1253 pos.x=(short)(LOWORD(lParam)-ZOOMED_XPOS)/PIXEL_WIDTH;
1254 pos.y=(short)HIWORD(lParam)/PIXEL_WIDTH;
1255
1256 if(dwDrag==1){
1257 MainClrRef=MdiInfo[WndNum].MdiIconEditInfo->MainColor;
1258 SubClrRef=MdiInfo[WndNum].MdiIconEditInfo->SubColor;
1259 }
1260 else{
1261 MainClrRef=MdiInfo[WndNum].MdiIconEditInfo->SubColor;
1262 SubClrRef=MdiInfo[WndNum].MdiIconEditInfo->MainColor;
1263 }
1264
1265 ReleaseCapture();
1266 dwDrag=0;
1267
1268 bRedrawMemBmp=0;
1269 if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_SELECT){
1270 if(NowDragging==SELECTING_FRAME){
1271 if(LastPos.x==pos.x&&LastPos.y==pos.y){
1272 ResetState_EditMenu();
1273 return 0;
1274 }
1275 rect.left=LastPos.x;
1276 rect.top=LastPos.y;
1277 rect.right=pos.x;
1278 rect.bottom=pos.y;
1279
1280 RectNaturalFormat(&rect,&MdiInfo[WndNum].MdiIconEditInfo->DraggingRect);
1281 LimitRectFormat(WndNum,&MdiInfo[WndNum].MdiIconEditInfo->DraggingRect);
1282 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=1;
1283 InvalidateRect(hwnd,NULL,0);
1284 }
1285 else if(NowDragging==FRAME_INSIDE)
1286 InvalidateRect(hwnd,NULL,0);
1287 }
1288 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_LINE){
1289 //変更情報
1290 IconEdit_NoticeChanging(WndNum);
1291
1292 IconEdit_DrawLine(WndNum,LastPos.x,LastPos.y,pos.x,pos.y,GetColorCode(WndNum,MainClrRef));
1293
1294 bRedrawMemBmp=1;
1295 }
1296 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_RECTANGLE){
1297 //変更情報
1298 IconEdit_NoticeChanging(WndNum);
1299
1300 IconEdit_DrawRectangle(WndNum,LastPos.x,LastPos.y,pos.x,pos.y,GetColorCode(WndNum,MainClrRef),0,0);
1301
1302 bRedrawMemBmp=1;
1303 }
1304 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT){
1305 //変更情報
1306 IconEdit_NoticeChanging(WndNum);
1307
1308 IconEdit_DrawRectangle(WndNum,LastPos.x,LastPos.y,pos.x,pos.y,
1309 GetColorCode(WndNum,MainClrRef),
1310 GetColorCode(WndNum,SubClrRef),1);
1311
1312 bRedrawMemBmp=1;
1313 }
1314 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT2){
1315 //変更情報
1316 IconEdit_NoticeChanging(WndNum);
1317
1318 IconEdit_DrawRectangle(WndNum,LastPos.x,LastPos.y,pos.x,pos.y,
1319 GetColorCode(WndNum,MainClrRef),
1320 GetColorCode(WndNum,MainClrRef),1);
1321
1322 bRedrawMemBmp=1;
1323 }
1324 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_ELLIPSE){
1325 //変更情報
1326 IconEdit_NoticeChanging(WndNum);
1327
1328 IconEdit_DrawEllipse(WndNum,LastPos.x,LastPos.y,pos.x,pos.y,GetColorCode(WndNum,MainClrRef));
1329
1330 bRedrawMemBmp=1;
1331 }
1332
1333 if(bRedrawMemBmp){
1334 rect.left=LastPos.x;
1335 rect.top=LastPos.y;
1336 rect.right=pos.x;
1337 rect.bottom=pos.y;
1338 RectNaturalFormat(&rect,&rc2);
1339 DrawIconToMemBmp(WndNum,&rc2);
1340 InvalidateRect(hwnd,NULL,0);
1341 }
1342
1343 ResetState_EditMenu();
1344 return 0;
1345 case WM_MOUSEMOVE:
1346 WndNum=GetWndNum(GetParent(hwnd));
1347
1348 pos.x=(short)(LOWORD(lParam)-ZOOMED_XPOS)/PIXEL_WIDTH;
1349 pos.y=(short)HIWORD(lParam)/PIXEL_WIDTH;
1350
1351 if(dwDrag==1){
1352 MainClrRef=MdiInfo[WndNum].MdiIconEditInfo->MainColor;
1353 SubClrRef=MdiInfo[WndNum].MdiIconEditInfo->SubColor;
1354 }
1355 else{
1356 MainClrRef=MdiInfo[WndNum].MdiIconEditInfo->SubColor;
1357 SubClrRef=MdiInfo[WndNum].MdiIconEditInfo->MainColor;
1358 }
1359
1360 if(dwDrag){
1361 if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_SELECT){
1362 if(NowDragging==SELECTING_FRAME){
1363 //範囲選択中
1364 rect.left=LastPos.x;
1365 rect.top=LastPos.y;
1366 rect.right=pos.x;
1367 rect.bottom=pos.y;
1368 RectNaturalFormat(&rect,&rc2);
1369 LimitRectFormat(WndNum,&rc2);
1370 IconEdit_DrawFrame(hwnd,WndNum,&rc2);
1371 }
1372 else if(NowDragging==FRAME_INSIDE){
1373 //移動中
1374 dx=pos.x-LastPos.x;
1375 dy=pos.y-LastPos.y;
1376 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left+=dx;
1377 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right+=dx;
1378 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top+=dy;
1379 MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom+=dy;
1380 LastPos=pos;
1381
1382
1383 ////////////////////////
1384 // 古い選択範囲を再描画
1385 HRGN hRgn,hRgn2;
1386
1387 OldRect.right++;
1388 OldRect.bottom++;
1389
1390 hRgn=CreateRectRgnIndirect(&OldRect);
1391 hRgn2=CreateRectRgnIndirect(&MdiInfo[WndNum].MdiIconEditInfo->DraggingRect);
1392 CombineRgn(hRgn,hRgn,hRgn2,RGN_XOR);
1393 DeleteObject(hRgn2);
1394
1395 p2.x=OldRect.left;
1396 p2.y=OldRect.top;
1397 GetZoomedPos(&p2);
1398 rect.left=p2.x;
1399 rect.top=p2.y;
1400 p2.x=OldRect.right;
1401 p2.y=OldRect.bottom;
1402 GetZoomedPos(&p2);
1403 rect.right=p2.x+1;
1404 rect.bottom=p2.y+1;
1405 hRgn2=CreateRectRgnIndirect(&rect);
1406 CombineRgn(hRgn,hRgn,hRgn2,RGN_OR);
1407 DeleteObject(hRgn2);
1408
1409 p2.x=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.left;
1410 p2.y=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.top;
1411 GetZoomedPos(&p2);
1412 rect.left=p2.x;
1413 rect.top=p2.y;
1414 p2.x=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.right;
1415 p2.y=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect.bottom;
1416 GetZoomedPos(&p2);
1417 rect.right=p2.x+1;
1418 rect.bottom=p2.y+1;
1419 hRgn2=CreateRectRgnIndirect(&rect);
1420 CombineRgn(hRgn,hRgn,hRgn2,RGN_XOR);
1421 DeleteObject(hRgn2);
1422
1423 InvalidateRgn(hwnd,hRgn,0);
1424 DeleteObject(hRgn);
1425 UpdateWindow(hwnd);
1426 hdc=GetDC(hwnd);
1427 DrawSelectingImage(hdc,WndNum);
1428 ReleaseDC(hwnd,hdc);
1429
1430 OldRect=MdiInfo[WndNum].MdiIconEditInfo->DraggingRect;
1431 }
1432 }
1433 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_PEN){
1434 if(abs(pos.x-LastPos.x)>1||abs(pos.y-LastPos.y)>1){
1435 IconEdit_DrawLine(WndNum,LastPos.x,LastPos.y,pos.x,pos.y,GetColorCode(WndNum,MainClrRef));
1436
1437 rect.left=LastPos.x;
1438 rect.top=LastPos.y;
1439 rect.right=pos.x;
1440 rect.bottom=pos.y;
1441 RectNaturalFormat(&rect,&rc2);
1442 DrawIconToMemBmp(WndNum,&rc2);
1443 InvalidateRect(hwnd,NULL,0);
1444 }
1445 else{
1446 PixelChange(WndNum,pos.x,pos.y,GetColorCode(WndNum,MainClrRef));
1447
1448 rect.left=pos.x;
1449 rect.top=pos.y;
1450 rect.right=pos.x;
1451 rect.bottom=pos.y;
1452 DrawIconToMemBmp(WndNum,&rect);
1453 InvalidateRect(hwnd,NULL,0);
1454 }
1455 LastPos=pos;
1456 }
1457 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_LINE){
1458 InvalidateRect(hwnd,NULL,0);
1459 UpdateWindow(hwnd);
1460
1461 hdc=GetDC(hwnd);
1462 TempLine(hdc,WndNum,LastPos.x,LastPos.y,pos.x,pos.y,MainClrRef);
1463 ReleaseDC(hwnd,hdc);
1464 }
1465 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_RECTANGLE){
1466 InvalidateRect(hwnd,NULL,0);
1467 UpdateWindow(hwnd);
1468
1469 hdc=GetDC(hwnd);
1470 TempRectangle(hdc,WndNum,LastPos.x,LastPos.y,pos.x,pos.y,MainClrRef,0,0);
1471 ReleaseDC(hwnd,hdc);
1472 }
1473 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT){
1474 InvalidateRect(hwnd,NULL,0);
1475 UpdateWindow(hwnd);
1476
1477 hdc=GetDC(hwnd);
1478 TempRectangle(hdc,WndNum,LastPos.x,LastPos.y,pos.x,pos.y,
1479 MainClrRef,
1480 SubClrRef,1);
1481 ReleaseDC(hwnd,hdc);
1482 }
1483 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT2){
1484 InvalidateRect(hwnd,NULL,0);
1485 UpdateWindow(hwnd);
1486
1487 hdc=GetDC(hwnd);
1488 TempRectangle(hdc,WndNum,LastPos.x,LastPos.y,pos.x,pos.y,
1489 MainClrRef,
1490 MainClrRef,1);
1491 ReleaseDC(hwnd,hdc);
1492 }
1493 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_ELLIPSE){
1494 InvalidateRect(hwnd,NULL,0);
1495 UpdateWindow(hwnd);
1496
1497 hdc=GetDC(hwnd);
1498 TempEllipse(hdc,WndNum,LastPos.x,LastPos.y,pos.x,pos.y,MainClrRef);
1499 ReleaseDC(hwnd,hdc);
1500 }
1501 }
1502 else{
1503 //ドラッグ中でないとき
1504 if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_SELECT){
1505 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel)
1506 SetCursorByState(IconEdit_GetStateOfDraggingFrame(WndNum,LOWORD(lParam),HIWORD(lParam)));
1507 else
1508 SetCursor(LoadCursor(NULL,IDC_CROSS));
1509 }
1510 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_PEN)
1511 SetCursor(LoadCursor(hResInst,MAKEINTRESOURCE(IDC_CURSOR_PEN)));
1512 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILL)
1513 SetCursor(LoadCursor(hResInst,MAKEINTRESOURCE(IDC_CURSOR_FILL)));
1514 else if(MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_LINE||
1515 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_RECTANGLE||
1516 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT||
1517 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_FILLRECT2||
1518 MdiInfo[WndNum].MdiIconEditInfo->NowTool==IDC_TOOL_ELLIPSE){
1519 SetCursor(LoadCursor(NULL,IDC_CROSS));
1520 }
1521 }
1522 return 0;
1523 case WM_KEYDOWN:
1524 switch(wParam){
1525 case VK_ESCAPE:
1526 WndNum=GetWndNum(GetParent(hwnd));
1527 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==2){
1528 DeleteObject(MdiInfo[WndNum].MdiIconEditInfo->hSelectingBmp);
1529 MdiInfo[WndNum].MdiIconEditInfo->SelectLevel=0;
1530 }
1531 InvalidateRect(hwnd,NULL,0);
1532 return 0;
1533 }
1534 break;
1535 case WM_PAINT:
1536 PAINTSTRUCT ps;
1537 SIZE size;
1538
1539 WndNum=GetWndNum(GetParent(hwnd));
1540 BITMAPINFOHEADER *pBmpInfoHdr;
1541 pBmpInfoHdr=(BITMAPINFOHEADER *)MdiInfo[WndNum].MdiIconEditInfo->pIconImage[MdiInfo[WndNum].MdiIconEditInfo->SelectIconNum];
1542
1543 hdc=BeginPaint(hwnd,&ps);
1544
1545 size.cx=ZOOMED_XPOS+pBmpInfoHdr->biWidth*PIXEL_WIDTH+1;
1546 size.cy=pBmpInfoHdr->biWidth*PIXEL_WIDTH+1;
1547
1548 BitBlt(hdc,
1549 0,0,
1550 size.cx,
1551 size.cy,
1552 MdiInfo[WndNum].MdiIconEditInfo->memdc,0,0,SRCCOPY);
1553
1554 HBRUSH hOldBrush;
1555 hOldBrush=(HBRUSH)SelectObject(hdc,GetStockObject(WHITE_BRUSH));
1556 PatBlt(hdc,
1557 0,size.cy,
1558 ScreenX,ScreenY-size.cy,
1559 PATCOPY);
1560 PatBlt(hdc,
1561 size.cx,0,
1562 ScreenX-size.cx,size.cy,
1563 PATCOPY);
1564
1565 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==1)
1566 IconEdit_DrawSelectingRect(hdc,WndNum);
1567 if(MdiInfo[WndNum].MdiIconEditInfo->SelectLevel==2){
1568 DrawSelectingImage(hdc,WndNum);
1569 if(dwDrag==0) IconEdit_DrawSelectingRect(hdc,WndNum);
1570 }
1571
1572 EndPaint(hwnd,&ps);
1573 return 0;
1574 }
1575 return DefWindowProc(hwnd,message,wParam,lParam);
1576}
Note: See TracBrowser for help on using the repository browser.