Exemplo n.º 1
0
static void textEditMiceEvent(struct OzUIWidget *widget, struct OzUIMiceEvent *miceEvent)
{
    struct OzUITextEdit *textEdit;
    struct Rect cursorRect;
    if (miceEvent->type == OZUI_MICE_EVENT_DOWN) {
        textEdit = (struct OzUITextEdit*)widget->d;
        getCursorRect(textEdit, &cursorRect);
        OzUITextEditSetCursorPos(textEdit, findCursorPos(textEdit, miceEvent->x, 
                    miceEvent->y + textEdit->layout->height));
    }
}
Exemplo n.º 2
0
// Erases everything from the current cursor position to the end of the line
bool Console::eraseToEndOfLine(void)
{
	cout.flush();
	findCursorPos();

	for(int i = xPos; i < 80; i++)
		cout << " ";
	cout.flush();
	setCursorPos(xPos, yPos);
		
	return true;
}
Exemplo n.º 3
0
// Erases everything from the cursor position to the end
bool Console::eraseFromCursorToEnd(void)
{
	cout.flush();
	findCursorPos();
	DWORD numCharactersWritten;
	COORD consoleCoords = {xPos, yPos};
	FillConsoleOutputCharacter(consoleHandle, ' ', (25 - yPos) * 80 + (80 - xPos), consoleCoords, &numCharactersWritten);
	FillConsoleOutputAttribute(consoleHandle, consoleInfo.wAttributes, (25 - yPos) * 80 + (80 - xPos), consoleCoords, &numCharactersWritten);
	setCursorPos(xPos, yPos);
	cout.flush();
	
	return true;
}
Exemplo n.º 4
0
// Erases everything from (0,0) to the cursor position
bool Console::eraseFromStartToCursor(void)
{
	cout.flush();
	findCursorPos();
	DWORD numCharactersWritten;
	COORD consoleCoords = {0, 0};
	FillConsoleOutputCharacter(consoleHandle, ' ', 80 * yPos + xPos, consoleCoords, &numCharactersWritten);
	FillConsoleOutputAttribute(consoleHandle, consoleInfo.wAttributes, 80 * yPos + xPos, consoleCoords, &numCharactersWritten);

	setCursorPos(xPos, yPos);
	cout.flush();

	return true;
}
Exemplo n.º 5
0
// Erases the entire line that the cursor is on
bool Console::eraseEntireLine(void)
{
	cout.flush();
	findCursorPos();
	unsigned char tempX = xPos;
	
	setCursorPos(0, yPos);

	for(int i = 0; i < 80; i++)
		cout << " ";

	cout.flush();
	setCursorPos(tempX, yPos);
	
	return true;
}
Exemplo n.º 6
0
// Erases everything from the start of the current line to the cursor position
bool Console::eraseFromStartOfLineToCursor(void)
{
	cout.flush();
	findCursorPos();
		
	unsigned char tempX = xPos;
	
	setCursorPos(0, yPos);

	for(int i = 0; i < xPos; i++)
		cout << " ";
	cout.flush();
	setCursorPos(tempX, yPos);

	return true;
}
Exemplo n.º 7
0
static void textEditKeyEvent(struct OzUIWidget *widget, struct OzUIKeyEvent *keyEvent)
{
    struct OzUITextEdit *textEdit;
    struct Rect cursorRect;
    wchar_t *text;
    wchar_t wch;
    textEdit = (struct OzUITextEdit*)widget->d;
    if (keyEvent->type != OZUI_KEY_EVENT_DOWN)
        return;
    switch (keyEvent->code) {
        case Key_Left:
            if (!keyEvent->mask)
                OzUITextEditSetCursorPos(textEdit, textEdit->cursorPos-1);
            break;
        case Key_Right:
            if (!keyEvent->mask)
                OzUITextEditSetCursorPos(textEdit, textEdit->cursorPos+1);
            break;
        case Key_Up:
            if (!keyEvent->mask) {
                getCursorRect(textEdit, &cursorRect);
                OzUITextEditSetCursorPos(textEdit, 
                        findCursorPos(textEdit, rectLeft(&cursorRect), rectBottom(&cursorRect) - textEdit->layout->height));
            }
            break;
        case Key_Down:
            if (!keyEvent->mask) {
                getCursorRect(textEdit, &cursorRect);
                OzUITextEditSetCursorPos(textEdit, 
                        findCursorPos(textEdit, rectLeft(&cursorRect), rectBottom(&cursorRect) + textEdit->layout->height));
            }
            break;
        case Key_Delete:
            if (textEdit->cursorPos < textEdit->layout->chars-1) {
                text = (wchar_t*)calloc(textEdit->layout->chars, sizeof(wchar_t));
                wcsncpy(text, textEdit->text, textEdit->cursorPos);
                wcscpy(&text[textEdit->cursorPos], &textEdit->text[textEdit->cursorPos+1]);
                OzUITextEditSetText(textEdit, text);
                free(text);
            }
            break;
        case Key_Backspace:
            if (textEdit->cursorPos) {
                text = (wchar_t*)calloc(textEdit->layout->chars, sizeof(wchar_t));
                wcsncpy(text, textEdit->text, textEdit->cursorPos-1);
                wcscpy(&text[textEdit->cursorPos-1], &textEdit->text[textEdit->cursorPos]);
                textEdit->cursorPos--;
                OzUITextEditSetText(textEdit, text);
                free(text);
            }
            break;
        case Key_Return:
            if (textEdit->allowMultiline) {
                wch = L'\n';
                text = (wchar_t*)calloc(textEdit->layout->chars+1, sizeof(wchar_t));
                wcsncpy(text, textEdit->text, textEdit->cursorPos);
                text[textEdit->cursorPos] = wch;
                wcscpy(&text[textEdit->cursorPos+1], &textEdit->text[textEdit->cursorPos]);
                textEdit->cursorPos++;
                OzUITextEditSetText(textEdit, text);
                free(text);
            }
            break;
        default:
            wch = OzUIKeyEventTranslate(keyEvent);
            if (wch) {
                text = (wchar_t*)calloc(textEdit->layout->chars+1, sizeof(wchar_t));
                wcsncpy(text, textEdit->text, textEdit->cursorPos);
                text[textEdit->cursorPos] = wch;
                wcscpy(&text[textEdit->cursorPos+1], &textEdit->text[textEdit->cursorPos]);
                textEdit->cursorPos++;
                OzUITextEditSetText(textEdit, text);
                free(text);
            }
    }
}