Small gfx.c update

This commit is contained in:
J-D-K 2018-07-27 18:00:20 -04:00
parent e6d870f8c9
commit 2385b2a6c2
10 changed files with 62 additions and 83 deletions

View File

@ -38,7 +38,7 @@ INCLUDES := inc
EXEFS_SRC := exefs_src
APP_TITLE := JKSV
APP_AUTHOR := JK_
APP_VERSION := 07/21/2018
APP_VERSION := 07/27/2018
ROMFS := romfs
#---------------------------------------------------------------------------------

View File

@ -22,7 +22,7 @@ typedef struct
FT_Library lib;
FT_Face face;
FT_Error libRet, faceRet;
//Loads to buffer for speed
//Loads to buffer for speed for TTF
uint8_t *fntData;
} font;
@ -43,21 +43,25 @@ bool graphicsExit();
void gfxHandleBuffs();
//Creates color from uint32_t
inline void colorCreateFromU32(color *c, uint32_t clr)
inline color colorCreateU32(uint32_t clr)
{
c->a = clr >> 24 & 0xFF;
c->b = clr >> 16 & 0xFF;
c->g = clr >> 8 & 0xFF;
c->r = clr & 0xFF;
color ret;
ret.a = clr >> 24 & 0xFF;
ret.b = clr >> 16 & 0xFF;
ret.g = clr >> 8 & 0xFF;
ret.r = clr & 0xFF;
return ret;
}
//Sets color to [r], [g], [b], [a]
inline void colorSetRGBA(color *c, uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a)
inline color colorCreateRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a)
{
c->r = _r;
c->g = _g;
c->b = _b;
c->a = _a;
color ret;
ret.r = _r;
ret.g = _g;
ret.b = _b;
ret.a = _a;
return ret;
}
//Inverts color
@ -74,18 +78,6 @@ inline uint32_t colorGetColor(const color c)
return (c.a << 24 | c.b << 16 | c.g << 8 | c.r);
}
inline color colorCreateTemp(uint32_t clr)
{
color ret;
ret.r = clr & 0xFF;
ret.g = clr >> 8 & 0xFF;
ret.b = clr >> 16 & 0xFF;
ret.a = clr >> 24 & 0xFF;
return ret;
}
//Draws text using f
void drawText(const char *str, tex *target, const font *f, int x, int y, int sz, color c);

View File

