Starting porting new code to other targets besides GRX.
This commit is contained in:
parent
a83fddc486
commit
e807f883b4
13 changed files with 372 additions and 182 deletions
|
@ -4,35 +4,48 @@ CONFIG -= qt
|
||||||
CONFIG -= console
|
CONFIG -= console
|
||||||
CONFIG += c99
|
CONFIG += c99
|
||||||
|
|
||||||
LINUX = $$PWD/../installed/linux
|
CONFIG += BACKEND_GRX
|
||||||
|
#CONFIG += BACKEND_SDL2
|
||||||
|
#CONFIG += BACKEND_DJGPP
|
||||||
|
|
||||||
SHARED = $$PWD/../shared
|
SHARED = $$PWD/../shared
|
||||||
|
|
||||||
DESTDIR = $$OUT_PWD/bin
|
DESTDIR = $$OUT_PWD/bin
|
||||||
|
|
||||||
INCLUDEPATH += \
|
INCLUDEPATH += \
|
||||||
$$PWD/src \
|
$$PWD/src \
|
||||||
$$LINUX/include \
|
|
||||||
$$SHARED
|
$$SHARED
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$SHARED/macros.h \
|
$$SHARED/macros.h \
|
||||||
../shared/array.h \
|
$$SHARED/array.h \
|
||||||
../shared/memory.h \
|
$$SHARED/memory.h \
|
||||||
../shared/stddclmr.h \
|
$$SHARED/stddclmr.h \
|
||||||
../shared/thirdparty/memwatch/memwatch.h \
|
$$SHARED/thirdparty/memwatch/memwatch.h \
|
||||||
../shared/thirdparty/stb_ds.h \
|
$$SHARED/thirdparty/stb_ds.h \
|
||||||
src/gui/gui.h \
|
src/gui/gui.h \
|
||||||
src/gui/wmwindow.h \
|
src/gui/wmwindow.h \
|
||||||
src/os.h
|
src/os.h \
|
||||||
|
src/platform/djgpp.h \
|
||||||
|
src/platform/grx.h \
|
||||||
|
src/platform/platform.h \
|
||||||
|
src/platform/sdl2.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
../shared/array.c \
|
$$SHARED/array.c \
|
||||||
../shared/memory.c \
|
$$SHARED/memory.c \
|
||||||
../shared/thirdparty/memwatch/memwatch.c \
|
$$SHARED/thirdparty/memwatch/memwatch.c \
|
||||||
src/gui/gui.c \
|
src/gui/gui.c \
|
||||||
src/gui/wmwindow.c \
|
src/gui/wmwindow.c \
|
||||||
src/main.c
|
src/main.c \
|
||||||
|
src/platform/djgpp.c \
|
||||||
|
src/platform/grx.c \
|
||||||
|
src/platform/sdl2.c
|
||||||
|
|
||||||
|
BACKEND_GRX {
|
||||||
|
LINUX = $$PWD/../installed/linux
|
||||||
|
DEFINES += BACKEND_GRX
|
||||||
|
INCLUDEPATH += $$LINUX/include
|
||||||
LIBS += \
|
LIBS += \
|
||||||
-L$$LINUX/lib \
|
-L$$LINUX/lib \
|
||||||
-lgrx20X \
|
-lgrx20X \
|
||||||
|
@ -40,3 +53,13 @@ LIBS += \
|
||||||
-ljpeg \
|
-ljpeg \
|
||||||
-lpng \
|
-lpng \
|
||||||
-lz
|
-lz
|
||||||
|
}
|
||||||
|
|
||||||
|
BACKEND_SDL2 {
|
||||||
|
DEFINES += BACKEND_SDL2
|
||||||
|
}
|
||||||
|
|
||||||
|
BACKEND_DJGPP
|
||||||
|
DEFINES += BACKEND_DJGPP
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,95 +3,46 @@
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct VideoModeS {
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int depth;
|
|
||||||
} VideoModeT;
|
|
||||||
|
|
||||||
typedef struct WidgetCatalogS {
|
typedef struct WidgetCatalogS {
|
||||||
uint8_t key; // Magic
|
uint8_t key; // Magic
|
||||||
RegisterT *value;
|
RegisterT *value;
|
||||||
} WidgetCatalogT;
|
} WidgetCatalogT;
|
||||||
|
|
||||||
|
|
||||||
GrColor *__guiBaseColors = NULL;
|
ColorT *__guiBaseColors = NULL;
|
||||||
GrContext *__guiBackBuffer = NULL;
|
SurfaceT *__guiBackBuffer = NULL;
|
||||||
GrContext *__guiScreenBuffer = NULL;
|
SurfaceT *__guiScreenBuffer = NULL;
|
||||||
|
|
||||||
|
|
||||||
static uint8_t _magicCount = 0;
|
static uint8_t _magicCount = 0;
|
||||||
static WidgetCatalogT *_widgetCatalog = NULL;
|
static WidgetCatalogT *_widgetCatalog = NULL;
|
||||||
static uint8_t _guiRunning = 1;
|
static uint8_t _guiRunning = 1;
|
||||||
static GrContext *_mousePointer = NULL;
|
static SurfaceT *_mousePointer = NULL;
|
||||||
static GrColor _mouseTransparency;
|
static ColorT _mouseTransparency;
|
||||||
|
|
||||||
|
|
||||||
// This is a total hack to prevent GRX from drawing the mouse pointer.
|
|
||||||
extern struct _GR_mouseInfo _GrMouseInfo;
|
|
||||||
|
|
||||||
|
|
||||||
void guiModesShow(void) {
|
|
||||||
VideoModeT mode[256];
|
|
||||||
int32_t modeCount = 0;
|
|
||||||
int32_t i;
|
|
||||||
GrFrameMode fm;
|
|
||||||
const GrVideoMode *mp;
|
|
||||||
|
|
||||||
GrSetDriver(NULL);
|
|
||||||
if (GrCurrentVideoDriver() == NULL) {
|
|
||||||
printf("No graphics driver found!\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (fm=GR_firstGraphicsFrameMode; fm<=GR_lastGraphicsFrameMode; fm++) {
|
|
||||||
mp = GrFirstVideoMode(fm);
|
|
||||||
while (mp != NULL) {
|
|
||||||
if (mp->width >= 640 && mp->height >= 480 && mp->bpp >= 8) {
|
|
||||||
mode[modeCount].width = mp->width;
|
|
||||||
mode[modeCount].height = mp->height;
|
|
||||||
mode[modeCount].depth = mp->bpp;
|
|
||||||
modeCount++;
|
|
||||||
}
|
|
||||||
mp = GrNextVideoMode(mp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GrSetMode(GR_default_text);
|
|
||||||
|
|
||||||
printf("Available graphics modes:\n\n");
|
|
||||||
for (i=0; i<modeCount; i++) {
|
|
||||||
printf("%4d x %4d %2d bpp\n", mode[i].width, mode[i].height, mode[i].depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
GrKeyRead();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void guiRun(void) {
|
void guiRun(void) {
|
||||||
GrMouseEvent event;
|
EventT event;
|
||||||
|
|
||||||
while (_guiRunning) {
|
while (_guiRunning) {
|
||||||
// Read mouse & keyboard.
|
// Read mouse & keyboard.
|
||||||
GrMouseGetEventT(GR_M_EVENT, &event, 0);
|
platformEventGet(&event);
|
||||||
|
|
||||||
// Paint desktop.
|
// Paint desktop.
|
||||||
GrSetContext(__guiBackBuffer);
|
videoSurfaceSet(__guiBackBuffer);
|
||||||
GrClearContext(GUI_CYAN);
|
videoSurfaceClear(GUI_CYAN);
|
||||||
|
|
||||||
// Paint GUI.
|
// Paint GUI.
|
||||||
wmPaint(&event);
|
wmPaint(&event);
|
||||||
|
|
||||||
// Paint mouse pointer.
|
// Paint mouse pointer.
|
||||||
GrBitBlt(__guiBackBuffer, event.x, event.y, _mousePointer, 0, 0, _mousePointer->gc_xmax, _mousePointer->gc_ymax, GrIMAGE | _mouseTransparency);
|
videoSurfaceBlitWithTransparency(__guiBackBuffer, event.x, event.y, _mousePointer, _mouseTransparency);
|
||||||
|
|
||||||
// Copy to screen.
|
// Copy to screen.
|
||||||
GrBitBltNC(__guiScreenBuffer, 0, 0, __guiBackBuffer, 0, 0, __guiBackBuffer->gc_xmax, __guiBackBuffer->gc_ymax, GrWRITE);
|
videoSurfaceBlit(__guiScreenBuffer, 0, 0, __guiBackBuffer);
|
||||||
|
|
||||||
// Emergency Exit?
|
// Emergency Exit?
|
||||||
if (event.flags & GR_M_KEYPRESS && event.key == GrKey_Escape) guiStop();
|
if (event.flags & EVENT_FLAG_KEYPRESS && event.key == KEY_ESC) guiStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,45 +62,26 @@ void guiShutdown(void) {
|
||||||
hmfree(_widgetCatalog);
|
hmfree(_widgetCatalog);
|
||||||
|
|
||||||
wmShutdown();
|
wmShutdown();
|
||||||
|
mouseShutdown();
|
||||||
|
|
||||||
GrMouseEraseCursor();
|
videoSurfaceDestroy(_mousePointer);
|
||||||
GrMouseUnInit();
|
videoSurfaceDestroy(__guiBackBuffer);
|
||||||
|
|
||||||
GrDestroyContext(_mousePointer);
|
videoShutdown();
|
||||||
|
|
||||||
GrDestroyContext(__guiBackBuffer);
|
|
||||||
GrSetMode(GR_default_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void guiStartup(int16_t width, int16_t height, int16_t depth) {
|
void guiStartup(int16_t width, int16_t height, int16_t depth) {
|
||||||
|
|
||||||
int32_t x;
|
videoStartup(width, height, depth);
|
||||||
int32_t y;
|
|
||||||
|
|
||||||
// Set up graphics environment.
|
__guiScreenBuffer = videoSurfaceScreenGet();
|
||||||
if (!GrSetMode(GR_width_height_bpp_graphics, width, height, depth)) {
|
__guiBackBuffer = videoSurfaceCreate(videoDisplayWidthGet(), videoDisplayHeightGet());
|
||||||
//***TODO*** Die
|
|
||||||
}
|
|
||||||
GrSetRGBcolorMode();
|
|
||||||
__guiBaseColors = GrAllocEgaColors(); // This does not need released.
|
|
||||||
__guiScreenBuffer = GrScreenContext();
|
|
||||||
__guiBackBuffer = GrCreateContext(GrScreenX(), GrScreenY(), NULL, NULL);
|
|
||||||
|
|
||||||
// Set up mouse.
|
mouseStartup();
|
||||||
GrMouseInit();
|
|
||||||
GrMouseEventEnable(1, 1);
|
|
||||||
GrMouseSetCursorMode(GR_M_CUR_NORMAL);
|
|
||||||
// This is a total hack to prevent GRX from drawing the mouse pointer.
|
|
||||||
_GrMouseInfo.cursor = NULL;
|
|
||||||
|
|
||||||
// Load mouse pointer.
|
_mousePointer = imageLoad("mouse.png");
|
||||||
if (!GrQueryPng("mouse.png", &x, &y)) {
|
_mouseTransparency = videoSurfacePixelGet(_mousePointer, videoSurfaceWidthGet(_mousePointer) - 2, 0); // Find our transparency color.
|
||||||
//***TODO*** Die
|
|
||||||
}
|
|
||||||
_mousePointer = GrCreateContext(x, y, NULL, NULL);
|
|
||||||
GrLoadContextFromPng(_mousePointer, "mouse.png", 0);
|
|
||||||
_mouseTransparency = GrPixelC(_mousePointer, x - 1, 0); // Find our transparency color.
|
|
||||||
|
|
||||||
wmStartup();
|
wmStartup();
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
#define GUI_H
|
#define GUI_H
|
||||||
|
|
||||||
|
|
||||||
#include "grx20.h"
|
|
||||||
#include "grxkeys.h"
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,9 +44,9 @@ typedef struct WidgetS {
|
||||||
typedef RegisterT *(*WidgetRegisterT)(uint8_t);
|
typedef RegisterT *(*WidgetRegisterT)(uint8_t);
|
||||||
|
|
||||||
|
|
||||||
extern GrContext *__guiBackBuffer;
|
extern SurfaceT *__guiBackBuffer;
|
||||||
extern GrContext *__guiScreenBuffer;
|
extern SurfaceT *__guiScreenBuffer;
|
||||||
extern GrColor *__guiBaseColors;
|
extern ColorT *__guiBaseColors;
|
||||||
|
|
||||||
|
|
||||||
#define GUI_BLACK __guiBaseColors[0]
|
#define GUI_BLACK __guiBaseColors[0]
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
uint8_t __MAGIC_WINDOW = 0;
|
uint8_t __MAGIC_WINDOW = 0;
|
||||||
|
|
||||||
static WindowT **_windowList = NULL;
|
static WindowT **_windowList = NULL;
|
||||||
static GrTextOption _textOption;
|
|
||||||
|
|
||||||
|
|
||||||
WindowT *windowCreate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *title, uint8_t flags, ...) {
|
WindowT *windowCreate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, char *title, uint8_t flags, ...) {
|
||||||
|
@ -54,17 +53,17 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
uint16_t tx2;
|
uint16_t tx2;
|
||||||
uint16_t ty2;
|
uint16_t ty2;
|
||||||
uint16_t minimizeOffset = 0;
|
uint16_t minimizeOffset = 0;
|
||||||
GrColor titleBackgroundColor = GUI_DARKGRAY;
|
ColorT titleBackgroundColor = GUI_DARKGRAY;
|
||||||
|
|
||||||
// Fake Window contents.
|
// Fake Window contents.
|
||||||
GrFilledBox(x1, y1, x2, y2, GUI_BLACK);
|
videoSurfaceBoxFilled(x1, y1, x2, y2, GUI_BLACK);
|
||||||
|
|
||||||
// If we need a titlebar, it's 18px.
|
// If we need a titlebar, it's 18px.
|
||||||
if (w->title || w->flags & WIN_CLOSE || w->flags & WIN_MAXIMIZE || w->flags & WIN_MINIMIZE) {
|
if (w->title || w->flags & WIN_CLOSE || w->flags & WIN_MAXIMIZE || w->flags & WIN_MINIMIZE) {
|
||||||
|
|
||||||
// Draw title bar background.
|
// Draw title bar background.
|
||||||
y1 -= 18;
|
y1 -= 18;
|
||||||
GrFilledBox(x1, y1, x2, y1 + 17, titleBackgroundColor);
|
videoSurfaceBoxFilled(x1, y1, x2, y1 + 17, titleBackgroundColor);
|
||||||
|
|
||||||
// Close box?
|
// Close box?
|
||||||
if (w->flags & WIN_CLOSE) {
|
if (w->flags & WIN_CLOSE) {
|
||||||
|
@ -73,18 +72,18 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
w->close.y = y1 + 1;
|
w->close.y = y1 + 1;
|
||||||
w->close.x2 = w->close.x + 24;
|
w->close.x2 = w->close.x + 24;
|
||||||
w->close.y2 = w->close.y + 15;
|
w->close.y2 = w->close.y + 15;
|
||||||
GrFilledBox(w->close.x + 1, w->close.y + 1, w->close.x2 - 1, w->close.y2 - 1, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(w->close.x + 1, w->close.y + 1, w->close.x2 - 1, w->close.y2 - 1, GUI_LIGHTGRAY);
|
||||||
GrHLine(w->close.x, w->close.x2, w->close.y, GUI_WHITE);
|
videoSurfaceLineH(w->close.x, w->close.x2, w->close.y, GUI_WHITE);
|
||||||
GrVLine(w->close.x, w->close.y, w->close.y2, GUI_WHITE);
|
videoSurfaceLineV(w->close.x, w->close.y, w->close.y2, GUI_WHITE);
|
||||||
// Button is 8px down, 3px tall, and 4px in on both sides.
|
// Button is 8px down, 3px tall, and 4px in on both sides.
|
||||||
tx1 = w->close.x + 4;
|
tx1 = w->close.x + 4;
|
||||||
ty1 = w->close.y + 7;
|
ty1 = w->close.y + 7;
|
||||||
tx2 = w->close.x2 - 4;
|
tx2 = w->close.x2 - 4;
|
||||||
ty2 = w->close.y + 9;
|
ty2 = w->close.y + 9;
|
||||||
GrHLine(tx1, tx2, ty1, GUI_WHITE);
|
videoSurfaceLineH(tx1, tx2, ty1, GUI_WHITE);
|
||||||
GrPlot(tx1, ty1 + 1, GUI_WHITE);
|
videoSurfacePixelSet(tx1, ty1 + 1, GUI_WHITE);
|
||||||
GrHLine(tx1, tx2, ty2, GUI_BLACK);
|
videoSurfaceLineH(tx1, tx2, ty2, GUI_BLACK);
|
||||||
GrVLine(tx2, ty1, ty2, GUI_BLACK);
|
videoSurfaceLineV(tx2, ty1, ty2, GUI_BLACK);
|
||||||
// Set titlebar area.
|
// Set titlebar area.
|
||||||
w->titlebar.x = w->close.x2 + 2;
|
w->titlebar.x = w->close.x2 + 2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -102,18 +101,18 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
w->maximize.x2 = x2 - 1;
|
w->maximize.x2 = x2 - 1;
|
||||||
w->maximize.x = w->maximize.x2 - 24;
|
w->maximize.x = w->maximize.x2 - 24;
|
||||||
w->maximize.y2 = w->maximize.y + 15;
|
w->maximize.y2 = w->maximize.y + 15;
|
||||||
GrFilledBox(w->maximize.x + 1, w->maximize.y + 1, w->maximize.x2 - 1, w->maximize.y2 - 1, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(w->maximize.x + 1, w->maximize.y + 1, w->maximize.x2 - 1, w->maximize.y2 - 1, GUI_LIGHTGRAY);
|
||||||
GrHLine(w->maximize.x, w->maximize.x2, w->maximize.y, GUI_WHITE);
|
videoSurfaceLineH(w->maximize.x, w->maximize.x2, w->maximize.y, GUI_WHITE);
|
||||||
GrVLine(w->maximize.x, w->maximize.y, w->maximize.y2, GUI_WHITE);
|
videoSurfaceLineV(w->maximize.x, w->maximize.y, w->maximize.y2, GUI_WHITE);
|
||||||
// Button is 3px down, and 4px in on both sides.
|
// Button is 3px down, and 4px in on both sides.
|
||||||
tx1 = w->maximize.x + 4;
|
tx1 = w->maximize.x + 4;
|
||||||
ty1 = w->maximize.y + 4;
|
ty1 = w->maximize.y + 4;
|
||||||
tx2 = w->maximize.x2 - 3;
|
tx2 = w->maximize.x2 - 3;
|
||||||
ty2 = w->maximize.y + 12;
|
ty2 = w->maximize.y + 12;
|
||||||
GrHLine(tx1, tx2, ty1, GUI_WHITE);
|
videoSurfaceLineH(tx1, tx2, ty1, GUI_WHITE);
|
||||||
GrVLine(tx1, ty1, ty2, GUI_WHITE);
|
videoSurfaceLineV(tx1, ty1, ty2, GUI_WHITE);
|
||||||
GrHLine(tx1, tx2, ty2, GUI_BLACK);
|
videoSurfaceLineH(tx1, tx2, ty2, GUI_BLACK);
|
||||||
GrVLine(tx2, ty1, ty2, GUI_BLACK);
|
videoSurfaceLineV(tx2, ty1, ty2, GUI_BLACK);
|
||||||
// Move minimize button over.
|
// Move minimize button over.
|
||||||
minimizeOffset = 26;
|
minimizeOffset = 26;
|
||||||
// Set titlebar area.
|
// Set titlebar area.
|
||||||
|
@ -127,31 +126,29 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
w->minimize.x2 = x2 - 1 - minimizeOffset;
|
w->minimize.x2 = x2 - 1 - minimizeOffset;
|
||||||
w->minimize.x = w->minimize.x2 - 24;
|
w->minimize.x = w->minimize.x2 - 24;
|
||||||
w->minimize.y2 = w->minimize.y + 15;
|
w->minimize.y2 = w->minimize.y + 15;
|
||||||
GrFilledBox(w->minimize.x + 1, w->minimize.y + 1, w->minimize.x2 - 1, w->minimize.y2 - 1, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(w->minimize.x + 1, w->minimize.y + 1, w->minimize.x2 - 1, w->minimize.y2 - 1, GUI_LIGHTGRAY);
|
||||||
GrHLine(w->minimize.x, w->minimize.x2, w->minimize.y, GUI_WHITE);
|
videoSurfaceLineH(w->minimize.x, w->minimize.x2, w->minimize.y, GUI_WHITE);
|
||||||
GrVLine(w->minimize.x, w->minimize.y, w->minimize.y2, GUI_WHITE);
|
videoSurfaceLineV(w->minimize.x, w->minimize.y, w->minimize.y2, GUI_WHITE);
|
||||||
tx1 = w->minimize.x + 10;
|
tx1 = w->minimize.x + 10;
|
||||||
ty1 = w->minimize.y + 6;
|
ty1 = w->minimize.y + 6;
|
||||||
tx2 = w->minimize.x2 - 8;
|
tx2 = w->minimize.x2 - 8;
|
||||||
ty2 = w->minimize.y + 9;
|
ty2 = w->minimize.y + 9;
|
||||||
GrHLine(tx1, tx2, ty1, GUI_WHITE);
|
videoSurfaceLineH(tx1, tx2, ty1, GUI_WHITE);
|
||||||
GrVLine(tx1, ty1, ty2, GUI_WHITE);
|
videoSurfaceLineV(tx1, ty1, ty2, GUI_WHITE);
|
||||||
GrHLine(tx1, tx2, ty2, GUI_BLACK);
|
videoSurfaceLineH(tx1, tx2, ty2, GUI_BLACK);
|
||||||
GrVLine(tx2, ty1, ty2, GUI_BLACK);
|
videoSurfaceLineV(tx2, ty1, ty2, GUI_BLACK);
|
||||||
// Set titlebar area.
|
// Set titlebar area.
|
||||||
w->titlebar.x2 -= 26;
|
w->titlebar.x2 -= 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Title font area is 12px high.
|
// Title font area is 12px high.
|
||||||
GrHLine(w->titlebar.x, w->titlebar.x2 - 1, w->titlebar.y, GUI_WHITE);
|
videoSurfaceLineH(w->titlebar.x, w->titlebar.x2 - 1, w->titlebar.y, GUI_WHITE);
|
||||||
GrVLine(w->titlebar.x, w->titlebar.y, w->titlebar.y2 - 1, GUI_WHITE);
|
videoSurfaceLineV(w->titlebar.x, w->titlebar.y, w->titlebar.y2 - 1, GUI_WHITE);
|
||||||
if (w->title) {
|
if (w->title) {
|
||||||
//***TODO*** Look into GrTextRegion
|
|
||||||
_textOption.txo_bgcolor.v = titleBackgroundColor;
|
|
||||||
ty1 = w->titlebar.y + 2;
|
ty1 = w->titlebar.y + 2;
|
||||||
tx1 = w->titlebar.x + 2 + (w->titlebar.x2 - w->titlebar.x - 4) * 0.5 - (GrStringWidth(w->title, strlen(w->title), &_textOption) * 0.5);
|
tx1 = w->titlebar.x + 2 + (w->titlebar.x2 - w->titlebar.x - 4) * 0.5 - ((strlen(w->title) * 8) * 0.5);
|
||||||
//***TODO*** Does not handle text being clipped.
|
//***TODO*** Does not handle text being clipped.
|
||||||
GrDrawString(w->title, strlen(w->title), tx1, ty1, &_textOption);
|
fontWrite(w->title, tx1, ty1, &FONT_VGA_8x14, GUI_WHITE, titleBackgroundColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,29 +157,29 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
y1--;
|
y1--;
|
||||||
x2++;
|
x2++;
|
||||||
y2++;
|
y2++;
|
||||||
GrHLine(x1, x2, y2, GUI_WHITE);
|
videoSurfaceLineH(x1, x2, y2, GUI_WHITE);
|
||||||
GrVLine(x2, y1, y2, GUI_WHITE);
|
videoSurfaceLineV(x2, y1, y2, GUI_WHITE);
|
||||||
GrHLine(x1, x2, y1, GUI_DARKGRAY);
|
videoSurfaceLineH(x1, x2, y1, GUI_DARKGRAY);
|
||||||
GrVLine(x1, y1, y2, GUI_DARKGRAY);
|
videoSurfaceLineV(x1, y1, y2, GUI_DARKGRAY);
|
||||||
|
|
||||||
// Frame Border. 4px wide.
|
// Frame Border. 4px wide.
|
||||||
x1 -= 4;
|
x1 -= 4;
|
||||||
y1 -= 4;
|
y1 -= 4;
|
||||||
x2 += 4;
|
x2 += 4;
|
||||||
y2 += 4;
|
y2 += 4;
|
||||||
GrFilledBox(x1, y1, x1 + 3, y2, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(x1, y1, x1 + 3, y2, GUI_LIGHTGRAY);
|
||||||
GrFilledBox(x2, y1, x2 - 3, y2, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(x2, y1, x2 - 3, y2, GUI_LIGHTGRAY);
|
||||||
GrFilledBox(x1, y1, x2, y1 + 3, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(x1, y1, x2, y1 + 3, GUI_LIGHTGRAY);
|
||||||
GrFilledBox(x1, y2, x2, y2 - 3, GUI_LIGHTGRAY);
|
videoSurfaceBoxFilled(x1, y2, x2, y2 - 3, GUI_LIGHTGRAY);
|
||||||
|
|
||||||
// Resize handle.
|
// Resize handle.
|
||||||
if (w->flags & WIN_RESIZE) {
|
if (w->flags & WIN_RESIZE) {
|
||||||
ty1 = y2 - 15 - 3;
|
ty1 = y2 - 15 - 3;
|
||||||
tx1 = x2 - 15 - 3;
|
tx1 = x2 - 15 - 3;
|
||||||
GrHLine(x2, x2 - 3, ty1, GUI_DARKGRAY);
|
videoSurfaceLineH(x2, x2 - 3, ty1, GUI_DARKGRAY);
|
||||||
GrHLine(x2, x2 - 3, ty1 + 1, GUI_WHITE);
|
videoSurfaceLineH(x2, x2 - 3, ty1 + 1, GUI_WHITE);
|
||||||
GrVLine(tx1, y2, y2 - 3, GUI_DARKGRAY);
|
videoSurfaceLineV(tx1, y2, y2 - 3, GUI_DARKGRAY);
|
||||||
GrVLine(tx1 + 1, y2, y2 - 3, GUI_WHITE);
|
videoSurfaceLineV(tx1 + 1, y2, y2 - 3, GUI_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outermost shadow frame. 1px wide.
|
// Outermost shadow frame. 1px wide.
|
||||||
|
@ -190,10 +187,10 @@ void windowPaint(struct WidgetS *widget, ...) {
|
||||||
y1--;
|
y1--;
|
||||||
x2++;
|
x2++;
|
||||||
y2++;
|
y2++;
|
||||||
GrHLine(x1, x2, y1, GUI_WHITE);
|
videoSurfaceLineH(x1, x2, y1, GUI_WHITE);
|
||||||
GrVLine(x1, y1, y2, GUI_WHITE);
|
videoSurfaceLineV(x1, y1, y2, GUI_WHITE);
|
||||||
GrHLine(x1, x2, y2, GUI_DARKGRAY);
|
videoSurfaceLineH(x1, x2, y2, GUI_DARKGRAY);
|
||||||
GrVLine(x2, y1, y2, GUI_DARKGRAY);
|
videoSurfaceLineV(x2, y1, y2, GUI_DARKGRAY);
|
||||||
w->bounds.x = x1;
|
w->bounds.x = x1;
|
||||||
w->bounds.x2 = x2;
|
w->bounds.x2 = x2;
|
||||||
w->bounds.y = y1;
|
w->bounds.y = y1;
|
||||||
|
@ -212,20 +209,12 @@ RegisterT *windowRegister(uint8_t magic) {
|
||||||
// One-time widget startup code.
|
// One-time widget startup code.
|
||||||
__MAGIC_WINDOW = magic;
|
__MAGIC_WINDOW = magic;
|
||||||
|
|
||||||
_textOption.txo_bgcolor.v = GUI_DARKGRAY;
|
|
||||||
_textOption.txo_fgcolor.v = GUI_WHITE;
|
|
||||||
_textOption.txo_chrtype = GR_BYTE_TEXT;
|
|
||||||
_textOption.txo_direct = GR_TEXT_RIGHT;
|
|
||||||
_textOption.txo_font = &GrFont_PC8x14;
|
|
||||||
_textOption.txo_xalign = GR_ALIGN_DEFAULT;
|
|
||||||
_textOption.txo_yalign = GR_ALIGN_DEFAULT;
|
|
||||||
|
|
||||||
return ®
|
return ®
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wmPaint(GrMouseEvent *event) {
|
void wmPaint(EventT *event) {
|
||||||
uint16_t i;
|
int16_t i;
|
||||||
WidgetT *widget;
|
WidgetT *widget;
|
||||||
WindowT *win;
|
WindowT *win;
|
||||||
static uint8_t dragging = 0;
|
static uint8_t dragging = 0;
|
||||||
|
@ -236,7 +225,7 @@ void wmPaint(GrMouseEvent *event) {
|
||||||
|
|
||||||
// Paint all windows.
|
// Paint all windows.
|
||||||
for (i=0; i<arrlen(_windowList); i++) {
|
for (i=0; i<arrlen(_windowList); i++) {
|
||||||
GrSetContext(__guiBackBuffer);
|
videoSurfaceSet(__guiBackBuffer);
|
||||||
widget = (WidgetT *)_windowList[i];
|
widget = (WidgetT *)_windowList[i];
|
||||||
widget->reg->paint(widget);
|
widget->reg->paint(widget);
|
||||||
}
|
}
|
||||||
|
@ -247,15 +236,15 @@ void wmPaint(GrMouseEvent *event) {
|
||||||
// Wrap left button processing with a 'for' so we can 'break' out of it.
|
// Wrap left button processing with a 'for' so we can 'break' out of it.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Is the left mouse button down?
|
// Is the left mouse button down?
|
||||||
if (event->buttons & GR_M_LEFT) {
|
if (event->buttons & BUTTON_LEFT) {
|
||||||
|
|
||||||
// DEBUG - draw active regions. ***TODO*** No resize grabber here.
|
// DEBUG - draw active regions. ***TODO*** No resize grabber here.
|
||||||
GrBox(win->bounds.x, win->bounds.y, win->bounds.x2, win->bounds.y2, GUI_YELLOW);
|
videoSurfaceBox(win->bounds.x, win->bounds.y, win->bounds.x2, win->bounds.y2, GUI_YELLOW);
|
||||||
GrBox(win->base.r.x, win->base.r.y, win->base.r.x + win->base.r.w - 1, win->base.r.y + win->base.r.h - 1, GUI_YELLOW);
|
videoSurfaceBox(win->base.r.x, win->base.r.y, win->base.r.x + win->base.r.w - 1, win->base.r.y + win->base.r.h - 1, GUI_YELLOW);
|
||||||
GrBox(win->close.x, win->close.y, win->close.x2, win->close.y2, GUI_RED);
|
videoSurfaceBox(win->close.x, win->close.y, win->close.x2, win->close.y2, GUI_RED);
|
||||||
GrBox(win->titlebar.x, win->titlebar.y, win->titlebar.x2, win->titlebar.y2, GUI_RED);
|
videoSurfaceBox(win->titlebar.x, win->titlebar.y, win->titlebar.x2, win->titlebar.y2, GUI_RED);
|
||||||
GrBox(win->minimize.x, win->minimize.y, win->minimize.x2, win->minimize.y2, GUI_RED);
|
videoSurfaceBox(win->minimize.x, win->minimize.y, win->minimize.x2, win->minimize.y2, GUI_RED);
|
||||||
GrBox(win->maximize.x, win->maximize.y, win->maximize.x2, win->maximize.y2, GUI_RED);
|
videoSurfaceBox(win->maximize.x, win->maximize.y, win->maximize.x2, win->maximize.y2, GUI_RED);
|
||||||
|
|
||||||
// Are we currently dragging?
|
// Are we currently dragging?
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
|
@ -268,7 +257,7 @@ void wmPaint(GrMouseEvent *event) {
|
||||||
} else { // Dragging.
|
} else { // Dragging.
|
||||||
|
|
||||||
// Did the button just go down?
|
// Did the button just go down?
|
||||||
if (event->flags & GR_M_LEFT_DOWN) {
|
if (event->flags & EVENT_FLAG_LEFT_DOWN) {
|
||||||
|
|
||||||
// Are we on the topmost window?
|
// Are we on the topmost window?
|
||||||
if (event->x <= win->bounds.x2 && event->x >= win->bounds.x && event->y <= win->bounds.y2 && event->y >= win->bounds.y) {
|
if (event->x <= win->bounds.x2 && event->x >= win->bounds.x && event->y <= win->bounds.y2 && event->y >= win->bounds.y) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ void windowPaint(struct WidgetS *widget, ...);
|
||||||
RegisterT *windowRegister(uint8_t magic);
|
RegisterT *windowRegister(uint8_t magic);
|
||||||
|
|
||||||
|
|
||||||
void wmPaint(GrMouseEvent *event);
|
void wmPaint(EventT *event);
|
||||||
void wmShutdown(void);
|
void wmShutdown(void);
|
||||||
void wmStartup(void);
|
void wmStartup(void);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "platform/platform.h"
|
||||||
#include "stddclmr.h"
|
#include "stddclmr.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
7
client/src/platform/djgpp.c
Normal file
7
client/src/platform/djgpp.c
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifdef BACKEND_DJGPP
|
||||||
|
|
||||||
|
|
||||||
|
#include "djgpp.h"
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BACKEND_DJGPP
|
4
client/src/platform/djgpp.h
Normal file
4
client/src/platform/djgpp.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#ifndef DJGPP_H
|
||||||
|
#define DJGPP_H
|
||||||
|
|
||||||
|
#endif // DJGPP_H
|
143
client/src/platform/grx.c
Normal file
143
client/src/platform/grx.c
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
#ifdef BACKEND_GRX
|
||||||
|
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
#include "grx.h"
|
||||||
|
#include "../gui/gui.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct VideoModeS {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int depth;
|
||||||
|
} VideoModeT;
|
||||||
|
|
||||||
|
|
||||||
|
// This is a total hack to prevent GRX from drawing the mouse pointer.
|
||||||
|
extern struct _GR_mouseInfo _GrMouseInfo;
|
||||||
|
|
||||||
|
|
||||||
|
void fontWrite(char *message, int16_t x, int16_t y, FontT *font, ColorT foreground, ColorT background) {
|
||||||
|
|
||||||
|
GrTextOption textOption;
|
||||||
|
|
||||||
|
textOption.txo_bgcolor.v = background;
|
||||||
|
textOption.txo_fgcolor.v = foreground;
|
||||||
|
textOption.txo_chrtype = GR_BYTE_TEXT;
|
||||||
|
textOption.txo_direct = GR_TEXT_RIGHT;
|
||||||
|
textOption.txo_font = font;
|
||||||
|
textOption.txo_xalign = GR_ALIGN_DEFAULT;
|
||||||
|
textOption.txo_yalign = GR_ALIGN_DEFAULT;
|
||||||
|
|
||||||
|
//***TODO*** Look into GrTextRegion
|
||||||
|
GrDrawString(message, strlen(message), x, y, &textOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SurfaceT *imageLoad(char *filename) {
|
||||||
|
int32_t x;
|
||||||
|
int32_t y;
|
||||||
|
SurfaceT *image = 0;
|
||||||
|
|
||||||
|
if (!GrQueryPng(filename, &x, &y)) {
|
||||||
|
//***TODO*** Die
|
||||||
|
}
|
||||||
|
image = videoSurfaceCreate(x, y);
|
||||||
|
GrLoadContextFromPng(image, filename, 0);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mouseShutdown(void) {
|
||||||
|
GrMouseEraseCursor();
|
||||||
|
GrMouseUnInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mouseStartup(void) {
|
||||||
|
// Set up mouse.
|
||||||
|
GrMouseInit();
|
||||||
|
GrMouseEventEnable(1, 1);
|
||||||
|
GrMouseSetCursorMode(GR_M_CUR_NORMAL);
|
||||||
|
// This is a total hack to prevent GRX from drawing the mouse pointer.
|
||||||
|
_GrMouseInfo.cursor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void videoModesShow(void) {
|
||||||
|
VideoModeT mode[256];
|
||||||
|
int32_t modeCount = 0;
|
||||||
|
int32_t i;
|
||||||
|
GrFrameMode fm;
|
||||||
|
const GrVideoMode *mp;
|
||||||
|
|
||||||
|
GrSetDriver(0);
|
||||||
|
if (GrCurrentVideoDriver() == 0) {
|
||||||
|
printf("No graphics driver found!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (fm=GR_firstGraphicsFrameMode; fm<=GR_lastGraphicsFrameMode; fm++) {
|
||||||
|
mp = GrFirstVideoMode(fm);
|
||||||
|
while (mp != 0) {
|
||||||
|
if (mp->width >= 640 && mp->height >= 480 && mp->bpp >= 8) {
|
||||||
|
mode[modeCount].width = mp->width;
|
||||||
|
mode[modeCount].height = mp->height;
|
||||||
|
mode[modeCount].depth = mp->bpp;
|
||||||
|
modeCount++;
|
||||||
|
}
|
||||||
|
mp = GrNextVideoMode(mp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrSetMode(GR_default_text);
|
||||||
|
|
||||||
|
printf("Available graphics modes:\n\n");
|
||||||
|
for (i=0; i<modeCount; i++) {
|
||||||
|
printf("%4d x %4d %2d bpp\n", mode[i].width, mode[i].height, mode[i].depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrKeyRead();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void videoShutdown(void) {
|
||||||
|
GrSetMode(GR_default_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void videoStartup(int16_t width, int16_t height, int16_t depth) {
|
||||||
|
// Set up graphics environment.
|
||||||
|
if (!GrSetMode(GR_width_height_bpp_graphics, width, height, depth)) {
|
||||||
|
//***TODO*** Die
|
||||||
|
}
|
||||||
|
GrSetRGBcolorMode();
|
||||||
|
__guiBaseColors = GrAllocEgaColors(); // This does not need released.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void videoSurfaceBlit(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source) {
|
||||||
|
GrBitBlt(target, targetX, targetY, source, 0, 0, videoSurfaceWidthGet(source) - 1, videoSurfaceHeightGet(source) - 1, GrWRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void videoSurfaceBlitWithTransparency(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source, ColorT transparent) {
|
||||||
|
GrBitBlt(target, targetX, targetY, source, 0, 0, videoSurfaceWidthGet(source) - 1, videoSurfaceHeightGet(source) - 1, GrIMAGE | transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int16_t videoSurfaceHeightGet(SurfaceT *surface) {
|
||||||
|
return surface->gc_ymax + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int16_t videoSurfaceWidthGet(SurfaceT *surface) {
|
||||||
|
return surface->gc_xmax + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BACKEND_GRX
|
54
client/src/platform/grx.h
Normal file
54
client/src/platform/grx.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#ifndef GRX_H
|
||||||
|
#define GRX_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
#include "grx20.h"
|
||||||
|
#include "grxkeys.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef GrColor ColorT;
|
||||||
|
typedef GrContext SurfaceT;
|
||||||
|
typedef GrMouseEvent EventT;
|
||||||
|
typedef GrFont FontT;
|
||||||
|
|
||||||
|
|
||||||
|
#define EVENT_FLAG_KEYPRESS GR_M_KEYPRESS
|
||||||
|
#define EVENT_FLAG_LEFT_DOWN GR_M_LEFT_DOWN
|
||||||
|
|
||||||
|
#define BUTTON_LEFT GR_M_LEFT
|
||||||
|
|
||||||
|
#define KEY_ESC GrKey_Escape
|
||||||
|
|
||||||
|
#define FONT_VGA_8x14 GrFont_PC8x14
|
||||||
|
|
||||||
|
|
||||||
|
#define platformEventGet(p) GrMouseGetEventT(GR_M_EVENT, p, 0)
|
||||||
|
|
||||||
|
#define videoDisplayHeightGet GrScreenY
|
||||||
|
#define videoDisplayWidthGet GrScreenX
|
||||||
|
#define videoSurfaceClear GrClearContext
|
||||||
|
#define videoSurfaceCreate(w,h) GrCreateContext(w,h,0,0)
|
||||||
|
#define videoSurfaceDestroy GrDestroyContext
|
||||||
|
#define videoSurfaceBox GrBox
|
||||||
|
#define videoSurfaceBoxFilled GrFilledBox
|
||||||
|
#define videoSurfaceLineH GrHLine
|
||||||
|
#define videoSurfaceLineV GrVLine
|
||||||
|
#define videoSurfacePixelGet GrPixelC
|
||||||
|
#define videoSurfacePixelSet GrPlot
|
||||||
|
#define videoSurfaceSet GrSetContext
|
||||||
|
#define videoSurfaceScreenGet GrScreenContext
|
||||||
|
|
||||||
|
|
||||||
|
void fontWrite(char *message, int16_t x, int16_t y, FontT *font, ColorT foreground, ColorT background);
|
||||||
|
|
||||||
|
SurfaceT *imageLoad(char *filename);
|
||||||
|
|
||||||
|
void videoSurfaceBlit(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source);
|
||||||
|
void videoSurfaceBlitWithTransparency(SurfaceT *target, int16_t targetX, int16_t targetY, SurfaceT *source, ColorT transparent);
|
||||||
|
int16_t videoSurfaceHeightGet(SurfaceT *surface);
|
||||||
|
int16_t videoSurfaceWidthGet(SurfaceT *surface);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // GRX_H
|
29
client/src/platform/platform.h
Normal file
29
client/src/platform/platform.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef PLATFORM_H
|
||||||
|
#define PLATFORM_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BACKEND_GRX
|
||||||
|
#include "grx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BACKEND_SDL2
|
||||||
|
#include "sdl2.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BACKEND_DJGPP
|
||||||
|
#include "djgpp.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void mouseShutdown(void);
|
||||||
|
void mouseStartup(void);
|
||||||
|
|
||||||
|
void videoModesShow(void);
|
||||||
|
void videoShutdown(void);
|
||||||
|
void videoStartup(int16_t width, int16_t height, int16_t depth);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PLATFORM_H
|
7
client/src/platform/sdl2.c
Normal file
7
client/src/platform/sdl2.c
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifdef BACKEND_SDL2
|
||||||
|
|
||||||
|
|
||||||
|
#include "linux.h"
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BACKEND_SDL2
|
4
client/src/platform/sdl2.h
Normal file
4
client/src/platform/sdl2.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#ifndef SDL2_H
|
||||||
|
#define SDL2_H
|
||||||
|
|
||||||
|
#endif // SDL2_H
|
Loading…
Add table
Reference in a new issue