Keyboard support. Kinda wonky on Linux. Thanks, SDL.

This commit is contained in:
Scott Duensing 2021-10-18 21:16:45 -05:00
parent 07dbada6e8
commit 39c22c7abe
16 changed files with 324 additions and 81 deletions

View file

@ -24,6 +24,7 @@ DESTDIR = $$OUT_PWD/bin
DOS_HEADERS =
DOS_SOURCES = \
src/dos/keyboard.c \
src/dos/mouse.c \
src/dos/vesa.c
@ -44,6 +45,7 @@ INCLUDEPATH += \
HEADERS = \
$$LINUX_HEADERS \
src/gui/button.h \
src/gui/keyboard.h \
src/gui/task.h \
src/thirdparty/stb_ds.h \
src/thirdparty/stb_leakcheck.h \

99
client/src/dos/keyboard.c Normal file
View file

@ -0,0 +1,99 @@
/*
* Kangaroo Punch Multi Player Game Server Mark II
* Copyright (C) 2020-2021 Scott Duensing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "keyboard.h"
#define KEYBOARD_READ_EXTENDED 0x10
#define KEYBOARD_CHECK_EXTENDED 0x11
#define KEYBOARD_META_EXTENDED 0x12
enum MetaBitsE {
META_SHIFT_RIGHT = 0,
META_SHIFT_LEFT,
META_CONTROL,
META_ALT,
META_SCROLL_LOCKED,
META_NUM_LOCKED,
META_CAPS_LOCKED,
META_INSERT_LOCKED,
META_CONTROL_LEFT,
META_ALT_LEFT,
META_CONTROL_RIGHT,
META_ALT_RIGHT,
META_SCROLL_LOCK,
META_NUM_LOCK,
META_CAPS_LOCK,
META_SYSREQ
};
static int16_t _key = 0;
static int16_t _meta = 0;
uint8_t keyAlt(void) {
return 0 != (_meta & (1 << META_ALT)) + (_meta & (1 << META_ALT_LEFT)) + (_meta & (1 << META_ALT_RIGHT));
}
uint8_t keyASCII(void) {
return (uint8_t)(_key & 0x00FF);
}
uint8_t keyControl(void) {
return 0 != (_meta & (1 << META_CONTROL)) + (_meta & (1 << META_CONTROL_LEFT)) + (_meta & (1 << META_CONTROL_RIGHT));
}
uint8_t keyHit(void) {
int16_t result = bioskey(KEYBOARD_CHECK_EXTENDED);
int16_t meta = bioskey(KEYBOARD_META_EXTENDED);
if (result > 0) {
_key = bioskey(KEYBOARD_READ_EXTENDED);;
_meta = meta;
return 1;
}
return 0;
}
uint8_t keyScanCode(void) {
return (uint8_t)((_key & 0xFF00) >> 8);
}
uint8_t keyShift(void) {
return 0 != (_meta & (1 << META_SHIFT_LEFT)) + (_meta & (1 << META_SHIFT_RIGHT));
}
void keyShutdown(void) {
// Nada for DOS.
}
void keyStartup(void) {
// Nada for DOS.
}

View file

@ -143,16 +143,16 @@ void vbeSetDisplayStart(uint32_t pixel, uint32_t scanline);
VBESurfaceT *vbeSetMode(uint16_t vbeModeNumber);
uint16_t vbeSetScanlineLength(uint16_t pixelLength);
void (*vbePutPixel)(uint16_t x, uint16_t y, PixelT pixel);
void (*vbePutPixel)(uint16_t x, uint16_t y, ColorT color);
static void (*pmVBESetDisplayStart)(void);
static void vbeCreatePalette(void);
static uint8_t vbeIsDesiredMode(void);
static void vbePutPixel8(uint16_t x, uint16_t y, PixelT pixel);
static void vbePutPixel16(uint16_t x, uint16_t y, PixelT pixel);
static void vbePutPixel32(uint16_t x, uint16_t y, PixelT pixel);
static void vbePutPixel8(uint16_t x, uint16_t y, ColorT color);
static void vbePutPixel16(uint16_t x, uint16_t y, ColorT color);
static void vbePutPixel32(uint16_t x, uint16_t y, ColorT color);
static VBESurfaceT _vbeSurface;
@ -392,7 +392,7 @@ static uint8_t vbeIsDesiredMode(void) {
}
PixelT vbeMakePixel(uint8_t red, uint8_t green, uint8_t blue) {
ColorT vbeMakeColor(uint8_t red, uint8_t green, uint8_t blue) {
return
(((red >> _vbeSurface.rShift) << _vbeSurface.rPos) & _vbeSurface.rMask) |
(((green >> _vbeSurface.gShift) << _vbeSurface.gPos) & _vbeSurface.gMask) |
@ -430,21 +430,21 @@ void vbePresent(void) {
}
static void vbePutPixel8(uint16_t x, uint16_t y, PixelT pixel) {
//_farpokeb(_vbeSurface.lfbSelector, _yTable[y] + x, (uint8_t)pixel);
_activeSurface->buffer.bits8[y * _activeSurface->width + x] = (uint8_t)pixel;
static void vbePutPixel8(uint16_t x, uint16_t y, ColorT color) {
//_farpokeb(_vbeSurface.lfbSelector, _yTable[y] + x, (uint8_t)color);
_activeSurface->buffer.bits8[y * _activeSurface->width + x] = (uint8_t)color;
}
static void vbePutPixel16(uint16_t x, uint16_t y, PixelT pixel) {
//_farpokew(_vbeSurface.lfbSelector, _yTable[y] + (x << 1), (uint16_t)pixel);
_activeSurface->buffer.bits16[y * _activeSurface->width + x] = (uint16_t)pixel;
static void vbePutPixel16(uint16_t x, uint16_t y, ColorT color) {
//_farpokew(_vbeSurface.lfbSelector, _yTable[y] + (x << 1), (uint16_t)color);
_activeSurface->buffer.bits16[y * _activeSurface->width + x] = (uint16_t)color;
}
static void vbePutPixel32(uint16_t x, uint16_t y, PixelT pixel) {
//_farpokel(_vbeSurface.lfbSelector, _yTable[y] + (x << 2), pixel);
_activeSurface->buffer.bits32[y * _activeSurface->width + x] = pixel;
static void vbePutPixel32(uint16_t x, uint16_t y, ColorT color) {
//_farpokel(_vbeSurface.lfbSelector, _yTable[y] + (x << 2), color);
_activeSurface->buffer.bits32[y * _activeSurface->width + x] = color;
}
@ -759,7 +759,7 @@ void vbeSurfaceBlit(SurfaceT *source, uint16_t x, uint16_t y) {
}
void vbeSurfaceClear(PixelT color) {
void vbeSurfaceClear(ColorT color) {
uint16_t x;
uint16_t y;

View file

@ -102,8 +102,8 @@ ButtonT *buttonNew(uint16_t x, uint16_t y, char *title, widgetCallback callback)
static void buttonPaint(WidgetT *widget) {
ButtonT *b = (ButtonT *)widget;
int16_t i;
PixelT highlight = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_BUTTON_SHADOW] : _guiColor[COLOR_BUTTON_HIGHLIGHT];
PixelT shadow = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_BUTTON_HIGHLIGHT] : _guiColor[COLOR_BUTTON_SHADOW] ;
ColorT highlight = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_BUTTON_SHADOW] : _guiColor[COLOR_BUTTON_HIGHLIGHT];
ColorT shadow = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_BUTTON_HIGHLIGHT] : _guiColor[COLOR_BUTTON_SHADOW] ;
if (GUI_GET_FLAG(widget, WIDGET_FLAG_DIRTY)) {
vbeSurfaceSet(b->base.surface);

View file

@ -64,7 +64,7 @@ FontT *fontLoad(char *filename) {
}
void fontRender(FontT *font, char *string, PixelT foreground, PixelT background, uint16_t x, uint16_t y) {
void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, uint16_t x, uint16_t y) {
uint8_t cx;
uint8_t cy;
uint16_t offset;

View file

@ -39,7 +39,7 @@ typedef struct FontS {
uint16_t fontHeightGet(FontT *font);
FontT *fontLoad(char *filename);
void fontRender(FontT *font, char *string, PixelT foreground, PixelT background, uint16_t x, uint16_t y);
void fontRender(FontT *font, char *string, ColorT foreground, ColorT background, uint16_t x, uint16_t y);
void fontUnload(FontT **font);
uint16_t fontWidthGet(FontT *font);

View file

@ -28,7 +28,7 @@
int16_t _guiMetric[METRIC_COUNT];
PixelT _guiColor[COLOR_COUNT];
ColorT _guiColor[COLOR_COUNT];
FontT *_guiFont = NULL;
WidgetT *_guiDragWidget = NULL;
uint16_t _guiDragOffsetX = 0;
@ -134,7 +134,7 @@ void guiDelete(WidgetT **widget) {
}
void guiDrawHighlightFrame(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, PixelT upperLeft, PixelT lowerRight) {
void guiDrawHighlightFrame(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, ColorT upperLeft, ColorT lowerRight) {
guiDrawLine(x1, y1, x2, y1, upperLeft);
guiDrawLine(x1, y1, x1, y2, upperLeft);
guiDrawLine(x1, y2, x2, y2, lowerRight);
@ -142,7 +142,7 @@ void guiDrawHighlightFrame(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, P
}
void guiDrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, PixelT color) {
void guiDrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT color) {
int16_t x;
int16_t y;
int16_t dx;
@ -202,7 +202,7 @@ void guiDrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, PixelT color) {
}
void guiDrawFilledRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, PixelT pixel) {
void guiDrawFilledRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT pixel) {
uint16_t x;
uint16_t y;
@ -351,18 +351,18 @@ DesktopT *guiStartup(void) {
_guiMetric[METRIC_WINDOW_TITLE_HEIGHT] = 17; // Does not include highlight or shadow lines.
_guiMetric[METRIC_WINDOW_TITLE_GRAB_HEIGHT] = _guiMetric[METRIC_WINDOW_BORDER_WIDTH] + _guiMetric[METRIC_WINDOW_TITLE_HEIGHT] + 4; // Border, highlights, titlebar.
_guiColor[COLOR_BUTTON_BACKGROUND] = vbeMakePixel(168, 168, 168);
_guiColor[COLOR_BUTTON_HIGHLIGHT] = vbeMakePixel(248, 252, 248);
_guiColor[COLOR_BUTTON_SHADOW] = vbeMakePixel( 80, 84, 80);
_guiColor[COLOR_BUTTON_TEXT] = vbeMakePixel( 0, 0, 0);
_guiColor[COLOR_DESKTOP] = vbeMakePixel( 51, 153, 255);
_guiColor[COLOR_WINDOW_BACKGROUND] = vbeMakePixel(168, 168, 168);
_guiColor[COLOR_WINDOW_HIGHLIGHT] = vbeMakePixel(248, 252, 248);
_guiColor[COLOR_WINDOW_SHADOW] = vbeMakePixel( 80, 84, 80);
_guiColor[COLOR_WINDOW_TITLE_ACTIVE] = vbeMakePixel( 80, 84, 80);
_guiColor[COLOR_WINDOW_TITLE_INACTIVE] = vbeMakePixel(168, 168, 168);
_guiColor[COLOR_WINDOW_TITLE_TEXT_ACTIVE] = vbeMakePixel(248, 252, 248);
_guiColor[COLOR_WINDOW_TITLE_TEXT_INACTIVE] = vbeMakePixel( 0, 0, 0);
_guiColor[COLOR_BUTTON_BACKGROUND] = vbeMakeColor(168, 168, 168);
_guiColor[COLOR_BUTTON_HIGHLIGHT] = vbeMakeColor(248, 252, 248);
_guiColor[COLOR_BUTTON_SHADOW] = vbeMakeColor( 80, 84, 80);
_guiColor[COLOR_BUTTON_TEXT] = vbeMakeColor( 0, 0, 0);
_guiColor[COLOR_DESKTOP] = vbeMakeColor( 51, 153, 255);
_guiColor[COLOR_WINDOW_BACKGROUND] = vbeMakeColor(168, 168, 168);
_guiColor[COLOR_WINDOW_HIGHLIGHT] = vbeMakeColor(248, 252, 248);
_guiColor[COLOR_WINDOW_SHADOW] = vbeMakeColor( 80, 84, 80);
_guiColor[COLOR_WINDOW_TITLE_ACTIVE] = vbeMakeColor( 80, 84, 80);
_guiColor[COLOR_WINDOW_TITLE_INACTIVE] = vbeMakeColor(168, 168, 168);
_guiColor[COLOR_WINDOW_TITLE_TEXT_ACTIVE] = vbeMakeColor(248, 252, 248);
_guiColor[COLOR_WINDOW_TITLE_TEXT_INACTIVE] = vbeMakeColor( 0, 0, 0);
_guiFont = fontLoad("vga8x14.dat");

View file

@ -90,7 +90,7 @@ typedef struct WindowS WindowT;
extern int16_t _guiMetric[METRIC_COUNT];
extern PixelT _guiColor[COLOR_COUNT];
extern ColorT _guiColor[COLOR_COUNT];
extern FontT *_guiFont;
extern WidgetT *_guiDragWidget;
extern uint16_t _guiDragOffsetX;
@ -101,9 +101,9 @@ extern WindowT *_guiActiveWindow;
void guiAttach(WidgetT *parent, WidgetT *child);
void guiComposite(void);
void guiDelete(WidgetT **widget);
void guiDrawHighlightFrame(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, PixelT upperLeft, PixelT lowerRight);
void guiDrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, PixelT pixel);
void guiDrawFilledRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, PixelT pixel);
void guiDrawHighlightFrame(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, ColorT upperLeft, ColorT lowerRight);
void guiDrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT pixel);
void guiDrawFilledRectangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, ColorT pixel);
void guiMousePositionOnWidgetGet(WidgetT *widget, MouseT *mouse, uint16_t *x, uint16_t *y);
void guiPaint(WidgetT *widget);
void guiProcessMouse(MouseT *mouse);

View file

@ -36,14 +36,14 @@ ImageT *imageAllocate(uint16_t w, uint16_t h) {
image->height = h;
// Create space for converted pixel data - columns
image->pixels = (PixelT **)malloc(sizeof(PixelT *) * image->width);
image->pixels = (ColorT **)malloc(sizeof(ColorT *) * image->width);
if (!image->pixels) {
free(image);
return NULL;
}
// Create space for converted pixel data - rows
for (x=0; x<image->width; x++) {
image->pixels[x] = (PixelT *)malloc(sizeof(PixelT) * image->height);
image->pixels[x] = (ColorT *)malloc(sizeof(ColorT) * image->height);
if (!image->pixels[x]) {
for (y=0; y<x; y++) {
free(image->pixels[y]);
@ -57,7 +57,7 @@ ImageT *imageAllocate(uint16_t w, uint16_t h) {
}
ImageT *imageCreate(uint16_t w, uint16_t h, PixelT color) {
ImageT *imageCreate(uint16_t w, uint16_t h, ColorT color) {
uint16_t x;
uint16_t y;
ImageT *image = imageAllocate(w, h);
@ -97,7 +97,7 @@ ImageT *imageLoad(char *filename) {
b = 0;
for (y=0; y<image->height; y++) {
for (x=0; x<image->width; x++) {
image->pixels[x][y] = vbeMakePixel(raw[b], raw[b + 1], raw[b + 2]);
image->pixels[x][y] = vbeMakeColor(raw[b], raw[b + 1], raw[b + 2]);
b += 3;
}
}
@ -108,7 +108,7 @@ ImageT *imageLoad(char *filename) {
}
PixelT imagePixelGet(ImageT *image, uint16_t x, uint16_t y) {
ColorT imagePixelGet(ImageT *image, uint16_t x, uint16_t y) {
return image->pixels[x][y];
}
@ -125,7 +125,7 @@ void imageRender(ImageT *image, uint16_t x, uint16_t y) {
}
void imageRenderWithAlpha(ImageT *image, uint16_t x, uint16_t y, PixelT alpha) {
void imageRenderWithAlpha(ImageT *image, uint16_t x, uint16_t y, ColorT alpha) {
uint16_t x1;
uint16_t y1;
uint16_t x2 = image->width;

View file

@ -31,16 +31,16 @@
typedef struct ImageS {
uint16_t width;
uint16_t height;
PixelT **pixels;
ColorT **pixels;
} ImageT;
ImageT *imageAllocate(uint16_t w, uint16_t h);
ImageT *imageCreate(uint16_t w, uint16_t h, PixelT color);
ImageT *imageCreate(uint16_t w, uint16_t h, ColorT color);
ImageT *imageLoad(char *filename);
PixelT imagePixelGet(ImageT *image, uint16_t x, uint16_t y);
ColorT imagePixelGet(ImageT *image, uint16_t x, uint16_t y);
void imageRender(ImageT *image, uint16_t x, uint16_t y);
void imageRenderWithAlpha(ImageT *image, uint16_t x, uint16_t y, PixelT alpha);
void imageRenderWithAlpha(ImageT *image, uint16_t x, uint16_t y, ColorT alpha);
void imageUnload(ImageT **image);

38
client/src/gui/keyboard.h Normal file
View file

@ -0,0 +1,38 @@
/*
* Kangaroo Punch Multi Player Game Server Mark II
* Copyright (C) 2020-2021 Scott Duensing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include "os.h"
uint8_t keyAlt(void);
uint8_t keyASCII(void);
uint8_t keyControl(void);
uint8_t keyHit(void);
uint8_t keyScanCode(void);
uint8_t keyShift(void);
void keyShutdown(void);
void keyStartup(void);
#endif // KEYBOARD_H

View file

@ -38,7 +38,7 @@
#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#include <conio.h>
#include <bios.h>
#include <sys/nearptr.h>
#include <sys/farptr.h>

View file

@ -25,7 +25,7 @@
#include "os.h"
typedef uint32_t PixelT;
typedef uint32_t ColorT;
typedef struct SurfaceS {
@ -45,12 +45,12 @@ uint8_t vbeStartup(uint16_t xRes, uint16_t yRes, uint8_t bpp);
uint8_t vbeDisplayDepthGet(void);
uint16_t vbeDisplayHeightGet(void);
uint16_t vbeDisplayWidthGet(void);
PixelT vbeMakePixel(uint8_t red, uint8_t green, uint8_t blue);
ColorT vbeMakeColor(uint8_t red, uint8_t green, uint8_t blue);
void vbePresent(void);
int16_t vbeShowInfo(void);
int16_t vbeShutdown(void);
void vbeSurfaceBlit(SurfaceT *source, uint16_t x, uint16_t y);
void vbeSurfaceClear(PixelT color);
void vbeSurfaceClear(ColorT color);
SurfaceT *vbeSurfaceCreate(uint16_t width, uint16_t height);
void vbeSurfaceDestroy(SurfaceT **surface);
uint16_t vbeSurfaceHeightGet(void);
@ -58,7 +58,7 @@ uint16_t vbeSurfaceWidthGet(void);
void vbeSurfaceSet(SurfaceT *surface);
void vbeWaitVBlank(void);
extern void (*vbePutPixel)(uint16_t x, uint16_t y, PixelT pixel);
extern void (*vbePutPixel)(uint16_t x, uint16_t y, ColorT color);
#endif // VESA20_H

View file

@ -148,8 +148,8 @@ static void windowPaint(WidgetT *widget) {
WindowT *w = (WindowT *)widget;
uint16_t x2 = w->base.w - 1;
uint16_t y2 = w->base.h - 1;
PixelT background = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_WINDOW_TITLE_ACTIVE] : _guiColor[COLOR_WINDOW_TITLE_INACTIVE];
PixelT text = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_WINDOW_TITLE_TEXT_ACTIVE] : _guiColor[COLOR_WINDOW_TITLE_TEXT_INACTIVE];
ColorT background = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_WINDOW_TITLE_ACTIVE] : _guiColor[COLOR_WINDOW_TITLE_INACTIVE];
ColorT text = GUI_GET_FLAG(widget, WIDGET_FLAG_ACTIVE) ? _guiColor[COLOR_WINDOW_TITLE_TEXT_ACTIVE] : _guiColor[COLOR_WINDOW_TITLE_TEXT_INACTIVE];
if (GUI_GET_FLAG(widget, WIDGET_FLAG_DIRTY)) {
vbeSurfaceSet(w->base.surface);

View file

@ -35,12 +35,74 @@ static uint16_t _width = 0;
static uint16_t _height = 0;
static MouseT _mouse;
static uint8_t _windowScale = 1;
static uint8_t _alt = 0;
static uint8_t _control = 0;
static uint8_t _shift = 0;
static uint8_t _ASCII = 0;
static uint8_t _scanCode = 0;
static uint8_t _ASCIIKeep = 0;
static uint8_t _scanCodeKeep = 0;
static uint8_t _keyPressed = 0;
static uint8_t _debounce = 0;
void (*vbePutPixel)(uint16_t x, uint16_t y, PixelT pixel);
void (*vbePutPixel)(uint16_t x, uint16_t y, ColorT color);
static void vbePutPixel32(uint16_t x, uint16_t y, PixelT pixel);
static void processEvent(void);
static void vbePutPixel32(uint16_t x, uint16_t y, ColorT color);
uint8_t keyAlt(void) {
return _alt;
}
uint8_t keyASCII(void) {
return _ASCIIKeep;
}
uint8_t keyControl(void) {
return _control;
}
uint8_t keyHit(void) {
uint8_t result = 0;
processEvent();
result = _keyPressed;
if (result) {
if (_scanCode == 41) _ASCII = 27; // Fix ESC mapping.
_ASCIIKeep = _ASCII;
_scanCodeKeep = _scanCode;
_keyPressed = 0;
}
return result;
}
uint8_t keyScanCode(void) {
return _scanCode;
}
uint8_t keyShift(void) {
return _shift;
}
void keyShutdown(void) {
SDL_StopTextInput();
}
void keyStartup(void) {
SDL_StartTextInput();
}
void mouseShutdown(void) {
@ -67,30 +129,64 @@ int16_t mouseStartup(void) {
MouseT *mouseRead(void) {
int mouseX = 0;
int mouseY = 0;
int buttons = 0;
SDL_Delay(1);
SDL_PumpEvents();
buttons = SDL_GetMouseState((int *)&mouseX, (int *)&mouseY);
_mouse.buttonLeftWasDown = _mouse.buttonLeft;
_mouse.buttonRightWasDown = _mouse.buttonRight;
_mouse.buttonMiddleWasDown = _mouse.buttonMiddle;
_mouse.buttonLeft = ((buttons & SDL_BUTTON_LMASK) != 0);
_mouse.buttonRight = ((buttons & SDL_BUTTON_RMASK) != 0);
_mouse.buttonMiddle = ((buttons & SDL_BUTTON_MMASK) != 0);
_mouse.x = mouseX / _windowScale;
_mouse.y = mouseY / _windowScale;
processEvent();
return &_mouse;
}
static void processEvent(void) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_MOUSEMOTION:
_mouse.x = e.motion.x;
_mouse.y = e.motion.y;
break;
case SDL_MOUSEBUTTONUP:
if (e.button.button == SDL_BUTTON_LEFT) _mouse.buttonLeft = 0;
if (e.button.button == SDL_BUTTON_RIGHT) _mouse.buttonRight = 0;
if (e.button.button == SDL_BUTTON_MIDDLE) _mouse.buttonMiddle = 0;
break;
case SDL_MOUSEBUTTONDOWN:
if (e.button.button == SDL_BUTTON_LEFT) _mouse.buttonLeft = 1;
if (e.button.button == SDL_BUTTON_RIGHT) _mouse.buttonRight = 1;
if (e.button.button == SDL_BUTTON_MIDDLE) _mouse.buttonMiddle = 1;
break;
case SDL_TEXTINPUT:
_ASCII = e.text.text[0]; //***TODO*** This is horrifically wrong.
break;
case SDL_KEYUP:
_scanCode = 0;
_ASCII = 0;
_keyPressed = 0;
_debounce = 0;
break;
case SDL_KEYDOWN:
if (_debounce == 0) {
_scanCode = e.key.keysym.scancode;
_shift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
_alt = ((SDL_GetModState() & KMOD_ALT) != 0);
_control = ((SDL_GetModState() & KMOD_CTRL) != 0);
_keyPressed = 1;
_debounce = 1;
}
break;
}
}
}
uint8_t vbeDisplayDepthGet(void) {
return 32;
}
@ -106,7 +202,7 @@ uint16_t vbeDisplayWidthGet(void) {
}
PixelT vbeMakePixel(uint8_t red, uint8_t green, uint8_t blue) {
ColorT vbeMakeColor(uint8_t red, uint8_t green, uint8_t blue) {
return
(red << 24) |
(green << 16) |
@ -124,10 +220,10 @@ void vbePresent(void) {
}
static void vbePutPixel32(uint16_t x, uint16_t y, PixelT pixel) {
uint8_t red = (pixel & 0xff000000) >> 24;
uint8_t green = (pixel & 0x00ff0000) >> 16;
uint8_t blue = (pixel & 0x0000ff00) >> 8;
static void vbePutPixel32(uint16_t x, uint16_t y, ColorT color) {
uint8_t red = (color & 0xff000000) >> 24;
uint8_t green = (color & 0x00ff0000) >> 16;
uint8_t blue = (color & 0x0000ff00) >> 8;
SDL_SetRenderDrawColor(_renderer, red, green, blue, 0xff);
SDL_RenderDrawPoint(_renderer, x, y);
@ -196,7 +292,7 @@ void vbeSurfaceBlit(SurfaceT *source, uint16_t x, uint16_t y) {
}
void vbeSurfaceClear(PixelT color) {
void vbeSurfaceClear(ColorT color) {
uint8_t red = (color & 0xff000000) >> 24;
uint8_t green = (color & 0x00ff0000) >> 16;
uint8_t blue = (color & 0x0000ff00) >> 8;

View file

@ -21,6 +21,7 @@
#include "os.h"
#include "vesa.h"
#include "mouse.h"
#include "keyboard.h"
#include "task.h"
#include "image.h"
#include "font.h"
@ -39,12 +40,13 @@ void buttonClick(WidgetT *widget) {
void test(void *data) {
MouseT *mouse = NULL;
ImageT *pointer = NULL;
PixelT alpha;
ColorT alpha;
DesktopT *desktop = (DesktopT *)guiRootGet();
WindowT *w1 = NULL;
WindowT *w2 = NULL;
WindowT *w3 = NULL;
ButtonT *b1 = NULL;
int8_t key = 0;
(void)data;
@ -63,12 +65,18 @@ void test(void *data) {
do {
mouse = mouseRead();
if (keyHit()) {
key = keyASCII();
logWrite("Key %d Scan %d Alt %d\n", key, keyScanCode(), keyAlt());
} else {
key = 0;
}
guiProcessMouse(mouse);
guiComposite();
imageRenderWithAlpha(pointer, mouse->x, mouse->y, alpha);
vbeWaitVBlank();
vbePresent();
} while (!(!mouse->buttonRight && mouse->buttonRightWasDown)); // Exit on release of right-click.
} while (key != 27 && !(!mouse->buttonRight && mouse->buttonRightWasDown)); // Exit on release of right-click.
imageUnload(&pointer);
}