source: trunk/ab5.0/ablib/src/basic/prompt.sbp@ 684

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

Circle, Sqrtを壊していたので修正。プロンプト画面の描画ステートメントの座標の引数をDoubleへ変更。

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