From cff84267f8b34b544c8815e9789db8705d85c10c Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Mon, 29 Sep 2014 12:26:54 -0400 Subject: [PATCH] Making changes. There's some rather terrible and buggy behavior that needs severe fixing - cause currently unknown, but cleartext and overlayblit related likely --- external/zero/include/UDisplayable.hpp | 3 ++ external/zero/src/UDisplayable.cpp | 64 ++++++++++++++++++++++++-- vndc/include/Data.hpp | 4 +- vndc/include/gitrev.hpp | 2 +- vndc/src/Data.cpp | 18 ++++++-- vndc/src/Loop.cpp | 2 + vndc/src/VNDC.cpp | 2 +- vndc/src/op_cleartext.cpp | 42 +---------------- 8 files changed, 87 insertions(+), 50 deletions(-) diff --git a/external/zero/include/UDisplayable.hpp b/external/zero/include/UDisplayable.hpp index 1d1c701..b733d64 100644 --- a/external/zero/include/UDisplayable.hpp +++ b/external/zero/include/UDisplayable.hpp @@ -17,6 +17,7 @@ typedef enum { UDisplayable(ContextManager* ctx, char* fname); // Sets up in normal mode. UDisplayable(ContextManager* ctx, UDisplayableMode mode, char* fname); // Sets up in specified mode; params not set UDisplayable(ContextManager* ctx, UDisplayableMode mode, void* memory, int mSize); // Sets up from memory block in mode + UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp); // Loads from SDL_surface // All modes can use the following. void SetXY(double x, double y); @@ -40,6 +41,7 @@ typedef enum { // Only specific modes can use these. Otherwise, they nop. void SetHitbox(int x, int y, int w, int h); void SetDock(int x, int y, int w, int h); + void SetOverlay(bool state); // Only animated Displayables can use these. void SetFrameWidth(int frameW); @@ -56,6 +58,7 @@ typedef enum { void* bitmap; // Will contain either a SDL_Surface or SDL_Texture SDL_Rect loc, clip; ContextManager* ctx; + bool over; int bmp_w, bmp_h; diff --git a/external/zero/src/UDisplayable.cpp b/external/zero/src/UDisplayable.cpp index 2a0d801..e50496d 100644 --- a/external/zero/src/UDisplayable.cpp +++ b/external/zero/src/UDisplayable.cpp @@ -188,6 +188,50 @@ } } + // From SDL_Surface. + UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp) { + this->x = 0; + this->y = 0; + this->loc.x = 0; + this->loc.y = 0; + this->ctx = cx; + this->frameWidth = bitmap_tmp->w; + this->bmp_w = bitmap_tmp->w; + this->bmp_h = bitmap_tmp->h; + + // We still allocate the two arrays, regardless. + + // These values are unused, but we'll default them so it will operate normally. + hitbox = (int*)calloc(sizeof(int), 4); + + // By default, it will fill this with 0, 0, W, H. + // This will behave identically to a displayable. + hitbox[0] = 0; + hitbox[1] = 0; + hitbox[2] = bitmap_tmp->w; + hitbox[3] = bitmap_tmp->h; + + this->loc.w = bitmap_tmp->w; + this->loc.h = bitmap_tmp->w; + + frame = (int*)calloc(sizeof(int), 4); + + frame[0] = 0; + frame[1] = 0; + frame[2] = cx->GetWidth(); + frame[3] = cx->GetHeight(); + + // Determine if we're on an accelerated context. If so, we create a texture out of the bitmap. + // Then we store what we'll use to the void* bitmap, either Tex or Surf. + + if(cx->Accelerated()) { + this->bitmap = cx->AccelImage(bitmap_tmp); + } + else { + this->bitmap = cx->GLTexImage(bitmap_tmp); + } + } + // Sets the position on screen. void UDisplayable::SetXY(double x, double y) { @@ -332,7 +376,10 @@ src.h = bmp_h; if (frameIndex == -1) { - ctx->Blit(bitmap, &src, &loc_adj, NULL); + if(over) + ctx->OverlayBlit(bitmap, &src, &loc_adj, NULL); + else + ctx->Blit(bitmap, &src, &loc_adj, NULL); return; } @@ -350,11 +397,17 @@ image_rect.x = 0; image_rect.w = bmp_w; image_rect.h = bmp_h; + if(over) + ctx->OverlayBlit(bitmap, &frameClip, &loc_adj, &image_rect); // GL needs data that isn't inside of bitmap. + else + ctx->Blit(bitmap, &frameClip, &loc_adj, &image_rect); // GL needs data that isn't inside of bitmap. - ctx->Blit(bitmap, &frameClip, &loc_adj, &image_rect); // GL needs data that isn't inside of bitmap. } else { - ctx->Blit(bitmap, &frameClip, &loc_adj, NULL); + if(over) + ctx->OverlayBlit(bitmap, &frameClip, &loc_adj, NULL); + else + ctx->Blit(bitmap, &frameClip, &loc_adj, NULL); } } @@ -374,6 +427,11 @@ return rect; } + // Surface is on overlay, not background. + void UDisplayable::SetOverlay(bool state) { + over = state; + } + // Destroy bitmap. UDisplayable::~UDisplayable() { diff --git a/vndc/include/Data.hpp b/vndc/include/Data.hpp index 7bf4fab..41105c6 100644 --- a/vndc/include/Data.hpp +++ b/vndc/include/Data.hpp @@ -43,10 +43,12 @@ class DataContainer { char* window_name; char* next_line; // Used for voice-detect. // It's impossible to parse without lookahead. + UDisplayable* text_box_base; }; DataContainer* GetData(); -void CreateDataContainer(); +void Data_PreInit(); +void Data_PostInit(); void DumpSave(char* fname); #endif diff --git a/vndc/include/gitrev.hpp b/vndc/include/gitrev.hpp index d15b922..2745b8b 100644 --- a/vndc/include/gitrev.hpp +++ b/vndc/include/gitrev.hpp @@ -1,5 +1,5 @@ #ifndef GIT_REV_HDR #define GIT_REV_HDR -#define GIT_REV "600f8372132a379e10f46584bba06b5013e8bf05" +#define GIT_REV "2aefc48e99ae39a5427858ce44bfb625c51ac8db" #endif diff --git a/vndc/src/Data.cpp b/vndc/src/Data.cpp index 71b1dc9..8c8ca87 100644 --- a/vndc/src/Data.cpp +++ b/vndc/src/Data.cpp @@ -44,16 +44,28 @@ DataContainer::DataContainer() { // It's impossible to parse without lookahead. } -void CreateDataContainer() { +void Data_PreInit() { data = new DataContainer(); - - + /* Storage of values for saves */ GetData()->main_scr = (char**)calloc(sizeof(char*), 1); GetData()->main_scr[0] = (char*)calloc(sizeof(char), 400); strncpy(GetData()->main_scr[0], loadup, 400); } +void Data_PostInit() { + /* Generate the surface for use with cleartext. */ + int width_dr = (GetData()->render_x2 - GetData()->render_x1 + 20); + int height_dr = (GetData()->render_y2 - GetData()->render_y1 + 20); + + SDL_Surface* pass_sfc = SDL_CreateRGBSurface(0, width_dr, height_dr, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK); + SDL_FillRect(pass_sfc, NULL, SDL_MapRGBA(pass_sfc->format, 0, 0, 0, 100)); + + GetData()->text_box_base = new UDisplayable(GetData()->ctx, Normal, pass_sfc); + GetData()->text_box_base->SetOverlay(true); + // GetData()->text_box_base->SetXY(GetData()->render_x1, GetData()->render_y1); +} + DataContainer* GetData() { return &data[0]; } diff --git a/vndc/src/Loop.cpp b/vndc/src/Loop.cpp index 87544f6..f4625e4 100644 --- a/vndc/src/Loop.cpp +++ b/vndc/src/Loop.cpp @@ -61,5 +61,7 @@ void Setup() { GetData()->ctx->Text()->Outline(1); GetData()->ctx->Text()->SetColor(255,255,255,255); + Data_PostInit(); + op_cleartext(); } diff --git a/vndc/src/VNDC.cpp b/vndc/src/VNDC.cpp index 57d23a1..4f502a4 100644 --- a/vndc/src/VNDC.cpp +++ b/vndc/src/VNDC.cpp @@ -102,7 +102,7 @@ int main(int argc, char** argv) { } } - CreateDataContainer(); + Data_PreInit(); GetData()->ctx = new ContextManager(); diff --git a/vndc/src/op_cleartext.cpp b/vndc/src/op_cleartext.cpp index 2b6c711..1763ceb 100644 --- a/vndc/src/op_cleartext.cpp +++ b/vndc/src/op_cleartext.cpp @@ -2,46 +2,6 @@ #include "Funcs.hpp" -void ct_transwindow() { - - int width_dr = (GetData()->render_x2 - GetData()->render_x1 + 20); - int height_dr = (GetData()->render_y2 - GetData()->render_y1 + 30 + 20); - - // if(! GetData()->ctx->Accelerated()) return; - SDL_Surface* sfc = SDL_CreateRGBSurface(0, width_dr, height_dr, 32, RED_MASK, GREEN_MASK, BLUE_MASK, ALPHA_MASK); - SDL_FillRect(sfc, NULL, SDL_MapRGBA(sfc->format, 0, 0, 0, 100)); - if(!GetData()->ctx->Accelerated()) { - } - - SDL_Rect src; - src.x = 0; - src.y = 0; - src.w = sfc->w; - src.h = sfc->h; - - SDL_Rect dst; - dst.x = GetData()->render_x1 - 10; - dst.y = GetData()->render_y1 - 10; - dst.w = src.w; - dst.h = src.h; - - if(GetData()->ctx->Accelerated()) { - SDL_Texture* dim = SDL_CreateTextureFromSurface(GetData()->ctx->Renderer(), sfc); - //SDL_SetTextureBlendMode(dim, SDL_BLENDMODE_BLEND); - //SDL_SetTextureAlphaMod(dim, 128); - - GetData()->ctx->OverlayBlit(dim, &src, &dst, NULL); - - SDL_DestroyTexture(dim); - } - else { - GetData()->ctx->OverlayBlit(sfc, &src, &dst, NULL); - } - - SDL_FreeSurface(sfc); - -} - /* * Implements cleartext vnds function. * cleartext mod @@ -57,5 +17,5 @@ void op_cleartext() { GetData()->ctx->ClearOverlay(); // Dim transparent overlay - ct_transwindow(); + GetData()->text_box_base->Blit(); } -- 2.39.5