From 3ba067d964b68f9bc6c2dac97fbe09d181297eb9 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 3 Jul 2013 17:43:16 +0800 Subject: [PATCH] Usermode/AxWin3 - SDL Edition of the WM, runs but no output --- Usermode/Applications/axwin3_src/Makefile.sdl | 0 .../Applications/axwin3_src/WM/Makefile.sdl | 16 ++++ .../Applications/axwin3_src/WM/input_SDL.c | 20 +++++ .../Applications/axwin3_src/WM/main_SDL.c | 55 ++++++++++++ .../Applications/axwin3_src/WM/video_SDL.c | 88 +++++++++++++++++++ Usermode/Applications/axwin3_src/sdl.mk | 54 ++++++++++++ 6 files changed, 233 insertions(+) create mode 100644 Usermode/Applications/axwin3_src/Makefile.sdl create mode 100644 Usermode/Applications/axwin3_src/WM/Makefile.sdl create mode 100644 Usermode/Applications/axwin3_src/WM/input_SDL.c create mode 100644 Usermode/Applications/axwin3_src/WM/main_SDL.c create mode 100644 Usermode/Applications/axwin3_src/WM/video_SDL.c create mode 100644 Usermode/Applications/axwin3_src/sdl.mk diff --git a/Usermode/Applications/axwin3_src/Makefile.sdl b/Usermode/Applications/axwin3_src/Makefile.sdl new file mode 100644 index 00000000..e69de29b diff --git a/Usermode/Applications/axwin3_src/WM/Makefile.sdl b/Usermode/Applications/axwin3_src/WM/Makefile.sdl new file mode 100644 index 00000000..cb5bacfb --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/Makefile.sdl @@ -0,0 +1,16 @@ +# +# Acess2 GUI (AxWin3) WM +# - By John Hodge (thePowersGang) +# +# Makefile.sdl +# - SDL-backed edition makefile +# + +OBJ := main_SDL.o video_SDL.o input_SDL.o +include common.mk + +BIN := AxWinWM + +include ../sdl.mk + +# vim: ft=make diff --git a/Usermode/Applications/axwin3_src/WM/input_SDL.c b/Usermode/Applications/axwin3_src/WM/input_SDL.c new file mode 100644 index 00000000..3c9c3133 --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/input_SDL.c @@ -0,0 +1,20 @@ +/* + * Acess2 GUI (AxWin3) WM + * - By John Hodge (thePowersGang) + * + * input_SDL.c + * - SDL build input translation + */ +#include + +// === CODE === +int Input_Init(void) +{ + return 0; +} + +void InputSDL_HandleMouseBtn(const SDL_Event *ev) +{ + +} + diff --git a/Usermode/Applications/axwin3_src/WM/main_SDL.c b/Usermode/Applications/axwin3_src/WM/main_SDL.c new file mode 100644 index 00000000..d5787abb --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/main_SDL.c @@ -0,0 +1,55 @@ +/* + * Acess2 GUI (AxWin3) WM + * - By John Hodge (thePowersGang) + * + * main_SDL.c + * - SDL build main function + */ +#include +#include +#include + +// === IMPORTS === +extern void Video_Setup(void); +extern void WM_Initialise(void); +extern void WM_Update(void); + +// === CODE === +int main(int argc, char *argv[]) +{ + // Set up basic SDL environment + if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { + fprintf(stderr, "Unable to initialise SDL: %s\n", SDL_GetError()); + exit(1); + } + atexit(SDL_Quit); + + + Video_Setup(); + WM_Initialise(); + + // Main loop + printf("Entering idle loop\n"); + int bRunning = 1; + while(bRunning) + { + SDL_Event ev; + WM_Update(); + SDL_WaitEvent(&ev); + switch( ev.type ) + { + case SDL_QUIT: + bRunning = 0; + break; + case SDL_KEYDOWN: + break; + case SDL_USEREVENT: + break; + } + } + + // TODO: Clean up + + return 0; +} + diff --git a/Usermode/Applications/axwin3_src/WM/video_SDL.c b/Usermode/Applications/axwin3_src/WM/video_SDL.c new file mode 100644 index 00000000..d723dca1 --- /dev/null +++ b/Usermode/Applications/axwin3_src/WM/video_SDL.c @@ -0,0 +1,88 @@ +/* + * Acess2 GUI (AxWin3) WM + * - By John Hodge (thePowersGang) + * + * video_SDL.c + * - SDL build video output + */ +#include +#include +#include + +// === GLOBALS === +SDL_Surface *gScreen; + int giScreenWidth = 1280; + int giScreenHeight = 720; + +// === CODE === +void Video_Setup(void) +{ + gScreen = SDL_SetVideoMode(giScreenWidth, giScreenHeight, 32, SDL_SWSURFACE); + if( !gScreen ) { + fprintf(stderr, "Unable to set %ix%i video mode: %s\n", + giScreenWidth, giScreenHeight, + SDL_GetError()); + exit(1); + } + SDL_WM_SetCaption("Acess2 GUI v3", "AxWin3"); +} + +void Video_Update(void) +{ + SDL_Flip(gScreen); +} + +void Video_FillRect(int X, int Y, int W, int H, uint32_t Colour) +{ + SDL_Rect r = {.x = X, .y = Y, .w = W, .h = H}; + SDL_FillRect(gScreen, &r, Colour); +} + +void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H) +{ + printf("Blit (%p, (%i,%i) %ix%i)\n", + Source, DstX, DstY, W, H); + SDL_Rect r = {.x = DstX, .y = DstY, .w = W, .h = H}; + SDL_Surface *tmps = SDL_CreateRGBSurfaceFrom( + Source, W, H, 32, W*4, + 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000); + SDL_BlitSurface(tmps, NULL, gScreen, &r); +} + +uint32_t Video_AlphaBlend(uint32_t _orig, uint32_t _new, uint8_t _alpha) +{ + uint16_t ao,ro,go,bo; + uint16_t an,rn,gn,bn; + if( _alpha == 0 ) return _orig; + if( _alpha == 255 ) return _new; + + ao = (_orig >> 24) & 0xFF; + ro = (_orig >> 16) & 0xFF; + go = (_orig >> 8) & 0xFF; + bo = (_orig >> 0) & 0xFF; + + an = (_new >> 24) & 0xFF; + rn = (_new >> 16) & 0xFF; + gn = (_new >> 8) & 0xFF; + bn = (_new >> 0) & 0xFF; + + if( _alpha == 0x80 ) { + ao = (ao + an) / 2; + ro = (ro + rn) / 2; + go = (go + gn) / 2; + bo = (bo + bn) / 2; + } + else { + ao = ao*(255-_alpha) + an*_alpha; + ro = ro*(255-_alpha) + rn*_alpha; + go = go*(255-_alpha) + gn*_alpha; + bo = bo*(255-_alpha) + bn*_alpha; + ao /= 255*2; + ro /= 255*2; + go /= 255*2; + bo /= 255*2; + } + + return (ao << 24) | (ro << 16) | (go << 8) | bo; +} + diff --git a/Usermode/Applications/axwin3_src/sdl.mk b/Usermode/Applications/axwin3_src/sdl.mk new file mode 100644 index 00000000..4defaf1b --- /dev/null +++ b/Usermode/Applications/axwin3_src/sdl.mk @@ -0,0 +1,54 @@ +# +# Acess2 GUI (AxWin3) +# - By John Hodge (thePowersGang) +# +# sdl.mk +# - SDL-backed edition core definitions +# + +UMODEBASE := ../../../ +LIBBASE := $(UMODEBASE)Libraries/ +LIBOUTDIR := $(UMODEBASE)Output/host/Libs + +CPPFLAGS += -DAXWIN_SDL_BUILD=1 +CPPFLAGS += $(patsubst -l%,-I$(LIBBASE)lib%.so_src/include_exp,$(filter -l%,$(LDFLAGS))) +CPPFLAGS += -I$(LIBBASE)libaxwin3.so_src/include_exp +LIBS := $(patsubst -l%,$(LIBBASE)lib%.so_src,$(filter -l%,$(LDFLAGS))) +LIBS := $(wildcard $(LIBS)) +LIBS := $(LIBS:$(LIBBASE)%_src=$(LIBOUTDIR)%) +LDFLAGS := `sdl-config --libs` -L$(LIBOUTDIR) $(LDFLAGS) + +ifeq ($(OS),Windows_NT) +BINSUFFIX := .exe +MKDIR := mkdir +RM := del /f /s /q +else +BINSUFFIX := +MKDIR := mkdir -p +RM := rm -rf +endif + +BDIR := obj-sdl/ +_OBJ := $(OBJ:%=$(BDIR)%) +_BIN := ../bin-SDL/$(BIN)$(BINSUFFIX) + +.PHONY: all clean + +all: $(_BIN) + +clean: + $(RM) $(_BIN) $(_OBJ) $(BDIR) + +$(_BIN): $(_OBJ) $(LIBS) + @$(MKDIR) $(dir $@) + @echo [LINK] $@ + @$(CC) $(LDFLAGS) -o $@ $(_OBJ) + +$(BDIR)%.o: %.c + @$(MKDIR) $(dir $@) + @echo [CC] $@ + @$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $< + +$(LIBOUTDIR)lib%.so: + -ARCH=host HOST_ARCH=x86_64 make -C $(LIBBASE)lib$*.so_src/ all + -- 2.20.1