source: Include/basic/prompt.sbp@ 121

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

#51対応

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