1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 12:40:36 +00:00

Replaces _TOGGLE_(KEY)LOCK with _(KEY)LOCK ON/OFF/_TOGGLE. Also:

- Changes CFont to sub__consolefont and func_CInp to func_cinp, in alignment with the rest of libqb/qbx.
- Adds stubs to all new console functionality, so we can still ship for other OSes with no bigger issues.
- Adds new keywords to syntax highlighter.
This commit is contained in:
FellippeHeitor 2020-01-02 19:55:58 -03:00
parent d7f77cd2af
commit 7c9eafbadb
4 changed files with 190 additions and 130 deletions

View file

@ -24,13 +24,12 @@
int32 disableEvents=0;
#ifdef QB64_WINDOWS //Global console vvalues
static int32 consolekey;
static int32 consolemousex;
static int32 consolemousey;
static int32 consolebutton;
int32 func__getconsoleinput(); //declare here, so we can use with SLEEP and END commands
#endif
//Global console vvalues
static int32 consolekey;
static int32 consolemousex;
static int32 consolemousey;
static int32 consolebutton;
int32 func__getconsoleinput(); //declare here, so we can use with SLEEP and END commands
//This next block used to be in common.cpp; put here until I can find a better
//place for it (LC, 2018-01-05)
@ -29724,104 +29723,160 @@ void reinit_glut_callbacks(){
#endif
}
#ifdef QB64_WINDOWS
int32 func__capslock(){
#ifdef QB64_WINDOWS
return -GetKeyState(VK_CAPITAL);
#endif
return 0;
}
int32 func__scrolllock(){
#ifdef QB64_WINDOWS
return -GetKeyState(VK_SCROLL);
#endif
return 0;
}
int32 func__numlock(){
#ifdef QB64_WINDOWS
return -GetKeyState(VK_NUMLOCK);
#endif
return 0;
}
void toggle_lock_key(int32 key_code){
#ifdef QB64_WINDOWS
keybd_event (key_code, 0x45, 1, 0);
keybd_event (key_code, 0x45, 3, 0);
#endif
}
void sub__capslock(int32 options){
#ifdef QB64_WINDOWS
//VK_CAPITAL
int32 currentState = func__capslock();
switch(options){
case 1: //ON
if (currentState==-1) return;
break;
case 2: //OFF
if (currentState==0) return;
break;
}
// _TOGGLE:
toggle_lock_key(VK_CAPITAL);
#endif
}
void sub__scrolllock(int32 options){
#ifdef QB64_WINDOWS
//VK_SCROLL
int32 currentState = func__scrolllock();
switch(options){
case 1: //ON
if (currentState==-1) return;
break;
case 2: //OFF
if (currentState==0) return;
break;
}
// _TOGGLE:
toggle_lock_key(VK_SCROLL);
#endif
}
void sub__numlock(int32 options){
#ifdef QB64_WINDOWS
//VK_NUMLOCK
int32 currentState = func__numlock();
switch(options){
case 1: //ON
if (currentState==-1) return;
break;
case 2: //OFF
if (currentState==0) return;
break;
}
// _TOGGLE:
toggle_lock_key(VK_NUMLOCK);
#endif
}
void sub__consolefont(qbs* FontName, int FontSize){
/*
#ifdef QB64_WINDOWS
SECURITY_ATTRIBUTES SecAttribs = {sizeof(SECURITY_ATTRIBUTES), 0, 1};
HANDLE cl_conout = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, & SecAttribs, OPEN_EXISTING, 0, 0);
static int OneTimePause;
if (!OneTimePause){ // a slight delay so the console can be properly created and registered with Windows, before we try and change fonts with it.
Sleep(500);
OneTimePause=1; //after the first pause, the console should be created, so we don't need any more delays in the future.
}
CONSOLE_FONT_INFOEX info = {0};
info.cbSize = sizeof(info);
info.dwFontSize.Y = FontSize; // leave X as zero
info.FontWeight = FW_NORMAL;
if (FontName->len>0){ //if we don't pass a font name, don't change the existing one.
const size_t cSize = FontName->len;
wchar_t* wc = new wchar_t[32];
mbstowcs (wc, (char *)FontName->chr, cSize);
wcscpy(info.FaceName, wc);
delete[] wc;
}
SetCurrentConsoleFontEx(cl_conout, NULL, &info);
#endif
*/
}
void sub__console_cursor(int32 visible, int32 cursorsize, int32 passed){
#ifdef QB64_WINDOWS
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
int func__capslock(){
return GetKeyState(VK_CAPITAL);
}
GetConsoleCursorInfo(consoleHandle, &info); //get the original info, so we reuse it, unless the user called for a change.
int func__scrollock(){
return GetKeyState(VK_NUMLOCK);
}
int func__numlock(){
return GetKeyState(VK_SCROLL);
}
void sub__toggle_capslock(){
keybd_event (VK_CAPITAL, 0x45, 1, 0);
keybd_event (VK_CAPITAL, 0x45, 3, 0);
}
void sub__toggle_scrollock(){
keybd_event (VK_NUMLOCK, 0x45, 1, 0);
keybd_event (VK_NUMLOCK, 0x45, 3, 0);
}
void sub__toggle_numlock(){
keybd_event (VK_SCROLL, 0x45, 1, 0);
keybd_event (VK_SCROLL, 0x45, 3, 0);
}
void CFont(qbs* FontName, int FontSize){
/*
SECURITY_ATTRIBUTES SecAttribs = {sizeof(SECURITY_ATTRIBUTES), 0, 1};
HANDLE cl_conout = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, & SecAttribs, OPEN_EXISTING, 0, 0);
static int OneTimePause;
if (!OneTimePause){ // a slight delay so the console can be properly created and registered with Windows, before we try and change fonts with it.
Sleep(500);
OneTimePause=1; //after the first pause, the console should be created, so we don't need any more delays in the future.
}
CONSOLE_FONT_INFOEX info = {0};
info.cbSize = sizeof(info);
info.dwFontSize.Y = FontSize; // leave X as zero
info.FontWeight = FW_NORMAL;
if (FontName->len>0){ //if we don't pass a font name, don't change the existing one.
const size_t cSize = FontName->len;
wchar_t* wc = new wchar_t[32];
mbstowcs (wc, (char *)FontName->chr, cSize);
wcscpy(info.FaceName, wc);
delete[] wc;
}
SetCurrentConsoleFontEx(cl_conout, NULL, &info);
*/
}
void sub__console_cursor(int32 visible, int32 cursorsize, int32 passed){
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
if (visible==1)info.bVisible = TRUE; //cursor is set to show
if (visible==2)info.bVisible = FALSE; //set to hide
if (passed&&cursorsize>=0&&cursorsize<=100)info.dwSize = cursorsize; //the user passed the cursor size, of a suitable size
GetConsoleCursorInfo(consoleHandle, &info); //get the original info, so we reuse it, unless the user called for a change.
SetConsoleCursorInfo(consoleHandle, &info);
#endif
}
if (visible==1)info.bVisible = TRUE; //cursor is set to show
if (visible==2)info.bVisible = FALSE; //set to hide
if (passed&&cursorsize>=0&&cursorsize<=100)info.dwSize = cursorsize; //the user passed the cursor size, of a suitable size
SetConsoleCursorInfo(consoleHandle, &info);
int32 func__getconsoleinput(){
#ifdef QB64_WINDOWS
HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE);
INPUT_RECORD irInputRecord;
DWORD dwEventsRead, fdwMode, dwMode;
CONSOLE_SCREEN_BUFFER_INFO cl_bufinfo;
GetConsoleMode(hStdin, (LPDWORD)&dwMode);
fdwMode = ENABLE_EXTENDED_FLAGS;
SetConsoleMode(hStdin, fdwMode);
fdwMode = dwMode | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin, fdwMode);
ReadConsoleInputA (hStdin, &irInputRecord, 1, &dwEventsRead);
switch(irInputRecord.EventType){
case KEY_EVENT: //keyboard input
consolekey = irInputRecord.Event.KeyEvent.wVirtualScanCode;
if (!irInputRecord.Event.KeyEvent.bKeyDown) consolekey = -consolekey; //positive/negative return of scan codes.
return 1;
case MOUSE_EVENT: //mouse input
consolemousex = irInputRecord.Event.MouseEvent.dwMousePosition.X + 1;
consolemousey = irInputRecord.Event.MouseEvent.dwMousePosition.Y - cl_bufinfo.srWindow.Top + 1;
consolebutton = irInputRecord.Event.MouseEvent.dwButtonState; //button state for all buttons
//SetConsoleMode(hStdin, dwMode);
return 2;
}
#endif
return 0; //in case it's some other odd input
}
int32 func__getconsoleinput(){
HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE);
INPUT_RECORD irInputRecord;
DWORD dwEventsRead, fdwMode, dwMode;
CONSOLE_SCREEN_BUFFER_INFO cl_bufinfo;
GetConsoleMode(hStdin, (LPDWORD)&dwMode);
fdwMode = ENABLE_EXTENDED_FLAGS;
SetConsoleMode(hStdin, fdwMode);
fdwMode = dwMode | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin, fdwMode);
ReadConsoleInputA (hStdin, &irInputRecord, 1, &dwEventsRead);
switch(irInputRecord.EventType){
case KEY_EVENT: //keyboard input
consolekey = irInputRecord.Event.KeyEvent.wVirtualScanCode;
if (!irInputRecord.Event.KeyEvent.bKeyDown) consolekey = -consolekey; //positive/negative return of scan codes.
return 1;
case MOUSE_EVENT: //mouse input
consolemousex = irInputRecord.Event.MouseEvent.dwMousePosition.X + 1;
consolemousey = irInputRecord.Event.MouseEvent.dwMousePosition.Y - cl_bufinfo.srWindow.Top + 1;
consolebutton = irInputRecord.Event.MouseEvent.dwButtonState; //button state for all buttons
//SetConsoleMode(hStdin, dwMode);
return 2;
}
return 0; //in case it's some other odd input
}
int32 func__CInp (int32 toggle, int32 passed){
int32 func__cinp (int32 toggle, int32 passed){
#ifdef QB64_WINDOWS
int32 temp = consolekey;
consolekey = 0; //reset the console key, now that we've read it
if (passed==0)toggle=1; //default return of positive/negative scan code values
@ -29831,6 +29886,7 @@ void reinit_glut_callbacks(){
if (temp>=0)return temp;
return -temp + 128;
}
}
#endif
#else
return 0;
#endif
}

