source: Include/basic/prompt.sbp@ 132

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

String型の自身を変更するメソッドを、戻り値で返すように変更。
併せて文字列比較を自前の関数で行うように変更。
プロンプトのキャレットの位置計算が正しくなかったバグを修正。

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