source: Include/basic/prompt.sbp@ 139

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

#55#73#75とりあえず完了

File size: 23.0 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 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 ImmSetCompositionFont(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 lstrcpy(.lfFaceName, "MS 明朝")
410 End With
411
412 _PromptSys_hFont = CreateFontIndirect(_PromptSys_LogFont)
413
414 'Critical Section
415 InitializeCriticalSection(_PromptSys_SectionOfBufferAccess)
416
417 'Regist Prompt Class
418 Dim wcl As WNDCLASSEX
419 ZeroMemory(VarPtr(wcl), Len(wcl))
420 With wcl
421 .cbSize = Len(wcl)
422 .hInstance = GetModuleHandle(0)
423 .style = CS_HREDRAW Or CS_VREDRAW' or CS_DBLCLKS
424 .hIcon = LoadImage(0, MAKEINTRESOURCE(IDI_APPLICATION), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HICON
425 .hIconSm = LoadImage(0, MAKEINTRESOURCE(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HICON
426 .hCursor = LoadImage(0, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HCURSOR
427 .lpszClassName = "PROMPT"
428 .lpfnWndProc = AddressOf(PromptProc)
429 .hbrBackground = GetStockObject(BLACK_BRUSH)
430 End With
431 Dim atom = RegisterClassEx(wcl)
432
433 'Create Prompt Window
434 _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As PCTSTR, "BASIC PROMPT",
435 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
436 0, 0, wcl.hInstance, 0)
437 ShowWindow(_PromptSys_hWnd, SW_SHOW)
438 UpdateWindow(_PromptSys_hWnd)
439 SetEvent(_PromptSys_hInitFinish)
440 Dim msg As MSG
441 Do
442 Dim iResult = GetMessage(msg, 0, 0, 0)
443 If iResult = 0 Or iResult = -1 Then Exit Do
444 TranslateMessage(msg)
445 DispatchMessage(msg)
446 Loop
447
448 '強制的に終了する
449 ExitProcess(0)
450
451 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
452
453 For i = 0 to 100
454 _System_free(_PromptSys_TextLine[i].Text)
455 _System_free(_PromptSys_TextLine[i].CharInfo)
456 Next
457
458 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
459
460 DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
461
462 ExitProcess(0)
463End Function
464
465
466'----------------------
467' Prompt text Commands
468'----------------------
469
470Macro CLS()(num As Long)
471 Dim i As Long
472
473 'When parameter was omitted, num is set to 1
474 If num = 0 Then num = 1
475
476 If num = 1 Or num = 3 Then
477 'Clear the text screen
478 For i = 0 To 100
479 With _PromptSys_TextLine[i]
480 .Text[0] = 0 '_System_FillChar(_PromptSys_TextLine[i].Text, -1 As Char, 0)
481 .Length = 0
482 End With
483 Next
484 With _PromptSys_CurPos
485 .x = 0
486 .y = 0
487 End With
488 End If
489
490 If num = 2 Or num = 3 Then
491 'Clear the graphics screen
492 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, GetStockObject(BLACK_BRUSH))
493 With _PromptSys_ScreenSize
494 PatBlt(_PromptSys_hMemDC, 0, 0, .cx, .cy, PATCOPY)
495 End With
496 SelectObject(_PromptSys_hMemDC, hOldBrush)
497 End If
498
499 'Redraw
500 InvalidateRect(_PromptSys_hWnd, ByVal 0, 0)
501End Macro
502
503Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
504 _PromptSys_NowTextColor = GetBasicColor(TextColorCode)
505 If BackColorCode = -1 Then
506 _PromptSys_NowBackColor = -1
507 Else
508 _PromptSys_NowBackColor = GetBasicColor(BackColorCode)
509 End If
510End Macro
511
512'---------- Defined in "command.sbp" ----------
513'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
514'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
515'----------------------------------------------
516Sub INPUT_FromPrompt(ShowStr As String)
517 Dim i As Long ,i2 As Long, i3 As Long
518 Dim buf As String
519
520*InputReStart
521
522 PRINT_ToPrompt(ShowStr)
523
524 'Input by keyboard
525 _PromptSys_InputLen = 0
526 SendMessage(_PromptSys_hWnd, WM_SETFOCUS, 0, 0)
527 While _PromptSys_InputLen <> -1
528 Sleep(10)
529 Wend
530 SendMessage(_PromptSys_hWnd, WM_KILLFOCUS, 0, 0)
531
532 'Set value to variable
533 i = 0
534 i2 = 0
535 buf = ZeroString(lstrlen(_PromptSys_InputStr))
536 While 1
537 i3 = 0
538 While 1
539 If _PromptSys_InputStr[i2] = &h2c Then
540 buf.Chars[i3] = 0
541 Exit While
542 End If
543
544 buf.Chars[i3] = _PromptSys_InputStr[i2]
545
546 If _PromptSys_InputStr[i2] = 0 Then Exit While
547
548 i2++
549 i3++
550 Wend
551
552 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], buf, i3)
553
554 i++
555 If _System_InputDataPtr[i] = 0 and _PromptSys_InputStr[i2] = &h2c Then 'Asc(",")
556 PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
557 Goto *InputReStart
558 ElseIf _PromptSys_InputStr[i2] = 0 Then
559 If _System_InputDataPtr[i]<>0 Then
560 PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
561 Goto *InputReStart
562 Else
563 Exit While
564 End If
565 End If
566
567 i2++
568 Wend
569End Sub
570
571Sub PRINTUSING_ToPrompt(UsingStr As String)
572 PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
573End Sub
574
575Macro LOCATE(x As Long, y As Long)
576 If x < 0 Then x = 0
577 If y < 0 Then y = 0
578 If y > 100 Then y = 100
579 With _PromptSys_CurPos
580 .x = x
581 .y = y
582 End With
583
584 Dim i = _PromptSys_TextLine[y].Length
585 If i < x Then
586 _System_FillChar(VarPtr(_PromptSys_TextLine[y].Text[i]), x - i, &h20) 'Asc(" ")
587 Dim i2 As Long
588 For i2 = i To ELM(x)
589 _PromptSys_TextLine[y].CharInfo[i2].BackColor = -1
590 Next
591 _PromptSys_TextLine[y].Length = x
592 End If
593End Macro
594
595
596'-------------------
597' Graphics Commands
598'-------------------
599
600Macro 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)
601 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
602 'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
603
604 Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
605
606 Dim hPen = CreatePen(PS_SOLID,1,GetBasicColor(ColorCode))
607 Dim hBrush As HBRUSH
608 If bFill Then
609 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
610 Else
611 hBrush = GetStockObject(NULL_BRUSH)
612 End If
613
614 Dim hDC = GetDC(_PromptSys_hWnd)
615 Dim hOldPenDC = SelectObject(hDC, hPen)
616 Dim hOldBrushDC = SelectObject(hDC, hBrush)
617 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
618 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
619
620 Dim radi2 As Long
621 If Aspect<1 Then
622 radi2=(CDbl(radius)*Aspect) As Long
623 Else
624 radi2=radius
625 radius=(CDbl(radius)/Aspect) As Long
626 End If
627
628 If StartPos=0 And EndPos=0 Then
629 Ellipse(hDC,x-radius,y-radi2,x+radius,y+radi2)
630 Ellipse(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2)
631 Else
632 Dim sw As Long
633 StartPos *=StartPos
634 EndPos *=EndPos
635
636 If StartPos<0 Or EndPos<0 Then
637 sw=1
638 Else
639 sw=0
640 End If
641
642 StartPos = Abs(StartPos)
643 EndPos = Abs(EndPos)
644
645 If StartPos<=78.5 Then
646 i1=78
647 i2=Int(StartPos)
648 ElseIf StartPos<=235.5 Then
649 StartPos -= 78.5
650 i1=78-Int(StartPos)
651 i2=78
652 ElseIf StartPos<=392.5 Then
653 StartPos -= 235.5
654 i1=-78
655 i2=78-Int(StartPos)
656 ElseIf StartPos<=549.5 Then
657 StartPos -= 392.5
658 i1=-78+Int(StartPos)
659 i2=-78
660 ElseIf StartPos<=628 Then
661 StartPos -= 549.5
662 i1=78
663 i2=-78+Int(StartPos)
664 End If
665
666 If EndPos<=78.5 Then
667 i3=78
668 i4=Int(EndPos)
669 ElseIf EndPos<=235.5 Then
670 EndPos -= 78.5
671 i3=78-Int(EndPos)
672 i4=78
673 ElseIf EndPos<=392.5 Then
674 EndPos -= 235.5
675 i3=-78
676 i4=78-Int(EndPos)
677 ElseIf EndPos<=549.5 Then
678 EndPos -= 392.5
679 i3=-78+Int(EndPos)
680 i4=-78
681 ElseIf EndPos<=628 Then
682 EndPos -= 549.5
683 i3=78
684 i4=-78+Int(EndPos)
685 End If
686
687 If sw Then
688 Pie(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
689 Pie(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
690 Else
691 Arc(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
692 Arc(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
693 End If
694 End If
695
696 SelectObject(hDC, hOldPenDC)
697 SelectObject(hDC, hOldBrushDC)
698 ReleaseDC(_PromptSys_hWnd, hDC)
699 SelectObject(_PromptSys_hMemDC, hOldPen)
700 SelectObject(_PromptSys_hMemDC, hOldBrush)
701 DeleteObject(hPen)
702 If bFill Then DeleteObject(hBrush)
703End Macro
704
705Macro 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)
706 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
707 'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
708 Dim temp As Long
709
710 If sx = &H80000000 And sy = &H80000000 Then
711 With _PromptSys_GlobalPos
712 sx = .x
713 sy = .y
714 End With
715 End If
716
717 If bStep Then
718 ex += sx
719 ey += sy
720 Else
721 If fType Then
722 'ラインの場合(四角形でない場合)
723 If sx>ex Then
724 temp=ex
725 ex=sx
726 sx=temp
727 End If
728 If sy>ey Then
729 temp=ey
730 ey=sy
731 sy=temp
732 End If
733 End If
734 End If
735
736 Dim hDC = GetDC(_PromptSys_hWnd)
737 Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
738 Dim hBrush As HBRUSH
739 If fType=2 Then
740 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
741 Else
742 hBrush = GetStockObject(NULL_BRUSH)
743 End If
744
745 SelectObject(hDC, hPen)
746 SelectObject(hDC, hBrush)
747 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
748 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
749
750 Select Case fType
751 Case 0
752 'line
753 MoveToEx(_PromptSys_hMemDC,sx,sy,ByVal NULL)
754 LineTo(_PromptSys_hMemDC,ex,ey)
755 SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode))
756 MoveToEx(hDC,sx,sy,ByVal NULL)
757 LineTo(hDC,ex,ey)
758 SetPixel(hDC,ex,ey,GetBasicColor(ColorCode))
759 Case Else
760 'Rectangle
761 Rectangle(hDC,sx,sy,ex+1,ey+1)
762 Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1)
763 End Select
764
765 ReleaseDC(_PromptSys_hWnd,hDC)
766 SelectObject(_PromptSys_hMemDC,hOldPen)
767 SelectObject(_PromptSys_hMemDC,hOldBrush)
768 DeleteObject(hPen)
769 If fType = 2 Then DeleteObject(hBrush)
770 With _PromptSys_GlobalPos
771 .x = ex
772 .y = ey
773 End With
774End Macro
775
776Macro PSET(x As Long, y As Long)(ColorCode As Long)
777 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
778 'PSet (x,y),ColorCode
779
780 Dim hDC = GetDC(_PromptSys_hWnd)
781 SetPixel(hDC, x, y, GetBasicColor(ColorCode))
782 SetPixel(_PromptSys_hMemDC, x, y, GetBasicColor(ColorCode))
783 ReleaseDC(_PromptSys_hWnd, hDC)
784 With _PromptSys_GlobalPos
785 .x = x
786 .y = y
787 End With
788End Macro
789
790Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long)
791 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
792 'Paint (x,y),BrushColor,LineColor
793
794 Dim hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
795
796 Dim hDC = GetDC(_PromptSys_hWnd)
797 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
798 Dim hOldBrushWndDC = SelectObject(hDC, hBrush)
799
800 ExtFloodFill(hDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
801 ExtFloodFill(_PromptSys_hMemDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
802
803 ReleaseDC(_PromptSys_hWnd, hDC)
804 SelectObject(_PromptSys_hMemDC, hOldBrush)
805 SelectObject(hDC, hOldBrushWndDC)
806 DeleteObject(hBrush)
807End Macro
808
809
810'-----------
811' Functions
812'-----------
813
814Function Inkey$() As String
815 If _PromptSys_KeyChar=0 Then
816 Inkey$=""
817 Else
818 Inkey$=Chr$(_PromptSys_KeyChar)
819 End If
820 _PromptSys_KeyChar=0
821End Function
822
823Function Input$(length As Long) As String
824 Dim i As Long
825
826 If length<=0 Then
827 Input$=""
828 Exit Function
829 End If
830
831 i=0
832 While 1
833 If _PromptSys_KeyChar Then
834 Input$=Input$+Chr$(_PromptSys_KeyChar)
835 _PromptSys_KeyChar=0
836 i++
837 If i >= length Then
838 Exit While
839 End If
840 End If
841 Sleep(1)
842 Wend
843End Function
844
845
846#endif '_INC_PROMPT
Note: See TracBrowser for help on using the repository browser.