View file

@ -1,18 +1,16 @@
#include "common.h"
#ifdef QB64_WINDOWS
extern int32 func__CInp (int32 toggle, int32 passed); //Console INP scan code reader
extern int func__capslock();
extern int func__scrollock();
extern int func__numlock();
extern void sub__toggle_capslock();
extern void sub__toggle_scrollock();
extern void sub__toggle_numlock();
extern void CFont(qbs* FontName, int FontSize);
extern void sub__console_cursor(int32 visible, int32 cursorsize, int32 passed);
extern int32 func__getconsoleinput();
#endif
extern int32 func__cinp (int32 toggle, int32 passed); //Console INP scan code reader
extern int func__capslock();
extern int func__scrolllock();
extern int func__numlock();
extern void sub__capslock(int32 options);
extern void sub__scrolllock(int32 options);
extern void sub__numlock(int32 options);
extern void sub__consolefont(qbs* FontName, int FontSize);
extern void sub__console_cursor(int32 visible, int32 cursorsize, int32 passed);
extern int32 func__getconsoleinput();
#ifdef DEPENDENCY_ZLIB
qbs *func__deflate(qbs *text);

View file

@ -122,7 +122,7 @@ listOfKeywords$ = listOfKeywords$ + "_ERRORLINE@_EXIT@_EXPLICIT@_FILEEXISTS@_FLO
listOfKeywords$ = listOfKeywords$ + "_GLCOPYTEXSUBIMAGE2D@_GLCULLFACE@_GLDELETELISTS@_GLDELETETEXTURES@_GLDEPTHFUNC@_GLDEPTHMASK@_GLDEPTHRANGE@_GLDISABLE@_GLDISABLECLIENTSTATE@_GLDRAWARRAYS@_GLDRAWBUFFER@_GLDRAWELEMENTS@_GLDRAWPIXELS@_GLEDGEFLAG@_GLEDGEFLAGPOINTER@_GLEDGEFLAGV@_GLENABLE@_GLENABLECLIENTSTATE@_GLEND@_GLENDLIST@_GLEVALCOORD1D@_GLEVALCOORD1DV@_GLEVALCOORD1F@_GLEVALCOORD1FV@_GLEVALCOORD2D@_GLEVALCOORD2DV@_GLEVALCOORD2F@_GLEVALCOORD2FV@_GLEVALMESH1@_GLEVALMESH2@_GLEVALPOINT1@_GLEVALPOINT2@_GLFEEDBACKBUFFER@_GLFINISH@_GLFLUSH@_GLFOGF@_GLFOGFV@_GLFOGI@_GLFOGIV@_GLFRONTFACE@_GLFRUSTUM@_GLGENLISTS@_GLGENTEXTURES@_GLGETBOOLEANV@_GLGETCLIPPLANE@_GLGETDOUBLEV@_GLGETERROR@_GLGETFLOATV@_GLGETINTEGERV@_GLGETLIGHTFV@_GLGETLIGHTIV@_GLGETMAPDV@_GLGETMAPFV@_GLGETMAPIV@_GLGETMATERIALFV@_GLGETMATERIALIV@_GLGETPIXELMAPFV@_GLGETPIXELMAPUIV@_GLGETPIXELMAPUSV@_GLGETPOINTERV@_GLGETPOLYGONSTIPPLE@_GLGETSTRING@_GLGETTEXENVFV@_GLGETTEXENVIV@_GLGETTEXGENDV@_GLGETTEXGENFV@_GLGETTEXGENIV@_GLGETTEXIMAGE@_GLGETTEXLEVELPARAMETERFV@_GLGETTEXLEVELPARAMETERIV@_GLGETTEXPARAMETERFV@_GLGETTEXPARAMETERIV@_GLHINT@_GLINDEXMASK@_GLINDEXPOINTER@_GLINDEXD@_GLINDEXDV@_GLINDEXF@_GLINDEXFV@_GLINDEXI@_GLINDEXIV@_GLINDEXS@_GLINDEXSV@_GLINDEXUB@_GLINDEXUBV@_GLINITNAMES@_GLINTERLEAVEDARRAYS@_GLISENABLED@_GLISLIST@_GLISTEXTURE@_GLLIGHTMODELF@_GLLIGHTMODELFV@_GLLIGHTMODELI@_GLLIGHTMODELIV@_GLLIGHTF@_GLLIGHTFV@_GLLIGHTI@_GLLIGHTIV@_GLLINESTIPPLE@_GLLINEWIDTH@_GLLISTBASE@_GLLOADIDENTITY@_GLLOADMATRIXD@_GLLOADMATRIXF@_GLLOADNAME@_GLLOGICOP@_GLMAP1D@_GLMAP1F@_GLMAP2D@_GLMAP2F@_GLMAPGRID1D@_GLMAPGRID1F@_GLMAPGRID2D@_GLMAPGRID2F@_GLMATERIALF@_GLMATERIALFV@_GLMATERIALI@_GLMATERIALIV@_GLMATRIXMODE@_GLMULTMATRIXD@_GLMULTMATRIXF@_GLNEWLIST@_GLNORMAL3B@_GLNORMAL3BV@_GLNORMAL3D@_GLNORMAL3DV@_GLNORMAL3F@_GLNORMAL3FV@_GLNORMAL3I@_GLNORMAL3IV@_GLNORMAL3S@_GLNORMAL3SV@_GLNORMALPOINTER@_GLORTHO@_GLPASSTHROUGH@_GLPIXELMAPFV@_GLPIXELMAPUIV@_GLPIXELMAPUSV@_GLPIXELSTOREF@_GLPIXELSTOREI@_GLPIXELTRANSFERF@_GLPIXELTRANSFERI@_GLPIXELZOOM@_GLPOINTSIZE@_GLPOLYGONMODE@_GLPOLYGONOFFSET@_GLPOLYGONSTIPPLE@"
listOfKeywords$ = listOfKeywords$ + "_GLPOPATTRIB@_GLPOPCLIENTATTRIB@_GLPOPMATRIX@_GLPOPNAME@_GLPRIORITIZETEXTURES@_GLPUSHATTRIB@_GLPUSHCLIENTATTRIB@_GLPUSHMATRIX@_GLPUSHNAME@_GLRASTERPOS2D@_GLRASTERPOS2DV@_GLRASTERPOS2F@_GLRASTERPOS2FV@_GLRASTERPOS2I@_GLRASTERPOS2IV@_GLRASTERPOS2S@_GLRASTERPOS2SV@_GLRASTERPOS3D@_GLRASTERPOS3DV@_GLRASTERPOS3F@_GLRASTERPOS3FV@_GLRASTERPOS3I@_GLRASTERPOS3IV@_GLRASTERPOS3S@_GLRASTERPOS3SV@_GLRASTERPOS4D@_GLRASTERPOS4DV@_GLRASTERPOS4F@_GLRASTERPOS4FV@_GLRASTERPOS4I@_GLRASTERPOS4IV@_GLRASTERPOS4S@_GLRASTERPOS4SV@_GLREADBUFFER@_GLREADPIXELS@_GLRECTD@_GLRECTDV@_GLRECTF@_GLRECTFV@_GLRECTI@_GLRECTIV@_GLRECTS@_GLRECTSV@_GLRENDERMODE@_GLROTATED@_GLROTATEF@_GLSCALED@_GLSCALEF@_GLSCISSOR@_GLSELECTBUFFER@_GLSHADEMODEL@_GLSTENCILFUNC@_GLSTENCILMASK@_GLSTENCILOP@_GLTEXCOORD1D@_GLTEXCOORD1DV@_GLTEXCOORD1F@_GLTEXCOORD1FV@_GLTEXCOORD1I@_GLTEXCOORD1IV@_GLTEXCOORD1S@_GLTEXCOORD1SV@_GLTEXCOORD2D@_GLTEXCOORD2DV@_GLTEXCOORD2F@_GLTEXCOORD2FV@_GLTEXCOORD2I@_GLTEXCOORD2IV@_GLTEXCOORD2S@_GLTEXCOORD2SV@_GLTEXCOORD3D@_GLTEXCOORD3DV@_GLTEXCOORD3F@_GLTEXCOORD3FV@_GLTEXCOORD3I@_GLTEXCOORD3IV@_GLTEXCOORD3S@_GLTEXCOORD3SV@_GLTEXCOORD4D@_GLTEXCOORD4DV@_GLTEXCOORD4F@_GLTEXCOORD4FV@_GLTEXCOORD4I@_GLTEXCOORD4IV@_GLTEXCOORD4S@_GLTEXCOORD4SV@_GLTEXCOORDPOINTER@_GLTEXENVF@_GLTEXENVFV@_GLTEXENVI@_GLTEXENVIV@_GLTEXGEND@_GLTEXGENDV@_GLTEXGENF@_GLTEXGENFV@_GLTEXGENI@_GLTEXGENIV@_GLTEXIMAGE1D@_GLTEXIMAGE2D@_GLTEXPARAMETERF@_GLTEXPARAMETERFV@_GLTEXPARAMETERI@_GLTEXPARAMETERIV@_GLTEXSUBIMAGE1D@_GLTEXSUBIMAGE2D@_GLTRANSLATED@_GLTRANSLATEF@_GLVERTEX2D@_GLVERTEX2DV@_GLVERTEX2F@_GLVERTEX2FV@_GLVERTEX2I@_GLVERTEX2IV@_GLVERTEX2S@_GLVERTEX2SV@_GLVERTEX3D@_GLVERTEX3DV@_GLVERTEX3F@_GLVERTEX3FV@_GLVERTEX3I@_GLVERTEX3IV@_GLVERTEX3S@_GLVERTEX3SV@_GLVERTEX4D@_GLVERTEX4DV@_GLVERTEX4F@_GLVERTEX4FV@_GLVERTEX4I@_GLVERTEX4IV@_GLVERTEX4S@_GLVERTEX4SV@_GLVERTEXPOINTER@_GLVIEWPORT@SMOOTH@STRETCH@_ANTICLOCKWISE@_BEHIND@_CLEAR@_FILLBACKGROUND@_GLUPERSPECTIVE@_HARDWARE@_HARDWARE1@_KEEPBACKGROUND@_NONE@_OFF@_ONLY@_ONLYBACKGROUND@_ONTOP@_SEAMLESS@_SMOOTH@_SMOOTHSHRUNK@_SMOOTHSTRETCHED@"
listOfKeywords$ = listOfKeywords$ + "_SOFTWARE@_SQUAREPIXELS@_STRETCH@_ALLOWFULLSCREEN@_ALL@_ECHO@_INSTRREV@_TRIM$@_ACCEPTFILEDROP@_FINISHDROP@_TOTALDROPPEDFILES@_DROPPEDFILE@_DROPPEDFILE$@_SHR@_SHL@"
listOfKeywords$ = listOfKeywords$ + "_DEFLATE$@_INFLATE$@_READBIT@_RESETBIT@_SETBIT@_TOGGLEBIT@$ASSERTS@_ASSERT@"
listOfKeywords$ = listOfKeywords$ + "_DEFLATE$@_INFLATE$@_READBIT@_RESETBIT@_SETBIT@_TOGGLEBIT@$ASSERTS@_ASSERT@_CAPSLOCK@_NUMLOCK@_SCROLLLOCK@_TOGGLE@_CONSOLEFONT@_CONSOLECURSOR@_CONSOLEINPUT@_CINP@"
'IDE MODULE: shared data & definitions
'---------------------------------------------------

