JD2022-TU1/main/extern/Camcam/LIBS/Mixer/SCENE_InputHook.cpp

480 lines
12 KiB
C++

#include "SCENE.H"
#include "mshtmhst.h"
int WORLD::UpdateText()
{
if (pTG)
{
CurrentlyEditedText[2000] = 0;
pTG -> UPDATETEXT(CurrentlyEditedText);
strcpy(CurrentlyEditedText,pTG->TEXT);
if (D_UI.CursorPos >= strlen(CurrentlyEditedText))
{
D_UI.CursorPos = strlen(CurrentlyEditedText);
pTG -> UPDATETEXT(CurrentlyEditedText);
strcpy(CurrentlyEditedText,pTG->TEXT);
}
}
return 0;
}
int WORLD::GetTextFocus(TEXT_Grabber *pTGTS)
{
if (pTG != pTGTS) LooseFocus();
pTG = pTGTS;
memset(&D_UI,0,sizeof(DrwTEXT_UI));
D_UI.ColorFront = 0xffffffff;
D_UI.ColorBack = 0;
D_UI.CurrentCursorPos = 0;
D_UI.CursorPos = 0;
D_UI.MouseToCursor = 0;
D_UI.SelStart = D_UI.SelEnd = 0;
D_UI.X = 2;
D_UI.Y = pTG->Image.SY-18;
D_UI.XEnd = 0;
D_UI.YEnd = 0;
strcpy(CurrentlyEditedText,pTG->TEXT);
D_UI.CursorPos = strlen(CurrentlyEditedText);
D_UI.Birth = timeGetTime();
return 0;
}
int WORLD::LooseFocus()
{
if (pTG)
{
TEXT_Grabber *PTGSave;
PTGSave = pTG;
pTG = NULL;
PTGSave -> UPDATETEXT(CurrentlyEditedText);
}
return 0;
}
int WORLD::ProcessSel(char *NewString)
{
u32 Start,End;
if (D_UI.SelStart == D_UI.SelEnd)
D_UI.SelStart = D_UI.SelEnd = D_UI.CursorPos;
if (D_UI.SelStart < D_UI.SelEnd )
{
Start = D_UI.SelStart;
End = D_UI.SelEnd ;
} else
{
Start = D_UI.SelEnd ;
End = D_UI.SelStart;
}
if ((Start != End) || (NewString && *NewString))
{
if ((Start <= strlen(CurrentlyEditedText)) && (End <= strlen(CurrentlyEditedText)))
{
char Local[sizeof(CurrentlyEditedText)];
strcpy(Local,&CurrentlyEditedText[End]);
if (NewString)
{
if (strlen(NewString) + strlen(CurrentlyEditedText) < sizeof(CurrentlyEditedText) -1)
{
sprintf(&CurrentlyEditedText[Start],"%s%s",NewString,Local);
Start += strlen(NewString);
}
}
else
sprintf(&CurrentlyEditedText[Start],"%s",Local);
}
}
if (D_UI.SelStart != D_UI.SelEnd )
{
D_UI.SelEnd = D_UI.CursorPos = D_UI.SelStart = Start;
return 1;
}
else
{
D_UI.SelEnd = D_UI.CursorPos = D_UI.SelStart = Start;
return 0;
}
}
int WORLD::InputHook(UINT message , LPARAM wParam, LPARAM lParam)
{
static u32 LastClickTime = 0;
/* A text is edited and focus all events */
switch (message)
{
case WM_CUT:
case WM_PASTE:
case WM_COPY:
ProcessSel(NULL);
break;
case WM_KEYDOWN:
if (pTG)
{
if ((wParam == VK_TAB) || (wParam == VK_RETURN))
{
LuaHandle(WM_KEYDOWN, wParam, 0);
} else
LuaHandle(WM_KEYDOWN, 0, 0);
u32 COPY,PASTE,CUT;
COPY=PASTE=CUT=0;
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
if ((wParam == 'C') || (wParam == VK_INSERT)) // ^INSERT or ^c
COPY = 1;
else
if (wParam == 'V') // ^V
PASTE = 1;
else
if (wParam == 'X') // ^X
CUT = 1;
}
if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
{
if (wParam == VK_INSERT) // ^INSERT or ^c
PASTE = 1;
}
if ((COPY || CUT) && (!pTG->TT.Password))
{
/* COPY */
if (( D_UI.SelStart != D_UI.SelEnd ) && OpenClipboard(NULL))
{
HANDLE hMem;
char *DET;
u32 size,Base;
if (D_UI.SelStart < D_UI.SelEnd)
{
Base = D_UI.SelStart;
size = D_UI.SelEnd - D_UI.SelStart + 1;
} else
{
Base = D_UI.SelEnd;
size = D_UI.SelStart - D_UI.SelEnd + 1;
}
hMem = GlobalAlloc(GMEM_MOVEABLE,size);
DET=(char*)GlobalLock(hMem);
if (DET)
{
memcpy(DET,&CurrentlyEditedText[Base],size);
DET[size-1] = 0;
GlobalUnlock(hMem);
}
EmptyClipboard();
hMem = SetClipboardData(CF_TEXT,hMem);
CloseClipboard();
}
if (CUT) ProcessSel(NULL);
}
if (PASTE )
{
// PASTE
if (OpenClipboard(NULL))
{
HANDLE hMem;
hMem = GetClipboardData(CF_TEXT);
char *DET;
if (hMem)
{
DET=(char*)GlobalLock(hMem);
if (DET)
{
ProcessSel(DET);
GlobalUnlock(hMem);
}
}
CloseClipboard();
}
}
if (COPY|PASTE|CUT)
{
UpdateText();
return 1;
}
if ((wParam != VK_CONTROL) && (wParam <= 0x2f)&& (wParam != VK_SPACE))
{
if (D_UI.CursorPos >= strlen(CurrentlyEditedText) ) D_UI.CursorPos = strlen(CurrentlyEditedText);
D_UI.Birth = timeGetTime();
if (wParam == 27) // ESCAPE
{
LooseFocus();
return 1;
}
if (wParam == VK_RIGHT)
{
if (CurrentlyEditedText[D_UI.CursorPos]) D_UI.CursorPos++;
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
while (((CurrentlyEditedText[D_UI.CursorPos] != ' ') && (CurrentlyEditedText[D_UI.CursorPos] != '\n')) && CurrentlyEditedText[D_UI.CursorPos]) {D_UI.CursorPos++;};
while (((CurrentlyEditedText[D_UI.CursorPos] == ' ') || (CurrentlyEditedText[D_UI.CursorPos] == '\n') ) && CurrentlyEditedText[D_UI.CursorPos]) {D_UI.CursorPos++;};
}
}
if (wParam == VK_LEFT)
{
if (D_UI.CursorPos) D_UI.CursorPos--;
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
while (D_UI.CursorPos && (CurrentlyEditedText[D_UI.CursorPos] == ' ') ) {D_UI.CursorPos--;};
while (D_UI.CursorPos && (CurrentlyEditedText[D_UI.CursorPos-1] != '\n') && (CurrentlyEditedText[D_UI.CursorPos-1] != ' ') ) {D_UI.CursorPos--;};
}
}
if (wParam == VK_UP) D_UI.CursorPos = D_UI.CursorPosUP;
if (wParam == VK_HOME)
{
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
D_UI.CursorPos = 0;
else
{
if (D_UI.CursorPos)
while (((CurrentlyEditedText[D_UI.CursorPos - 1] != '\n') && D_UI.CursorPos&& (D_UI.CursorPos>1))) {D_UI.CursorPos--;};
if (D_UI.CursorPos == 1) D_UI.CursorPos = 0;
}
}
if (wParam == VK_END)
{
if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
{
D_UI.CursorPos = strlen(CurrentlyEditedText);
//if (D_UI.CursorPos) D_UI.CursorPos--;
}
else
{
while ((CurrentlyEditedText[D_UI.CursorPos] != '\n') && CurrentlyEditedText[D_UI.CursorPos])
{
D_UI.CursorPos++;
};
}
}
if (wParam == VK_DOWN)
D_UI.CursorPos = D_UI.CursorPosDown;
if (wParam == VK_INSERT)
D_UI.InsertMode ^= 1;
//if (wParam == VK_PRIOR) D_UI.CursorPos = D_UI.CursorPosDown;
if (wParam == VK_PRIOR)
{
s32 LineCounter,LineNumber;
/* advance cursor of imagesy / 16 lignes */
LineCounter = 0;
LineNumber = (pTG->Image.SY / 16) - 4;
if (LineNumber < 0) LineNumber = 1;
while ((D_UI.CursorPos) && (LineCounter < LineNumber))
{
if (CurrentlyEditedText[D_UI.CursorPos] == '\n') LineCounter++;
D_UI.CursorPos--;
}
}
if (wParam == VK_NEXT)
{
s32 LineCounter,LineNumber;
/* advance cursor of imagesy / 16 lignes */
LineCounter = 0;
LineNumber = (pTG->Image.SY / 16) - 4;
if (LineNumber < 0) LineNumber = 1;
while ((CurrentlyEditedText[D_UI.CursorPos]) && (LineCounter < LineNumber))
{
if (CurrentlyEditedText[D_UI.CursorPos] == '\n') LineCounter++;
D_UI.CursorPos++;
}
if (!CurrentlyEditedText[D_UI.CursorPos])
if(D_UI.CursorPos) D_UI.CursorPos-- ;
}
if (wParam == VK_BACK)
{
if (!ProcessSel(NULL))
{
u32 Coun = D_UI.CursorPos;
if (Coun)
{
Coun--;
D_UI.CursorPos--;
while (CurrentlyEditedText[Coun])
{
CurrentlyEditedText[Coun] = CurrentlyEditedText[Coun+1];
Coun++;
}
CurrentlyEditedText[Coun] = 0;
}
}
}
if (wParam == VK_DELETE)
{
if (!ProcessSel(NULL))
{
u32 Coun = D_UI.CursorPos;
if (CurrentlyEditedText[Coun])
{
while (CurrentlyEditedText[Coun])
{
CurrentlyEditedText[Coun] = CurrentlyEditedText[Coun+1];
Coun++;
}
CurrentlyEditedText[Coun] = 0;
}
}
}
if (wParam == VK_SHIFT)
D_UI.SelStart = D_UI.SelEnd = D_UI.CursorPos;
else
if (!(GetAsyncKeyState(VK_SHIFT) & 0x8000))
{
D_UI.SelStart = D_UI.SelEnd = D_UI.CursorPos;
} else
D_UI.SelEnd = D_UI.CursorPos;
UpdateText();
}
return 1;
}
break;
case WM_CHAR:
if (pTG)
{
if (wParam == '\r')
wParam = '\n';
if (strlen(CurrentlyEditedText) <= sizeof(CurrentlyEditedText)-1)
{
if (((wParam >= 32) && (wParam <= 255)) || ((wParam == '\n') && (pTG->TT.Multiline)))
{
char Swap,Swap2;
u32 Coun;
ProcessSel(NULL);
if (D_UI.InsertMode)
{
if (!CurrentlyEditedText[D_UI.CursorPos]) CurrentlyEditedText[D_UI.CursorPos+1] = 0;
CurrentlyEditedText[D_UI.CursorPos] = (char)wParam;
D_UI.CursorPos++;
} else
{
Coun = D_UI.CursorPos;
Swap = CurrentlyEditedText[Coun];
CurrentlyEditedText[Coun] = (char)wParam;
while (CurrentlyEditedText[Coun])
{
Swap2 = CurrentlyEditedText[Coun+1];
CurrentlyEditedText[Coun+1] = Swap;
Swap = Swap2;
Coun++;
}
CurrentlyEditedText[Coun] = 0;
D_UI.CursorPos++;
}
}//*/
}
UpdateText();
}
break;
case WM_KEYUP:
if (pTG)
{
D_UI.Birth = timeGetTime();
}
break;
case WM_KILLFOCUS:
LooseFocus();
break;
case WM_LBUTTONDOWN:
u32 ulLooseFocus;
ulLooseFocus = 1;
if (PickReportFinal.CollidedMediaName[0] == 0)
{
for (u32 Counter = 0 ; Counter < MAX_INPMED ; Counter++)
{
if (ID_MEDIA[Counter] && (&ID_MEDIA[Counter]->Image == PickReportFinal.CollidedMap))
{
strcpy((char*)PickReportFinal.CollidedMediaName,(char*)ID_MEDIA[Counter]->MediaName);
strcpy((char*)PickReportFinal.CollidedMediaNickname,(char*)ID_MEDIA[Counter]->Nickname);
Counter = MAX_INPMED;
}
}
}
if (*PickReportFinal.PickingClass && PickReportFinal.CollidedMediaName)
{
UnicID MediaIndex;
MediaIndex = MediaDico.IsExist(PickReportFinal.CollidedMediaName);
if (MediaIndex != -1)
{
MediaIndex = MediaDico.mpst_Dico[MediaIndex].AssociatedValue;
ulLooseFocus = 0;
if (ID_MEDIA[MediaIndex] && (ID_MEDIA[MediaIndex]->GetType() == IOtype_TEXT) && (((TEXT_Grabber *)ID_MEDIA[MediaIndex])->TT.Editable)&&(pTG!=ID_MEDIA[MediaIndex]))
{
LooseFocus();
GetTextFocus((TEXT_Grabber *)ID_MEDIA[MediaIndex]);
} else
if (pTG!=ID_MEDIA[MediaIndex])
ulLooseFocus = 1;
}
}
if (pTG && ulLooseFocus)
{
LooseFocus();
return 0;
}
if (pTG)
{
if (timeGetTime() - LastClickTime < 500) // Double CLick !!
{
D_UI.SelStart = D_UI.SelEnd = D_UI.CursorPos = D_UI.MouseToCursor;
while (D_UI.SelStart && (CurrentlyEditedText[D_UI.SelStart-1] != ' ') && (CurrentlyEditedText[D_UI.SelStart-1] != '\n') ) {D_UI.SelStart--;};
if (D_UI.SelStart == 1) D_UI.SelStart = 0;
while (CurrentlyEditedText[D_UI.SelEnd] && (CurrentlyEditedText[D_UI.SelEnd] != ' ') && (CurrentlyEditedText[D_UI.SelEnd] != '\n') ) {D_UI.SelEnd++;};
D_UI.CursorPos = D_UI.SelStart;
} else
{
D_UI.Birth = timeGetTime();
D_UI.MouseX = PickReportFinal.PickingCoordUV.x;
D_UI.MouseY = PickReportFinal.PickingCoordUV.y;
UpdateText();
if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
D_UI.SelStart = D_UI.CursorPos = D_UI.MouseToCursor;
else
D_UI.SelStart = D_UI.CursorPos = D_UI.SelEnd = D_UI.MouseToCursor;
}
LastClickTime = timeGetTime();
}
break;
case WM_MOUSEMOVE:
//if (timeGetTime() - LastClickTime > 100)
{
if (pTG && (GetAsyncKeyState(VK_LBUTTON) & 0x8000))
{
D_UI.Birth = timeGetTime();
D_UI.MouseX = PickReportFinal.PickingCoordUV.x;
D_UI.MouseY = PickReportFinal.PickingCoordUV.y;
D_UI.SelStart = D_UI.CursorPos = D_UI.MouseToCursor;
}
}
break;
}
return 0;
}
void WORLD::InputHookPickEnd()
{
if (pTG)
D_UI.Age = timeGetTime() - D_UI.Birth;
}