Start of new built-in GUI.

The idea is to present icons for the most commonly used functions that
will pop up on the screen when moused over, then go away once the mouse
is not over them anymore. Hopefully this will actually be usable, unlike
the previous clusterfuck that I attempted. It was a good idea, but SDL
just wasn't up to the heavy lifting required.
This commit is contained in:
Shamus Hammons 2013-10-08 16:55:07 -05:00
parent f36d026c7b
commit d61fc97ee4
6 changed files with 417 additions and 1095 deletions

File diff suppressed because it is too large Load Diff

View File

@ -861,14 +861,8 @@ static void RenderDHiRes(uint16_t toLine/*= 192*/)
void RenderVideoFrame(void)
{
//temp...
/*RenderLoRes();
RenderScreenBuffer();
return;//*/
if (textMode)
{
// There's prolly more to it than this (like 80 column text), but this'll have to do for now...
if (!col80Mode)
Render40ColumnText();
else
@ -911,7 +905,5 @@ return;//*/
DrawString();
msgTicks--;
}
RenderScreenBuffer();
}

View File

@ -479,3 +479,181 @@ void GUI::Stop(void)
exitGUI = true;
}
//
// NEW GUI STARTS HERE
//
enum { SBS_SHOWING, SBS_HIDING, SBS_SHOWN, SBS_HIDDEN };
SDL_Texture * GUI2::overlay = NULL;
SDL_Rect GUI2::olSrc;
SDL_Rect GUI2::olDst;
bool GUI2::sidebarOut = false;
int GUI2::sidebarState = SBS_HIDDEN;
int32_t GUI2::dx = 0;
GUI2::GUI2(void)
{
}
GUI2::~GUI2(void)
{
}
void GUI2::Init(SDL_Renderer * renderer)
{
overlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
SDL_TEXTUREACCESS_STREAMING, 128, 256);
if (!overlay)
{
WriteLog("GUI: Could not create overlay!\n");
return;
}
if (SDL_SetTextureBlendMode(overlay, SDL_BLENDMODE_BLEND) == -1)
WriteLog("GUI: Could not set blend mode for overlay.\n");
// uint32_t * texturePointer = (uint32_t *)scrBuffer;
uint32_t texturePointer[128 * 256];
for(uint32_t i=0; i<128*256; i++)
texturePointer[i] = 0x50A000A0;
SDL_UpdateTexture(overlay, NULL, texturePointer, 128 * sizeof(Uint32));
olSrc.x = olSrc.y = 0;
olSrc.w = 128;
olSrc.h = 256;
olDst.x = VIRTUAL_SCREEN_WIDTH;
olDst.y = 24;
olDst.w = 128;
olDst.h = 256;
WriteLog("GUI: Successfully initialized.\n");
}
void GUI2::MouseDown(int32_t x, int32_t y, uint32_t buttons)
{
}
void GUI2::MouseUp(int32_t x, int32_t y, uint32_t buttons)
{
}
void GUI2::MouseMove(int32_t x, int32_t y, uint32_t buttons)
{
if (!sidebarOut)
{
if (x > (VIRTUAL_SCREEN_WIDTH - 100))
{
//printf("GUI: sidebar showing (x = %i)...\n", x);
sidebarState = SBS_SHOWING;
dx = -8;
}
else
{
//printf("GUI: sidebar hiding[1] (x = %i)...\n", x);
sidebarState = SBS_HIDING;
dx = 8;
}
}
else
{
if (x < (VIRTUAL_SCREEN_WIDTH - 100))
{
//printf("GUI: sidebar hiding[2] (x = %i)...\n", x);
sidebarOut = false;
sidebarState = SBS_HIDING;
dx = 8;
}
}
}
void GUI2::Render(SDL_Renderer * renderer)
{
if (!overlay)
return;
HandleGUIState();
SDL_RenderCopy(renderer, overlay, &olSrc, &olDst);
}
void GUI2::HandleGUIState(void)
{
olDst.x += dx;
if (olDst.x < (VIRTUAL_SCREEN_WIDTH - 100) && sidebarState == SBS_SHOWING)
{
olDst.x = VIRTUAL_SCREEN_WIDTH - 100;
sidebarOut = true;
sidebarState = SBS_SHOWN;
dx = 0;
}
else if (olDst.x > VIRTUAL_SCREEN_WIDTH && sidebarState == SBS_HIDING)
{
olDst.x = VIRTUAL_SCREEN_WIDTH;
sidebarState = SBS_HIDDEN;
dx = 0;
}
}
/*
GUI Considerations:
screen is 560 x 384
cut into 7 pieces give ~54 pix per piece
So, let's try 40x40 icons, and see if that's good enough...
drive proportions: 1.62 : 1
Icon order:
+-----+
| |
|Power|
| |
+-----+
+-----+
| |
|Disk1|
| ^| <-- eject button
+-----+
+-----+
| |
|Disk2|
| ^|
+-----+
+-----+
| |
|Swap |
| |
+-----+
+-----+
| |
|Confg|
| |
+-----+
maybe state save/load
*/

View File

@ -35,5 +35,30 @@ class GUI
SDL_Rect mouse, oldMouse;
};
class GUI2
{
public:
GUI2();
~GUI2();
// Everything else is a class method...
static void Init(SDL_Renderer *);
static void MouseDown(int32_t, int32_t, uint32_t);
static void MouseUp(int32_t, int32_t, uint32_t);
static void MouseMove(int32_t, int32_t, uint32_t);
static void Render(SDL_Renderer *);
static void HandleGUIState(void);
// Class variables...
static SDL_Texture * overlay;
static SDL_Rect olSrc;
static SDL_Rect olDst;
static bool sidebarOut;
static int sidebarState;
static int32_t dx;
};
#endif // __GUI_H__

View File

@ -12,9 +12,9 @@
//
#include "video.h"
#include <SDL2/SDL.h>
#include <string.h> // Why??? (for memset, etc... Lazy!) Dunno why, but this just strikes me as wrong...
#include <malloc.h>
#include "gui/gui.h"
#include "log.h"
#include "settings.h"
@ -22,7 +22,7 @@
// Exported global variables (actually, these are LOCAL global variables, EXPORTED...)
static SDL_Window * sdlWindow = NULL;
static SDL_Renderer * sdlRenderer = NULL;
SDL_Renderer * sdlRenderer = NULL;
static SDL_Texture * sdlTexture = NULL;
uint32_t scrBuffer[VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT * sizeof(uint32_t)];
@ -79,7 +79,6 @@ void RenderScreenBuffer(void)
SDL_UpdateTexture(sdlTexture, NULL, scrBuffer, VIRTUAL_SCREEN_WIDTH * sizeof(Uint32));
SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(sdlRenderer);
}
@ -97,3 +96,4 @@ void ToggleFullScreen(void)
WriteLog("Video::ToggleFullScreen: SDL error = %s\n", SDL_GetError());
}

View File

@ -5,8 +5,10 @@
#ifndef __VIDEO_H__
#define __VIDEO_H__
#include <SDL2/SDL.h>
#include <stdint.h> // For uint32_t
// These are double the normal width because we use sub-pixel rendering.
//#define VIRTUAL_SCREEN_WIDTH 280
#define VIRTUAL_SCREEN_WIDTH 560
//#define VIRTUAL_SCREEN_HEIGHT 192
@ -19,6 +21,7 @@ void ToggleFullScreen(void);
// Exported crap
extern SDL_Renderer * sdlRenderer;
extern uint32_t scrBuffer[];
extern uint32_t mainScrBuffer[];