source: Include/basic/prompt.sbp@ 125

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

#51完了

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