source: Include/basic/prompt.sbp@ 119

Last change on this file since 119 was 119, checked in by イグトランス (egtra), 17 years ago

Unicode (#50) 前準備
Byte→Char (#51) 型名は殆ど完了、ただし中身までは手を付けていないものが多い

File size: 20.7 KB
Line 
1'prompt.sbp
2
3
4#ifndef _INC_PROMPT
5#define _INC_PROMPT
6
7
8#include <api_imm.sbp>
9
10Dim _PromptSys_hWnd As HWND
11Dim _PromptSys_dwThreadID As DWord
12Dim _PromptSys_bInitFinish As BOOL
13
14'text
15Dim _PromptSys_LogFont As LOGFONT
16Dim _PromptSys_hFont As HFONT
17Dim _PromptSys_FontSize As SIZE
18Dim _PromptSys_InputStr[255] As Char
19Dim _PromptSys_InputLen As Long
20Dim _PromptSys_KeyChar As Byte
21Dim _PromptSys_CurPos As POINTAPI
22Dim _PromptSys_Buffer[100] As *Char
23Dim _PromptSys_TextColor[100] As DWordPtr
24Dim _PromptSys_BackColor[100] As DWordPtr
25Dim _PromptSys_NowTextColor As DWord
26Dim _PromptSys_NowBackColor As DWord
27Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION
28
29
30_PromptSys_InputLen=-1
31
32'graphic
33Dim _PromptSys_hBitmap As HBITMAP
34Dim _PromptSys_hMemDC As HDC
35Dim _PromptSys_ScreenSize As SIZE
36Dim _PromptSys_GlobalPos As POINTAPI
37
38
39_PromptSys_bInitFinish=0
40CreateThread(
41 0,
42 0,
43 AddressOf(PromptMain) As LPTHREAD_START_ROUTINE,
44 0 As VoidPtr,
45 0,
46 _PromptSys_dwThreadID)
47Do
48 Sleep(20)
49Loop Until _PromptSys_bInitFinish
50
51Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
52 Dim i As Long, i2 As Long, i3 As Long
53 Dim hOldFont As HFONT
54 Dim sz As SIZE
55 Dim temporary[2] As Char
56
57 hOldFont=SelectObject(hDC,_PromptSys_hFont)
58
59 'Scroll
60 Dim rc As RECT
61 GetClientRect(_PromptSys_hWnd,rc)
62 While (_PromptSys_CurPos.y+1)*_PromptSys_FontSize.cy>rc.bottom and _PromptSys_CurPos.y>0
63 HeapFree(_System_hProcessHeap,0,_PromptSys_Buffer[0])
64 HeapFree(_System_hProcessHeap,0,_PromptSys_TextColor[0])
65 HeapFree(_System_hProcessHeap,0,_PromptSys_BackColor[0])
66 For i=0 To 100-1
67 _PromptSys_Buffer[i]=_PromptSys_Buffer[i+1]
68 _PromptSys_TextColor[i]=_PromptSys_TextColor[i+1]
69 _PromptSys_BackColor[i]=_PromptSys_BackColor[i+1]
70 Next
71 _PromptSys_Buffer[100]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255)
72 _PromptSys_TextColor[100]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR))
73 _PromptSys_BackColor[100]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR))
74
75 _PromptSys_CurPos.y--
76
77 'Redraw
78 StartLine=-1
79 Wend
80
81 i=0
82 While i*_PromptSys_FontSize.cy<rc.bottom and i<=100
83 If StartLine=-1 or (StartLine<=i and i<=EndLine) Then
84 GetTextExtentPoint32(hDC,_PromptSys_Buffer[i],lstrlen(_PromptSys_Buffer[i]),sz)
85 BitBlt(hDC,_
86 sz.cx, i*_PromptSys_FontSize.cy, _
87 rc.right, _PromptSys_FontSize.cy, _
88 _PromptSys_hMemDC,sz.cx,i*_PromptSys_FontSize.cy,SRCCOPY)
89
90 i3=lstrlen(_PromptSys_Buffer[i])
91 For i2=0 To i3-1
92 SetTextColor(hDC,_PromptSys_TextColor[i][i2])
93 If _PromptSys_BackColor[i][i2]=-1 Then
94 SetBkMode(hDC,TRANSPARENT)
95 Else
96 SetBkMode(hDC,OPAQUE)
97 SetBkColor(hDC,_PromptSys_BackColor[i][i2])
98 End If
99
100 temporary[0]=_PromptSys_Buffer[i][i2]
101#ifdef UNICODE
102 If _System_IsSurrogatePair(_PromptSys_Buffer[i][i2], _PromptSys_Buffer[i][i2+1]) Then
103#else
104 If IsDBCSLeadByte(temporary[0]) Then
105#endif
106 temporary[1]=_PromptSys_Buffer[i][i2+1]
107 temporary[2]=0
108 i2++
109 Else
110 temporary[1]=0
111 End If
112 TextOut(hDC,i2*_PromptSys_FontSize.cx,i*_PromptSys_FontSize.cy,_
113 temporary,lstrlen(temporary))
114 Next
115 End If
116
117 i++
118 Wend
119
120 SelectObject(hDC,hOldFont)
121End Sub
122
123Sub PRINT_ToPrompt(buf As String)
124 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
125
126 Dim hDC As HDC
127 Dim StartLine As Long
128 Dim i2 As Long, i3 As Long
129
130 StartLine=_PromptSys_CurPos.y
131
132 'Addition
133 i2=0
134 Do
135 If buf[i2]=9 Then 'tab
136 i3=8-(_PromptSys_CurPos.x mod 8)
137
138 FillMemory(_PromptSys_Buffer[_PromptSys_CurPos.y]+_PromptSys_CurPos.x,i3,Asc(" "))
139
140 i2++
141 _PromptSys_CurPos.x += i3
142 Continue
143 End If
144
145 If buf[i2]=13 and buf[i2+1]=10 Then '\r\n
146 i2 += 2
147 _PromptSys_CurPos.y++
148 _PromptSys_CurPos.x=0
149 Continue
150 End If
151
152 If buf[i2]=0 Then Exit Do
153 _PromptSys_Buffer[_PromptSys_CurPos.y][_PromptSys_CurPos.x]=buf[i2]
154 _PromptSys_TextColor[_PromptSys_CurPos.y][_PromptSys_CurPos.x]=_PromptSys_NowTextColor
155 _PromptSys_BackColor[_PromptSys_CurPos.y][_PromptSys_CurPos.x]=_PromptSys_NowBackColor
156
157 i2++
158 _PromptSys_CurPos.x++
159 Loop
160
161 'Draw the text buffer added
162 hDC=GetDC(_PromptSys_hWnd)
163 DrawPromptBuffer(hDC,StartLine,_PromptSys_CurPos.y)
164 ReleaseDC(_PromptSys_hWnd,hDC)
165
166 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
167End Sub
168
169Function PromptProc(hWnd As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) As LRESULT
170 Dim hIMC As HIMC
171 Dim hDC As HDC
172 Dim ps As PAINTSTRUCT
173 Dim TempStr As String
174 Dim temporary[255] As Byte
175 Dim CompForm As COMPOSITIONFORM
176 Dim hGlobal As HGLOBAL
177
178 Select Case message
179 Case WM_CREATE
180 hDC=GetDC(hWnd)
181 _PromptSys_hBitmap=CreateCompatibleBitmap(hDC,_PromptSys_ScreenSize.cx,_PromptSys_ScreenSize.cy)
182 _PromptSys_hMemDC=CreateCompatibleDC(hDC)
183 SelectObject(_PromptSys_hMemDC,_PromptSys_hBitmap)
184
185 'Initialize for Win9x
186 Dim hOldBrush As HBRUSH
187 hOldBrush=SelectObject(_PromptSys_hMemDC,GetStockObject(BLACK_BRUSH))
188 PatBlt(_PromptSys_hMemDC,0,0,_PromptSys_ScreenSize.cx,_PromptSys_ScreenSize.cy,PATCOPY)
189 SelectObject(_PromptSys_hMemDC,hOldBrush)
190
191 Dim hOldFont As HFONT
192 Dim tm As TEXTMETRIC
193 hOldFont=SelectObject(_PromptSys_hMemDC,_PromptSys_hFont)
194 GetTextExtentPoint32(_PromptSys_hMemDC," ",1,_PromptSys_FontSize)
195 GetTextMetrics(_PromptSys_hMemDC,tm)
196 SelectObject(_PromptSys_hMemDC,hOldFont)
197 _PromptSys_FontSize.cy=tm.tmHeight
198
199 ReleaseDC(hWnd,hDC)
200 Case WM_PAINT
201 hDC=BeginPaint(hWnd,ps)
202 BitBlt(hDC,0,0,_PromptSys_ScreenSize.cx,_PromptSys_ScreenSize.cy,_PromptSys_hMemDC,0,0,SRCCOPY)
203 DrawPromptBuffer(hDC,-1,0)
204 EndPaint(hWnd,ps)
205
206 _PromptSys_bInitFinish=1
207 Case WM_SETFOCUS
208 If _PromptSys_InputLen<>-1 Then
209 hIMC=ImmGetContext(hWnd)
210 If hIMC Then
211 CompForm.dwStyle=CFS_POINT
212 CompForm.ptCurrentPos.x=_PromptSys_CurPos.x*_PromptSys_FontSize.cx
213 CompForm.ptCurrentPos.y=_PromptSys_CurPos.y*_PromptSys_FontSize.cy
214 ImmSetCompositionWindow(hIMC,CompForm)
215 ImmSetCompositionFont(hIMC,_PromptSys_LogFont)
216 End If
217 ImmReleaseContext(hWnd,hIMC)
218
219 CreateCaret(hWnd,NULL,9,6)
220 SetCaretPos(_PromptSys_CurPos.x*_PromptSys_FontSize.cx, _
221 (_PromptSys_CurPos.y+1)*_PromptSys_FontSize.cy-7)
222 ShowCaret(hWnd)
223 End If
224 Case WM_KILLFOCUS
225 HideCaret(hWnd)
226 DestroyCaret()
227 Case WM_KEYDOWN
228 If _PromptSys_InputLen=-1 Then
229 _PromptSys_KeyChar=wParam As Byte
230 End If
231 Case WM_CHAR
232 If _PromptSys_InputLen<>-1 Then
233 If wParam=VK_BACK Then
234 If _PromptSys_InputLen Then
235 _PromptSys_InputLen=_PromptSys_InputLen-1
236 _PromptSys_InputStr[_PromptSys_InputLen]=0
237
238 _PromptSys_CurPos.x=_PromptSys_CurPos.x-1
239 _PromptSys_Buffer[_PromptSys_CurPos.y][_PromptSys_CurPos.x]=0
240 End If
241 ElseIf wParam=VK_RETURN Then
242 _PromptSys_InputStr[_PromptSys_InputLen]=0
243 _PromptSys_InputLen=-1
244 TempStr=Ex"\r\n"
245 ElseIf wParam=&H16 Then
246 'Paste Command(Use Clippboard)
247 OpenClipboard(hWnd)
248 hGlobal=GetClipboardData(CF_TEXT)
249 If hGlobal=0 Then PromptProc=0:Exit Function
250 Dim pTemp=GlobalLock(hGlobal) As *Byte
251#ifdef UNICODE
252 Dim tempSizeW = MultiByteToWideChar(CP_ACP, 0, pTemp, -1, 0, 0) + 1
253 TempStr=ZeroString(tempSizeW)
254 MultiByteToWideChar(CP_ACP, 0, pTemp, -1, StrPtr(TempStr), tempSizeW)
255#else
256 TempStr=ZeroString(lstrlen(pTemp)+1)
257 lstrcpy(StrPtr(TempStr),pTemp)
258#endif
259 lstrcpy((VarPtr(_PromptSys_InputStr[0])+_PromptSys_InputLen) As *Byte,pTemp)
260 _PromptSys_InputLen=_PromptSys_InputLen+lstrlen(pTemp)
261
262 GlobalUnlock(hGlobal)
263 CloseClipboard()
264 Else
265 _PromptSys_InputStr[_PromptSys_InputLen]=wParam As Byte
266 _PromptSys_InputLen++
267
268 temporary[0]=wParam As Byte
269 temporary[1]=0
270 TempStr=temporary
271 End If
272
273 SendMessage(hWnd,WM_KILLFOCUS,0,0)
274 PRINT_ToPrompt(TempStr)
275 SendMessage(hWnd,WM_SETFOCUS,0,0)
276 End If
277 Case WM_DESTROY
278 DeleteDC(_PromptSys_hMemDC)
279 DeleteObject(_PromptSys_hBitmap)
280
281 PostQuitMessage(0)
282 Case Else
283 PromptProc=DefWindowProc(hWnd,message,wParam,lParam)
284 Exit Function
285 End Select
286 PromptProc=0
287End Function
288
289Function PromptMain(dwData As Long) As Long
290 Dim i As Long
291
292 'Allocate
293 For i=0 To 100
294 _PromptSys_Buffer[i]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255)
295 _PromptSys_TextColor[i]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR))
296 _PromptSys_BackColor[i]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR))
297 Next
298
299 'Current Colors initialize
300 _PromptSys_NowTextColor=RGB(255,255,255)
301 _PromptSys_NowBackColor=RGB(0,0,0)
302
303 'Setup
304 _PromptSys_ScreenSize.cx=GetSystemMetrics(SM_CXSCREEN)
305 _PromptSys_ScreenSize.cy=GetSystemMetrics(SM_CYSCREEN)
306
307 'LogFont initialize
308 _PromptSys_LogFont.lfHeight=-16
309 _PromptSys_LogFont.lfWidth=0
310 _PromptSys_LogFont.lfEscapement=0
311 _PromptSys_LogFont.lfOrientation=0
312 _PromptSys_LogFont.lfWeight=0
313 _PromptSys_LogFont.lfItalic=0
314 _PromptSys_LogFont.lfUnderline=0
315 _PromptSys_LogFont.lfStrikeOut=0
316 _PromptSys_LogFont.lfCharSet=SHIFTJIS_CHARSET
317 _PromptSys_LogFont.lfOutPrecision=OUT_DEFAULT_PRECIS
318 _PromptSys_LogFont.lfClipPrecision=CLIP_DEFAULT_PRECIS
319 _PromptSys_LogFont.lfQuality=DEFAULT_QUALITY
320 _PromptSys_LogFont.lfPitchAndFamily=FIXED_PITCH
321 lstrcpy(_PromptSys_LogFont.lfFaceName,"MS 明朝")
322
323 _PromptSys_hFont=CreateFontIndirect(_PromptSys_LogFont)
324
325 'Critical Section
326 InitializeCriticalSection(_PromptSys_SectionOfBufferAccess)
327
328 'Regist Prompt Class
329 Dim wcl As WNDCLASSEX
330 FillMemory(VarPtr(wcl),Len(wcl),0)
331 wcl.cbSize=Len(wcl)
332 wcl.hInstance=GetModuleHandle(0)
333 wcl.style=CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS
334 wcl.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION))
335 wcl.hIconSm=LoadIcon(NULL,MAKEINTRESOURCE(IDI_WINLOGO))
336 wcl.hCursor=LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW))
337 wcl.lpszClassName="PROMPT"
338 wcl.lpfnWndProc=AddressOf(PromptProc)
339 wcl.hbrBackground=GetStockObject(BLACK_BRUSH)
340 RegisterClassEx(wcl)
341
342 'Create Prompt Window
343 _PromptSys_hWnd=CreateWindowEx(WS_EX_CLIENTEDGE,"PROMPT","BASIC PROMPT",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,GetModuleHandle(0),0)
344 ShowWindow(_PromptSys_hWnd,SW_SHOW)
345 UpdateWindow(_PromptSys_hWnd)
346
347 Dim msg As MSG, iResult As Long
348 Do
349 iResult=GetMessage(msg,0,0,0)
350 If iResult=0 or iResult=-1 Then Exit Do
351 TranslateMessage(msg)
352 DispatchMessage(msg)
353 Loop
354
355 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
356 For i=0 to 100
357 HeapFree(_System_hProcessHeap,0,_PromptSys_Buffer[i])
358 HeapFree(_System_hProcessHeap,0,_PromptSys_TextColor[i])
359 HeapFree(_System_hProcessHeap,0,_PromptSys_BackColor[i])
360 Next
361
362 '強制的に終了する
363 ExitProcess(0)
364
365 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
366
367 DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
368
369 ExitProcess(0)
370End Function
371
372
373'----------------------
374' Prompt text Commands
375'----------------------
376
377Macro CLS()(num As Long)
378 Dim i As Long
379 Dim hOldBrush As HBRUSH
380
381 'When parameter was omitted, num is set to 1
382 If num=0 Then num=1
383
384 If num=1 or num=3 Then
385 'Clear the text screen
386 For i=0 To 100
387 FillMemory(_PromptSys_Buffer[i],255,0)
388 Next
389 _PromptSys_CurPos.x=0
390 _PromptSys_CurPos.y=0
391 End If
392
393 If num=2 or num=3 Then
394 'Clear the graphics screen
395 hOldBrush=SelectObject(_PromptSys_hMemDC,GetStockObject(BLACK_BRUSH))
396 PatBlt(_PromptSys_hMemDC,0,0,_PromptSys_ScreenSize.cx,_PromptSys_ScreenSize.cy,PATCOPY)
397 SelectObject(_PromptSys_hMemDC,hOldBrush)
398 End If
399
400 'Redraw
401 InvalidateRect(_PromptSys_hWnd,ByVal 0,0)
402End Macro
403
404Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
405 _PromptSys_NowTextColor=GetBasicColor(TextColorCode)
406 If BackColorCode=-1 Then
407 _PromptSys_NowBackColor=-1
408 Else
409 _PromptSys_NowBackColor=GetBasicColor(BackColorCode)
410 End If
411End Macro
412
413'---------- Defined in "command.sbp" ----------
414'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
415'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
416'----------------------------------------------
417Sub INPUT_FromPrompt(ShowStr As String)
418 Dim i As Long ,i2 As Long, i3 As Long
419 Dim buf As String
420
421*InputReStart
422
423 PRINT_ToPrompt(ShowStr)
424
425 'Input by keyboard
426 _PromptSys_InputLen=0
427 SendMessage(_PromptSys_hWnd,WM_SETFOCUS,0,0)
428 While _PromptSys_InputLen<>-1
429 Sleep(10)
430 Wend
431 SendMessage(_PromptSys_hWnd,WM_KILLFOCUS,0,0)
432
433 'Set value to variable
434 i=0
435 i2=0
436 buf=ZeroString(lstrlen(_PromptSys_InputStr))
437 While 1
438 i3=0
439 While 1
440 If _PromptSys_InputStr[i2]=Asc(",") Then
441 buf.Chars[i3]=0
442 Exit While
443 End If
444
445 buf.Chars[i3]=_PromptSys_InputStr[i2]
446
447 If _PromptSys_InputStr[i2]=0 Then Exit While
448
449 i2++
450 i3++
451 Wend
452
453 Select Case _System_InputDataType[i]
454 Case _System_Type_Double
455 SetDouble(_System_InputDataPtr[i],Val(buf))
456 Case _System_Type_Single
457 SetSingle(_System_InputDataPtr[i],Val(buf))
458 Case _System_Type_Int64,_System_Type_QWord
459 SetQWord(_System_InputDataPtr[i],Val(buf))
460 Case _System_Type_Long,_System_Type_DWord
461 SetDWord(_System_InputDataPtr[i],Val(buf))
462 Case _System_Type_Integer,_System_Type_Word
463 SetWord(_System_InputDataPtr[i],Val(buf))
464 Case _System_Type_SByte,_System_Type_Byte
465 SetByte(_System_InputDataPtr[i],Val(buf))
466 Case _System_Type_Char
467#ifdef UNICODE
468 SetWord(_System_InputDataPtr[i], buf[0])
469#else
470 SetByte(_System_InputDataPtr[i], buf[0])
471#endif
472 Case _System_Type_String
473 *INPUT_FromPrompt_Type_String
474 Dim pTempStr As *String
475 pTempStr=_System_InputDataPtr[i] As *String
476 pTempStr->ReSize(i3)
477 memcpy(pTempStr->Chars, buf.Chars, pTempStr->Length)
478 pTempStr->Chars[pTempStr->Length] = 0
479 Case 13
480 Goto *INPUT_FromPrompt_Type_String
481 End Select
482
483 i++
484 If _System_InputDataPtr[i]=0 and _PromptSys_InputStr[i2]=Asc(",") Then
485 PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
486 Goto *InputReStart
487 ElseIf _PromptSys_InputStr[i2]=0 Then
488 If _System_InputDataPtr[i]<>0 Then
489 PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
490 Goto *InputReStart
491 Else
492 Exit While
493 End If
494 End If
495
496 i2=i2+1
497 Wend
498End Sub
499
500Sub PRINTUSING_ToPrompt(UsingStr As String)
501 PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
502End Sub
503
504Macro LOCATE(x As Long, y As Long)
505 Dim i As Long, i2 As Long
506
507 If x<0 Then x=0
508 If y<0 Then y=0
509 If y>100 Then y=100
510
511 _PromptSys_CurPos.x=x
512 _PromptSys_CurPos.y=y
513
514 i=0
515 While _PromptSys_Buffer[y][i]
516 i++
517 Wend
518
519 If i<x Then
520 FillMemory(_PromptSys_Buffer[y]+i,x-i,Asc(" "))
521 For i2=i To x-1
522 _PromptSys_BackColor[y][i2]=-1
523 Next
524 End If
525End Macro
526
527
528'-------------------
529' Graphics Commands
530'-------------------
531
532Macro CIRCLE(x As Long , y As Long, radius As Long)(ColorCode As Long, StartPos As Double, EndPos As Double, Aspect As Double, bFill As Long, BrushColor As Long)
533 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
534 'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
535
536 Dim hDC As HDC
537 Dim hPen As HPEN, hOldPen As VoidPtr
538 Dim hBrush As HBRUSH, hOldBrush As VoidPtr
539 Dim radi2 As Long
540 Dim sw As Long
541 Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
542
543 hPen=CreatePen(PS_SOLID,1,GetBasicColor(ColorCode))
544 If bFill Then
545 hBrush=CreateSolidBrush(GetBasicColor(BrushColor))
546 Else
547 hBrush=GetStockObject(NULL_BRUSH)
548 End If
549
550 hDC=GetDC(_PromptSys_hWnd)
551 SelectObject(hDC,hPen)
552 SelectObject(hDC,hBrush)
553 hOldPen=SelectObject(_PromptSys_hMemDC,hPen)
554 hOldBrush=SelectObject(_PromptSys_hMemDC,hBrush)
555
556 If Aspect<1 Then
557 radi2=(CDbl(radius)*Aspect) As Long
558 Else
559 radi2=radius
560 radius=(CDbl(radius)/Aspect) As Long
561 End If
562
563 If StartPos=0 And EndPos=0 Then
564 Ellipse(hDC,x-radius,y-radi2,x+radius,y+radi2)
565 Ellipse(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2)
566 Else
567 StartPos *=StartPos
568 EndPos *=EndPos
569
570 If StartPos<0 Or EndPos<0 Then
571 sw=1
572 Else
573 sw=0
574 End If
575
576 StartPos = Abs(StartPos)
577 EndPos = Abs(EndPos)
578
579 If StartPos<=78.5 Then
580 i1=78
581 i2=Int(StartPos)
582 ElseIf StartPos<=235.5 Then
583 StartPos -= 78.5
584 i1=78-Int(StartPos)
585 i2=78
586 ElseIf StartPos<=392.5 Then
587 StartPos -= 235.5
588 i1=-78
589 i2=78-Int(StartPos)
590 ElseIf StartPos<=549.5 Then
591 StartPos -= 392.5
592 i1=-78+Int(StartPos)
593 i2=-78
594 ElseIf StartPos<=628 Then
595 StartPos -= 549.5
596 i1=78
597 i2=-78+Int(StartPos)
598 End If
599
600 If EndPos<=78.5 Then
601 i3=78
602 i4=Int(EndPos)
603 ElseIf EndPos<=235.5 Then
604 EndPos -= 78.5
605 i3=78-Int(EndPos)
606 i4=78
607 ElseIf EndPos<=392.5 Then
608 EndPos -= 235.5
609 i3=-78
610 i4=78-Int(EndPos)
611 ElseIf EndPos<=549.5 Then
612 EndPos -= 392.5
613 i3=-78+Int(EndPos)
614 i4=-78
615 ElseIf EndPos<=628 Then
616 EndPos -= 549.5
617 i3=78
618 i4=-78+Int(EndPos)
619 End If
620
621 If sw Then
622 Pie(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
623 Pie(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
624 Else
625 Arc(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
626 Arc(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
627 End If
628 End If
629
630 ReleaseDC(_PromptSys_hWnd,hDC)
631 SelectObject(_PromptSys_hMemDC,hOldPen)
632 SelectObject(_PromptSys_hMemDC,hOldBrush)
633 DeleteObject(hPen)
634 If bFill Then DeleteObject(hBrush)
635End Macro
636
637Macro LINE(sx As Long, sy As Long, bStep As Long, ex As Long, ey As Long)(ColorCode As Long, fType As Long, BrushColor As Long)
638 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
639 'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
640 Dim temp As Long
641
642 If sx=&H80000000 And sy=&H80000000 Then
643 sx=_PromptSys_GlobalPos.x
644 sy=_PromptSys_GlobalPos.y
645 End If
646
647 If bStep Then
648 ex += sx
649 ey += sy
650 Else
651 If fType Then
652 'ラインの場合(四角形でない場合)
653 If sx>ex Then
654 temp=ex
655 ex=sx
656 sx=temp
657 End If
658 If sy>ey Then
659 temp=ey
660 ey=sy
661 sy=temp
662 End If
663 End If
664 End If
665
666 Dim hDC As HDC
667 Dim hPen As HPEN, hOldPen As VoidPtr
668 Dim hBrush As HBRUSH, hOldBrush As VoidPtr
669
670 hDC=GetDC(_PromptSys_hWnd)
671 hPen=CreatePen(PS_SOLID,1,GetBasicColor(ColorCode))
672 If fType=2 Then
673 hBrush=CreateSolidBrush(GetBasicColor(BrushColor))
674 Else
675 hBrush=GetStockObject(NULL_BRUSH)
676 End If
677
678 SelectObject(hDC,hPen)
679 SelectObject(hDC,hBrush)
680 hOldPen=SelectObject(_PromptSys_hMemDC,hPen)
681 hOldBrush=SelectObject(_PromptSys_hMemDC,hBrush)
682
683 Select Case fType
684 Case 0
685 'line
686 MoveToEx(_PromptSys_hMemDC,sx,sy,ByVal NULL)
687 LineTo(_PromptSys_hMemDC,ex,ey)
688 SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode))
689 MoveToEx(hDC,sx,sy,ByVal NULL)
690 LineTo(hDC,ex,ey)
691 SetPixel(hDC,ex,ey,GetBasicColor(ColorCode))
692 Case Else
693 'Rectangle
694 Rectangle(hDC,sx,sy,ex+1,ey+1)
695 Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1)
696 End Select
697
698 ReleaseDC(_PromptSys_hWnd,hDC)
699 SelectObject(_PromptSys_hMemDC,hOldPen)
700 SelectObject(_PromptSys_hMemDC,hOldBrush)
701 DeleteObject(hPen)
702 If fType=2 Then DeleteObject(hBrush)
703
704 _PromptSys_GlobalPos.x=ex
705 _PromptSys_GlobalPos.y=ey
706End Macro
707
708Macro PSET(x As Long, y As Long)(ColorCode As Long)
709 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
710 'PSet (x,y),ColorCode
711
712 Dim hDC As HDC
713
714 hDC=GetDC(_PromptSys_hWnd)
715 SetPixel(hDC,x,y,GetBasicColor(ColorCode))
716 SetPixel(_PromptSys_hMemDC,x,y,GetBasicColor(ColorCode))
717 ReleaseDC(_PromptSys_hWnd,hDC)
718
719 _PromptSys_GlobalPos.x=x
720 _PromptSys_GlobalPos.y=y
721End Macro
722
723Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long)
724 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
725 'Paint (x,y),BrushColor,LineColor
726
727 Dim hDC As HDC
728 Dim hBrush As HBRUSH, hOldBrush As VoidPtr
729
730 hBrush=CreateSolidBrush(GetBasicColor(BrushColor))
731
732 hDC=GetDC(_PromptSys_hWnd)
733 SelectObject(hDC,hBrush)
734 hOldBrush=SelectObject(_PromptSys_hMemDC,hBrush)
735
736 ExtFloodFill(hDC,x,y,GetBasicColor(LineColor),FLOODFILLBORDER)
737 ExtFloodFill(_PromptSys_hMemDC,x,y,GetBasicColor(LineColor),FLOODFILLBORDER)
738
739 ReleaseDC(_PromptSys_hWnd,hDC)
740 SelectObject(_PromptSys_hMemDC,hOldBrush)
741 DeleteObject(hBrush)
742End Macro
743
744
745'-----------
746' Functions
747'-----------
748
749Function Inkey$() As String
750 If _PromptSys_KeyChar=0 Then
751 Inkey$=""
752 Else
753 Inkey$=Chr$(_PromptSys_KeyChar)
754 End If
755 _PromptSys_KeyChar=0
756End Function
757
758Function Input$(length As Long) As String
759 Dim i As Long
760
761 If length<=0 Then
762 Input$=""
763 Exit Function
764 End If
765
766 i=0
767 While 1
768 If _PromptSys_KeyChar Then
769 Input$=Input$+Chr$(_PromptSys_KeyChar)
770 _PromptSys_KeyChar=0
771 i++
772 If i>=length Then
773 Exit While
774 End If
775 End If
776 Sleep(1)
777 Wend
778End Function
779
780
781#endif '_INC_PROMPT
Note: See TracBrowser for help on using the repository browser.