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

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

Circle命令語の描画開始・終了位置の算出をSin/Cosで行うように変更

File size: 26.8 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
[685]246 ClearGraphicsScreen()
[1]247
[126]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
[411]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
[126]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)
[258]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)
[126]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
[121]304 End With
[126]305 ImmSetCompositionWindow(himc, CompForm)
[258]306
307 Dim lf As LOGFONT
308 GetObject(_PromptSys_hFont, Len(lf), lf)
309 ImmSetCompositionFont(himc, lf)
[126]310 End If
311 ImmReleaseContext(hwnd, himc)
[1]312
[126]313 CreateCaret(hwnd, 0, 9, 6)
[132]314 With _PromptSys_CurPos
315 SetCaretPos(_PromptSys_TextLine[.y].CharInfo[.x].StartPos, (.y + 1) * _PromptSys_FontSize.cy - 7)
316 End With
[126]317 ShowCaret(hwnd)
318 End If
319End Sub
[1]320
[126]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
[1]351 End If
[126]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
[142]357/*
[126]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
[121]363#ifdef UNICODE 'A版ウィンドウプロシージャ用
[126]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)
[119]368#else
[126]369 TempStr = ZeroString(lstrlen(pTemp) + 1)
370 lstrcpy(StrPtr(TempStr), pTemp)
[119]371#endif
[126]372 memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), TempStr.Chars, SizeOf (Char) * TempStr.Length)
373 _PromptSys_InputLen += TempStr.Length
[1]374
[126]375 GlobalUnlock(hGlobal)
376 CloseClipboard()
[142]377*/
[126]378 Else
[272]379 Dim t = wParam As TCHAR
380 TempStr = New String(VarPtr(t), 1)
381 _PromptSys_InputStr[_PromptSys_InputLen] = TempStr[0]
[126]382 _PromptSys_InputLen++
383 End If
[1]384
[126]385 SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
[258]386 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(TempStr)
[126]387 SendMessage(hwnd, WM_SETFOCUS, 0, 0)
388 End If
389End Sub
[1]390
[142]391Function _PromptWnd_GetCompositionStringW(himc As HIMC, ByRef rpsz As PWSTR) As Long
392 Dim size = ImmGetCompositionStringW(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
[411]393 rpsz = GC_malloc(size) As PWSTR
[142]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はバイト単位
[411]403 rpsz = GC_malloc(size) As PSTR
[142]404 If rpsz = 0 Then
405 'Debug
406 Return 0
407 End If
408 Return ImmGetCompositionStringA(himc, GCS_RESULTSTR, rpsz, size)
409End Function
410
[126]411Function _PromptWnd_OnImeCompostion(hwnd As HWND, wp As WPARAM, lp As LPARAM) As LRESULT
[125]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
[272]418 Dim tempStr = Nothing As String
[497]419 Dim str As *Char
420#ifdef UNICODE
[258]421 Dim osver = System.Environment.OSVersion
422 With osver
[497]423 ' GetCompositionStringW is not implimented in Windows 95
[258]424 If .Version.Major = 4 And .Version.Minor = 0 And .Platform = System.PlatformID.Win32Windows Then
[142]425 Dim strA As PCSTR
426 Dim sizeA = _PromptWnd_GetCompositionStringA(himc, strA)
[272]427 tempStr = New String(strA, sizeA As Long)
[142]428 Else
429 Dim size = _PromptWnd_GetCompositionStringW(himc, str)
[272]430 tempStr = New String(str, (size \ SizeOf (WCHAR)) As Long)
[142]431 End If
432 End With
[497]433#else
434 Dim size = _PromptWnd_GetCompositionStringA(himc, str)
435 tempStr = New String(str, size As Long)
[142]436#endif
[125]437 ImmReleaseContext(hwnd, himc)
438
[272]439 ActiveBasic.Strings.ChrCopy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), tempStr.StrPtr, tempStr.Length As SIZE_T)
[142]440 _PromptSys_InputLen += tempStr.Length
[125]441
[258]442 SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
443 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(tempStr)
[125]444 SendMessage(hwnd, WM_SETFOCUS, 0, 0)
445
[126]446 _PromptWnd_OnImeCompostion = 0
[125]447 Else
[126]448 _PromptWnd_OnImeCompostion = DefWindowProc(hwnd, WM_IME_COMPOSITION, wp, lp)
[125]449 End If
450End Function
451
[537]452Function PromptMain(data As VoidPtr) As DWord
[1]453 Dim i As Long
454 'Allocate
[126]455 For i = 0 To 100
456 With _PromptSys_TextLine[i]
457 .Length = 0
[497]458 .Text = _System_calloc(SizeOf (Char) * 255)
[126]459 .CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
460 End With
[1]461 Next
462
463 'Current Colors initialize
[126]464 _PromptSys_NowTextColor = RGB(255, 255, 255)
465 _PromptSys_NowBackColor = RGB(0, 0, 0)
[1]466
467 'Setup
[125]468 With _PromptSys_ScreenSize
469 .cx = GetSystemMetrics(SM_CXSCREEN)
470 .cy = GetSystemMetrics(SM_CYSCREEN)
471 End With
[1]472
473 'Critical Section
474 InitializeCriticalSection(_PromptSys_SectionOfBufferAccess)
475
476 'Regist Prompt Class
477 Dim wcl As WNDCLASSEX
[123]478 ZeroMemory(VarPtr(wcl), Len(wcl))
479 With wcl
480 .cbSize = Len(wcl)
481 .hInstance = GetModuleHandle(0)
[126]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
[258]486 .lpszClassName = ToTCStr("PROMPT")
[123]487 .lpfnWndProc = AddressOf(PromptProc)
488 .hbrBackground = GetStockObject(BLACK_BRUSH)
489 End With
[121]490 Dim atom = RegisterClassEx(wcl)
[1]491
492 'Create Prompt Window
[258]493 _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As LPCTSTR, ToTCStr("BASIC PROMPT"), _
[192]494 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
[125]495 0, 0, wcl.hInstance, 0)
[123]496 ShowWindow(_PromptSys_hWnd, SW_SHOW)
[119]497 UpdateWindow(_PromptSys_hWnd)
[127]498 SetEvent(_PromptSys_hInitFinish)
[123]499 Dim msg As MSG
[1]500 Do
[123]501 Dim iResult = GetMessage(msg, 0, 0, 0)
[258]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
[1]508 TranslateMessage(msg)
509 DispatchMessage(msg)
510 Loop
511
[121]512 '強制的に終了する
[258]513 End
[121]514
[1]515 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
[126]516
517 For i = 0 to 100
518 _System_free(_PromptSys_TextLine[i].Text)
519 _System_free(_PromptSys_TextLine[i].CharInfo)
[121]520 Next
[17]521
[1]522 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
523
524 DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
525
[258]526 End
[1]527End Function
528
[685]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
[258]541'Prompt text command functoins
[1]542
[258]543Sub Cls(n As Long)
[1]544 Dim i As Long
545
546 'When parameter was omitted, num is set to 1
[258]547 If n = 0 Then n = 1
[1]548
[258]549 If n = 1 Or n = 3 Then
[1]550 'Clear the text screen
[123]551 For i = 0 To 100
[126]552 With _PromptSys_TextLine[i]
[497]553 .Text[0] = 0 '_System_FillChar(_PromptSys_TextLine[i].Text, -1 As Char, 0)
[126]554 .Length = 0
555 End With
[1]556 Next
[123]557 With _PromptSys_CurPos
558 .x = 0
559 .y = 0
560 End With
[1]561 End If
562
[258]563 If n = 2 Or n = 3 Then
[1]564 'Clear the graphics screen
[685]565 ClearGraphicsScreen()
[1]566 End If
567
568 'Redraw
[126]569 InvalidateRect(_PromptSys_hWnd, ByVal 0, 0)
[258]570End Sub
[1]571
[258]572Sub Color(textColorCode As Long, backColorCode As Long)
573 _PromptSys_NowTextColor = GetBasicColor(textColorCode)
574 If backColorCode = -1 Then
[126]575 _PromptSys_NowBackColor = -1
[1]576 Else
[258]577 _PromptSys_NowBackColor = GetBasicColor(backColorCode)
[1]578 End If
[258]579End Sub
[1]580
[258]581Sub INPUT_FromPrompt(showStr As String)
[1]582*InputReStart
583
[258]584 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(showStr)
[1]585
586 'Input by keyboard
[126]587 _PromptSys_InputLen = 0
588 SendMessage(_PromptSys_hWnd, WM_SETFOCUS, 0, 0)
589 While _PromptSys_InputLen <> -1
[1]590 Sleep(10)
591 Wend
[126]592 SendMessage(_PromptSys_hWnd, WM_KILLFOCUS, 0, 0)
[1]593
594 'Set value to variable
[497]595 Const comma = &h2c As Char 'Asc(",")
[272]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
[258]600 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
[1]601 Goto *InputReStart
602 End If
[635]603 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], broken.Item[i])
[272]604 Next
[1]605
[272]606 If _System_InputDataPtr[i]<>0 Then
607 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
608 Goto *InputReStart
609 End If
[1]610End Sub
611
[258]612Sub Locate(x As Long, y As Long)
[126]613 If x < 0 Then x = 0
614 If y < 0 Then y = 0
615 If y > 100 Then y = 100
[123]616 With _PromptSys_CurPos
617 .x = x
618 .y = y
619 End With
[1]620
[126]621 Dim i = _PromptSys_TextLine[y].Length
[123]622 If i < x Then
[497]623 ActiveBasic.Strings.ChrFill(VarPtr(_PromptSys_TextLine[y].Text[i]), x - i, &h20 As Char) 'Asc(" ")
[126]624 Dim i2 As Long
625 For i2 = i To ELM(x)
626 _PromptSys_TextLine[y].CharInfo[i2].BackColor = -1
[1]627 Next
[126]628 _PromptSys_TextLine[y].Length = x
[1]629 End If
[258]630End Sub
[1]631
[258]632'Prompt graphic command functions
[1]633
[688]634Sub 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)
635 Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
[126]636 Dim hBrush As HBRUSH
[1]637 If bFill Then
[126]638 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
[1]639 Else
[126]640 hBrush = GetStockObject(NULL_BRUSH)
[1]641 End If
642
[688]643 Dim hdc = GetDC(_PromptSys_hWnd)
644 Dim hOldPenDC = SelectObject(hdc, hPen)
645 Dim hOldBrushDC = SelectObject(hdc, hBrush)
[126]646 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
647 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
[1]648
[688]649 Dim yRadius As Double
650 Dim xRadius As Double
651 If Aspect = 1 Then
652 yRadius = radius
653 xRadius = radius
654 ElseIf Aspect < 1 Then
655 yRadius = radius * Aspect
656 xRadius = radius
[1]657 Else
[688]658 yRadius = radius
659 xRadius = radius / Aspect
[1]660 End If
661
[688]662 Dim x1 = (x - xRadius) As Long
663 Dim x2 = (x + xRadius) As Long
664 Dim y1 = (y - yRadius) As Long
665 Dim y2 = (y + yRadius) As Long
666
667 If StartPos = 0 And EndPos = 0 Then
668 Ellipse(hdc, x1, y1, x2, y2)
669 Ellipse(_PromptSys_hMemDC, x1, y1, x2, y2)
[1]670 Else
[688]671 Dim isPie As Boolean
672 If StartPos < 0 Or EndPos < 0 Then
673 isPie = True
[684]674 StartPos = Math.Abs(StartPos)
675 EndPos = Math.Abs(EndPos)
[1]676 Else
[688]677 isPie = False
[1]678 End If
679
[688]680 Dim scaleRadial = (x + y) * 0.5
681 Dim startX = (x + ActiveBasic.Math.Cos(StartPos) * scaleRadial) As Long
682 Dim startY = (y - ActiveBasic.Math.Sin(StartPos) * scaleRadial) As Long
683 Dim endX = (x + ActiveBasic.Math.Cos(EndPos) * scaleRadial) As Long
684 Dim endY = (y - ActiveBasic.Math.Sin(EndPos) * scaleRadial) As Long
[1]685
[688]686 If isPie Then
687 Pie(hdc, x1, y1, x2, y2, startX, startY, endX, endY)
688 Pie(_PromptSys_hMemDC, x1, y1, x2, y2, startX, startY, endX, endY)
[1]689 Else
[688]690 Arc(hdc, x1, y1, x2, y2, startX, startY, endX, endY)
691 Arc(_PromptSys_hMemDC, x1, y1, x2, y2, startX, startY, endX, endY)
[1]692 End If
693 End If
694
[688]695 SelectObject(hdc, hOldPenDC)
696 SelectObject(hdc, hOldBrushDC)
697 ReleaseDC(_PromptSys_hWnd, hdc)
[126]698 SelectObject(_PromptSys_hMemDC, hOldPen)
699 SelectObject(_PromptSys_hMemDC, hOldBrush)
[1]700 DeleteObject(hPen)
701 If bFill Then DeleteObject(hBrush)
[258]702End Sub
[1]703
[258]704Sub 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]705 Dim temp As Long
706
[126]707 If sx = &H80000000 And sy = &H80000000 Then
708 With _PromptSys_GlobalPos
709 sx = .x
710 sy = .y
711 End With
[1]712 End If
713
714 If bStep Then
[90]715 ex += sx
716 ey += sy
[1]717 Else
718 If fType Then
719 'ラインの場合(四角形でない場合)
720 If sx>ex Then
721 temp=ex
722 ex=sx
723 sx=temp
724 End If
725 If sy>ey Then
726 temp=ey
727 ey=sy
728 sy=temp
729 End If
730 End If
731 End If
732
[258]733 Dim hdc = GetDC(_PromptSys_hWnd)
[121]734 Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
735 Dim hBrush As HBRUSH
[1]736 If fType=2 Then
[126]737 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
[1]738 Else
[126]739 hBrush = GetStockObject(NULL_BRUSH)
[1]740 End If
741
[258]742 SelectObject(hdc, hPen)
743 SelectObject(hdc, hBrush)
[126]744 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
745 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
[1]746
747 Select Case fType
748 Case 0
749 'line
750 MoveToEx(_PromptSys_hMemDC,sx,sy,ByVal NULL)
751 LineTo(_PromptSys_hMemDC,ex,ey)
752 SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode))
[258]753 MoveToEx(hdc,sx,sy,ByVal NULL)
754 LineTo(hdc,ex,ey)
755 SetPixel(hdc,ex,ey,GetBasicColor(ColorCode))
[1]756 Case Else
757 'Rectangle
[258]758 Rectangle(hdc,sx,sy,ex+1,ey+1)
[1]759 Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1)
760 End Select
761
[258]762 ReleaseDC(_PromptSys_hWnd,hdc)
[1]763 SelectObject(_PromptSys_hMemDC,hOldPen)
764 SelectObject(_PromptSys_hMemDC,hOldBrush)
765 DeleteObject(hPen)
[126]766 If fType = 2 Then DeleteObject(hBrush)
767 With _PromptSys_GlobalPos
768 .x = ex
769 .y = ey
770 End With
[258]771End Sub
[1]772
[258]773Sub PSet(x As Long, y As Long, ColorCode As Long)
774 Dim hdc = GetDC(_PromptSys_hWnd)
775 SetPixel(hdc, x, y, GetBasicColor(ColorCode))
[126]776 SetPixel(_PromptSys_hMemDC, x, y, GetBasicColor(ColorCode))
[258]777 ReleaseDC(_PromptSys_hWnd, hdc)
[126]778 With _PromptSys_GlobalPos
779 .x = x
780 .y = y
781 End With
[258]782End Sub
[1]783
[258]784Sub Paint(x As Long, y As Long, BrushColor As Long, LineColor As Long)
785 Dim hbr = CreateSolidBrush(GetBasicColor(BrushColor))
[1]786
[258]787 Dim hdc = GetDC(_PromptSys_hWnd)
788 Dim hbrOld = SelectObject(_PromptSys_hMemDC, hbr)
789 Dim hbrOldWndDC = SelectObject(hdc, hbr)
[1]790
[258]791 ExtFloodFill(hdc, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
[126]792 ExtFloodFill(_PromptSys_hMemDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
[1]793
[258]794 ReleaseDC(_PromptSys_hWnd, hdc)
795 SelectObject(_PromptSys_hMemDC, hbrOld)
796 SelectObject(hdc, hbrOldWndDC)
797 DeleteObject(hbr)
798End Sub
[1]799
800Function Inkey$() As String
801 If _PromptSys_KeyChar=0 Then
802 Inkey$=""
803 Else
804 Inkey$=Chr$(_PromptSys_KeyChar)
805 End If
806 _PromptSys_KeyChar=0
807End Function
808
809Function Input$(length As Long) As String
[258]810 Dim i = 0 As Long
[1]811
812 If length<=0 Then
813 Input$=""
814 Exit Function
815 End If
816
817 While 1
818 If _PromptSys_KeyChar Then
819 Input$=Input$+Chr$(_PromptSys_KeyChar)
820 _PromptSys_KeyChar=0
[90]821 i++
[126]822 If i >= length Then
[1]823 Exit While
824 End If
825 End If
826 Sleep(1)
827 Wend
828End Function
829
[258]830End Namespace 'Detail
[1]831
[258]832Function OwnerWnd() As HWND
833 Return Detail._PromptSys_hWnd
834End Function
835
836End Namespace 'Prompt
837End Namespace 'ActiveBasic
838
839'----------------------
840' Prompt text Commands
841'----------------------
842
843Sub PRINT_ToPrompt(s As String)
844 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(s)
845End Sub
846
847Macro CLS()(num As Long)
848 ActiveBasic.Prompt.Detail.Cls(num)
849End Macro
850
851Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
852 ActiveBasic.Prompt.Detail.Color(TextColorCode, BackColorCode)
853End Macro
854
855'---------- Defined in "command.sbp" ----------
856'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
857'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
858'----------------------------------------------
859Sub INPUT_FromPrompt(ShowStr As String)
860 ActiveBasic.Prompt.Detail.INPUT_FromPrompt(ShowStr)
861End Sub
862
[288]863/* TODO: _System_GetUsingFormatを用意して実装する
[258]864Sub PRINTUSING_ToPrompt(UsingStr As String)
865 ActiveBasic.Prompt.Detail.PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
866End Sub
[288]867*/
[258]868
[684]869Macro LOCATE(x As Double, y As Double)
870 ActiveBasic.Prompt.Detail.Locate(x As Long, y As Long)
[258]871End Macro
872
873
874'-------------------
875' Graphics Commands
876'-------------------
877
[684]878Macro 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]879 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
880 'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
[688]881 ActiveBasic.Prompt.Detail.Circle(x, y, radius, ColorCode, StartPos, EndPos, Aspect, bFill, BrushColor)
[258]882End Macro
883
[684]884Macro 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]885 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
886 'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
[684]887 ActiveBasic.Prompt.Detail.Line(sx As Long, sy As Long, bStep, ex As Long, ey As Long, ColorCode, fType, BrushColor)
[258]888End Macro
889
[684]890Macro PSET(x As Double, y As Double)(ColorCode As Long)
[258]891 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
892 'PSet (x,y),ColorCode
[684]893 ActiveBasic.Prompt.Detail.PSet(x As Long, y As Long, ColorCode)
[258]894End Macro
895
[684]896Macro PAINT(x As Double, y As Double, BrushColor As Long)(ByVal LineColor As Long)
[258]897 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
898 'Paint (x,y),BrushColor,LineColor
[684]899 ActiveBasic.Prompt.Detail.Paint(x As Long, y As Long, BrushColor, LineColor)
[258]900End Macro
901
902
903'-----------
904' Functions
905'-----------
906
907Function Inkey$() As String
908 Return ActiveBasic.Prompt.Detail.Inkey$()
909End Function
910
911Function Input$(length As Long) As String
912 Return ActiveBasic.Prompt.Detail.Input$(length)
913End Function
914
915ActiveBasic.Prompt.Detail._PromptSys_Initialize()
916
917#endif '_INC_PROMPT
Note: See TracBrowser for help on using the repository browser.