View file

@ -3327,15 +3327,15 @@ id.n = "_CAPSLOCK"
id.subfunc = 1
id.callname = "func__capslock"
id.args = 0
id.ret = INTEGERTYPE - ISPOINTER
id.ret = LONGTYPE - ISPOINTER
regid
clearid
id.n = "_SCROLLOCK"
id.n = "_SCROLLLOCK"
id.subfunc = 1
id.callname = "func__scrollock"
id.callname = "func__scrolllock"
id.args = 0
id.ret = INTEGERTYPE - ISPOINTER
id.ret = LONGTYPE - ISPOINTER
regid
clearid
@ -3343,34 +3343,40 @@ id.n = "_NUMLOCK"
id.subfunc = 1
id.callname = "func__numlock"
id.args = 0
id.ret = INTEGERTYPE - ISPOINTER
id.ret = LONGTYPE - ISPOINTER
regid
clearid
id.n = "_TOGGLE_CAPSLOCK"
id.n = "_CAPSLOCK"
id.subfunc = 2
id.callname = "sub__toggle_capslock"
id.args = 0
id.callname = "sub__capslock"
id.arg = MKL$(LONGTYPE - ISPOINTER)
id.args = 1
id.specialformat = "{ON|OFF|_TOGGLE}"
regid
clearid
id.n = "_TOGGLE_SCROLLOCK"
id.n = "_SCROLLLOCK"
id.subfunc = 2
id.callname = "sub__toggle_scrollock"
id.args = 0
id.callname = "sub__scrolllock"
id.arg = MKL$(LONGTYPE - ISPOINTER)
id.args = 1
id.specialformat = "{ON|OFF|_TOGGLE}"
regid
clearid
id.n = "_TOGGLE_NUMLOCK"
id.n = "_NUMLOCK"
id.subfunc = 2
id.callname = "sub__toggle_numlock"
id.args = 0
id.callname = "sub__numlock"
id.arg = MKL$(LONGTYPE - ISPOINTER)
id.args = 1
id.specialformat = "{ON|OFF|_TOGGLE}"
regid
clearid
id.n = "_CONSOLEFONT"
id.subfunc = 2
id.callname = "CFont"
id.callname = "sub__consolefont"
id.args = 2
id.arg = MKL$(STRINGTYPE - ISPOINTER) + MKL$(INTEGERTYPE - ISPOINTER)
regid