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

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

Cls及び初期化時の塗り潰しをExtTextOutで行うよう変更

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