@ -94,9 +94,8 @@ static void drawGlyph(const FT_Bitmap *bmp, tex *target, int _x, int _y, const c
if(*bmpPtr > 0)
{
color txClr, tgtClr;
colorSetRGBA(&txClr, c.r, c.g, c.b, *bmpPtr);
colorCreateFromU32(&tgtClr, *rowPtr);
color txClr = colorCreateRGBA(c.r, c.g, c.b, *bmpPtr);
color tgtClr = colorCreateU32(*rowPtr);
*rowPtr = blend(txClr, tgtClr);
}
@ -373,23 +372,23 @@ void texDestroy(tex *t)
void texClearColor(tex *in, const color c)
{
uint32_t *dataPtr = &in->data[0];
uint32_t clr = colorGetColor(c);
for(int i = 0; i < in->size; i++)
*dataPtr++ = colorGetColor(c);
*dataPtr++ = clr;
}
void texDraw(const tex *t, tex *target, int x, int y)
{
if(t != NULL)
{
color dataClr, fbClr;
uint32_t *dataPtr = &t->data[0];
for(int tY = y; tY < y + t->height; tY++)
{
uint32_t *rowPtr = &target->data[tY * target->width + x];
for(int tX = x; tX < x + t->width; tX++, rowPtr++)
{
colorCreateFromU32(&dataClr, *dataPtr++);
colorCreateFromU32(&fbClr, *rowPtr);
color dataClr = colorCreateU32(*dataPtr++);
color fbClr = colorCreateU32(*rowPtr);
*rowPtr = blend(dataClr, fbClr);
}
@ -418,17 +417,16 @@ void texDrawSkip(const tex *t, tex *target, int x, int y)
if(t != NULL)
{
uint32_t *dataPtr = &t->data[0];
color px1, px2, fbPx;
for(int tY = y; tY < y + (t->height / 2); tY++, dataPtr += t->width)
{
uint32_t *rowPtr = &target->data[tY * target->width + x];
for(int tX = x; tX < x + (t->width / 2); tX++, rowPtr++)
{
colorCreateFromU32(&px1, *dataPtr++);
colorCreateFromU32(&px2, *dataPtr++);
colorCreateFromU32(&fbPx, *rowPtr);
color px1 = colorCreateU32(*dataPtr++);
color px2 = colorCreateU32(*dataPtr++);
color fbPx = colorCreateU32(*rowPtr);
*rowPtr = blend(colorCreateTemp(smooth(px1, px2)), fbPx);
*rowPtr = blend(colorCreateU32(smooth(px1, px2)), fbPx);
}
}
}
@ -439,14 +437,13 @@ void texDrawSkipNoAlpha(const tex *t, tex *target, int x, int y)
if(t != NULL)
{
uint32_t *dataPtr = &t->data[0];
color px1, px2;
for(int tY = y; tY < y + (t->height / 2); tY++, dataPtr += t->width)
{
uint32_t *rowPtr = &target->data[tY * target->width + x];
for(int tX = x; tX < x + (t->width / 2); tX++, rowPtr++)
{
colorCreateFromU32(&px1, *dataPtr++);
colorCreateFromU32(&px2, *dataPtr++);
color px1 = colorCreateU32(*dataPtr++);
color px2 = colorCreateU32(*dataPtr++);
*rowPtr = smooth(px1, px2);
}
@ -458,17 +455,15 @@ void texDrawInvert(const tex *t, tex *target, int x, int y, bool alpha)
{
if(t != NULL)
{
color dataClr, fbClr;
uint32_t *dataPtr = &t->data[0];
for(int tY = y; tY < y + t->height; tY++)
{
uint32_t *rowPtr = &target->data[tY * target->width + x];
for(int tX = x; tX < x + t->width; tX++, rowPtr++)
{
colorCreateFromU32(&dataClr, *dataPtr++);
color dataClr = colorCreateU32(*dataPtr);
colorInvert(&dataClr);
if(alpha)
colorCreateFromU32(&fbClr, *rowPtr);
color fbClr = colorCreateU32(*rowPtr);
*rowPtr = alpha ? blend(dataClr, fbClr) : colorGetColor(dataClr);
}

View File

@ -3,8 +3,6 @@
#include <vector>
#include <fstream>
#include <switch.h>
#include <unistd.h>
#include <sys/stat.h>
#include "gfx.h"
#include "data.h"

View File

@ -4,6 +4,7 @@
#include <cstdio>
#include <cstring>
#include <sys/stat.h>
#include <pthread.h>
#include <switch.h>
#include "ui.h"
@ -11,7 +12,7 @@
#include "util.h"
#include "file.h"
#define TITLE_TEXT "JKSV - 07/21/2018"
#define TITLE_TEXT "JKSV - 07/27/2018"
//Secret background that can be drawn from "/JKSV/back.jpg"
static tex *background = NULL;
@ -66,12 +67,12 @@ namespace ui
buttonY = texLoadPNGFile("romfs:/img/button/buttonY_drk.png");
buttonMin = texLoadPNGFile("romfs:/img/button/buttonMin_drk.png");
colorCreateFromU32(&clearClr, 0xFFEBEBEB);
colorCreateFromU32(&mnuTxt, 0xFF000000);
colorCreateFromU32(&txtClr, 0xFFFFFFFF);
colorCreateFromU32(&rectLt, 0xFFDFDFDF);
colorCreateFromU32(&rectSh, 0xFFCACACA);
colorCreateFromU32(&tboxClr, 0xFF505050);
clearClr = colorCreateU32(0xFFEBEBEB);
mnuTxt = colorCreateU32(0xFF000000);
txtClr = colorCreateU32(0xFFFFFFFF);
rectLt = colorCreateU32(0xFFDFDFDF);
rectSh = colorCreateU32(0xFFCACACA);
tboxClr = colorCreateU32(0xFF505050);
break;
default:
@ -89,12 +90,12 @@ namespace ui
buttonY = texLoadPNGFile("romfs:/img/button/buttonY_lght.png");
buttonMin = texLoadPNGFile("romfs:/img/button/buttonMin_lght.png");
colorCreateFromU32(&clearClr, 0xFF2D2D2D);
colorCreateFromU32(&mnuTxt, 0xFFFFFFFF);
colorCreateFromU32(&txtClr, 0xFF000000);
colorCreateFromU32(&rectLt, 0xFF505050);
colorCreateFromU32(&rectSh, 0xFF202020);
colorCreateFromU32(&tboxClr, 0xFFEBEBEB);
clearClr = colorCreateU32(0xFF2D2D2D);
mnuTxt = colorCreateU32(0xFFFFFFFF);
txtClr = colorCreateU32(0xFF000000);
rectLt = colorCreateU32(0xFF505050);
rectSh = colorCreateU32(0xFF202020);
tboxClr = colorCreateU32(0xFFEBEBEB);
break;
}

View File

@ -92,18 +92,18 @@ namespace ui
clrAdd = true;
}
drawRect(ui::fb, 0, 176, 1280, 64, colorCreateTemp(0xFFFFFFFF));
drawRect(ui::fb, 0, 240, 1280, 480, colorCreateTemp(0xFF2D2D2D));
drawRect(ui::fb, 0, 176, 1280, 64, colorCreateU32(0xFFFFFFFF));
drawRect(ui::fb, 0, 240, 1280, 480, colorCreateU32(0xFF2D2D2D));
uint32_t rectClr = 0xFF << 24 | ((0xBB + clrSh) & 0xFF) << 16 | ((0x88 + clrSh) & 0xFF) << 8 | 0x00;
color rectClr = colorCreateRGBA(0x00, 0x60 + clrSh, 0xBB + clrSh, 0xFF);
//Draw sel rectangle around key for controller
drawRect(ui::fb, keys[selKey].getX() - 4, keys[selKey].getY() - 4, keys[selKey].getW() + 8, keys[selKey].getH() + 8, colorCreateTemp(rectClr));
drawRect(ui::fb, keys[selKey].getX() - 4, keys[selKey].getY() - 4, keys[selKey].getW() + 8, keys[selKey].getH() + 8, rectClr);
for(unsigned i = 0; i < keys.size(); i++)
keys[i].draw();
drawText(str.c_str(), ui::fb, ui::shared, 16, 192, 32, colorCreateTemp(0xFF000000));
drawText(str.c_str(), ui::fb, ui::shared, 16, 192, 32, colorCreateU32(0xFF000000));
}
std::string keyboard::getString(const std::string& def)

View File

@ -154,12 +154,12 @@ namespace ui
else
length = start + 15;
uint32_t rectClr = 0xFF << 24 | ((0xBB + clrSh) & 0xFF) << 16 | ((0x60 + clrSh)) << 8 | 0x00;
color rectClr = colorCreateRGBA(0x00, 0x60 + clrSh, 0xBB + clrSh, 0xFF);
for(int i = start; i < length; i++)
{
if(i == selected)
drawRect(ui::fb, x, y + ((i - start) * 36), rW, 32, colorCreateTemp(rectClr));
drawRect(ui::fb, x, y + ((i - start) * 36), rW, 32, rectClr);
drawText(opt[i].c_str(), ui::fb, shared, x, (y + 8) + ((i - start) * 36), 16, textClr);
}

View File

@ -24,8 +24,8 @@ namespace ui
void progBar::draw(const std::string& text)
{
ui::drawTextbox(64, 240, 1152, 240);
drawRect(ui::fb, 96, 400, 1088, 64, colorCreateTemp(0xFF000000));
drawRect(ui::fb, 96, 400, (unsigned)width, 64, colorCreateTemp(0xFF00CC00));
drawRect(ui::fb, 96, 400, 1088, 64, colorCreateU32(0xFF000000));
drawRect(ui::fb, 96, 400, (unsigned)width, 64, colorCreateU32(0xFF00CC00));
//char tmp[64];
//sprintf(tmp, "%u / %u", (unsigned)prog, (unsigned)max);
@ -87,7 +87,7 @@ namespace ui
void button::draw()
{
if(pressed)
drawRect(ui::fb, x, y, w, h, colorCreateTemp(0xFF0D0D0D));
drawRect(ui::fb, x, y, w, h, colorCreateU32(0xFF0D0D0D));
else
ui::drawTextbox(x, y, w, h);

View File

@ -24,8 +24,8 @@ namespace ui
static ui::touchTrack track;
//Palette swapping
uint32_t selPrevClr = 0xFF << 24 | ((0xBB + clrShft) & 0xFF) << 16 | ((0x60 + clrShft)) << 8 | 0x00;
//Color swapping
color clrPrev = colorCreateRGBA(0x00, 0x60 + clrShft, 0xBB + clrShft, 0xFF);
if(clrAdd)
{
@ -41,13 +41,9 @@ namespace ui
}
//Updated sel
uint32_t curSelClr = 0xFF << 24 | ((0xBB + clrShft) & 0xFF) << 16 | ((0x60 + clrShft)) << 8 | 0x00;
color clrUpdt = colorCreateRGBA(0x00, 0x60 + clrShft, 0xBB + clrShft, 0xFF);
color selPrev, selCur;
colorCreateFromU32(&selPrev, selPrevClr);
colorCreateFromU32(&selCur, curSelClr);
texSwapColors(ui::selBox, selPrev, selCur);
texSwapColors(ui::selBox, clrPrev, clrUpdt);
unsigned x = 70, y = 80;

View File

@ -20,8 +20,8 @@ namespace ui
static ui::touchTrack track;
//Palette swapping selBox
uint32_t rectPrev = 0xFF << 24 | ((0xBB + clrShft) & 0xFF) << 16 | ((0x60 + clrShft)) << 8 | 0x00;
//Color swapping selBox
color clrPrev = colorCreateRGBA(0x00, 0x60 + clrShft, 0xBB + clrShft, 0xFF);
if(clrAdd)
{
@ -37,17 +37,14 @@ namespace ui
}
//Update selBox color
uint32_t rectClr = 0xFF << 24 | ((0xBB + clrShft) & 0xFF) << 16 | ((0x60 + clrShft)) << 8 | 0x00;
color clrUpdt = colorCreateRGBA(0x00, 0x60 + clrShft, 0xBB + clrShft, 0xFF);
unsigned x = 70, y = 80;
unsigned endUser = start + 32;
if(start + 32 > (int)data::users.size())
endUser = data::users.size();
color selPrev, selNew;
colorCreateFromU32(&selPrev, rectPrev);
colorCreateFromU32(&selNew, rectClr);
texSwapColors(ui::selBox, selPrev, selNew);
texSwapColors(ui::selBox, clrPrev, clrUpdt);
texDraw(ui::selBox, ui::fb, selRectX, selRectY);
for(unsigned i = start; i < endUser; y += 144)