source: Include/basic/prompt.sbp @ 126

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

#68修正完了

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