From: chaoskagami Date: Tue, 30 Sep 2014 05:54:02 +0000 (-0400) Subject: Everything is now backend/SDL dependent. How the backend does it's job is of no conce... X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=05689508cf23be930618651ecccd2085a6d85e05;p=vn%2Fvndc.git Everything is now backend/SDL dependent. How the backend does it's job is of no concern now. --- diff --git a/external/zero/src/TextManager.cpp b/external/zero/src/TextManager.cpp index abf3dd0..b976180 100644 --- a/external/zero/src/TextManager.cpp +++ b/external/zero/src/TextManager.cpp @@ -58,68 +58,49 @@ void TextManager::Render(char* text) { } void TextManager::Render(char* text, int x, int y) { - if (text == NULL || fonts[current_font] == NULL) + if (text == NULL || fonts[current_font] == NULL) { + fprintf(stderr, "[WARN] Null text or font passed.\n"); return; + } + SDL_Surface *sf1 = NULL, *sf2 = NULL; + sf1 = TTF_RenderUTF8_Blended(fonts[current_font], text, color); + if(outline) { + // Invert normal color. SDL_Color n_color; n_color.r = 255 - color.r; n_color.g = 255 - color.g; n_color.b = 255 - color.b; n_color.a = color.a; + + // Outline, so increase size. TTF_SetFontOutline(fonts[current_font], outline_px); sf2 = TTF_RenderUTF8_Blended(fonts[current_font], text, n_color); + + // Disable Outline. TTF_SetFontOutline(fonts[current_font], 0); } - SDL_Rect src, dst, src2, dst2; - src.x = 0; - src.y = 0; - src.w = sf1->w; - src.h = sf1->h; - - dst.x = x; - dst.y = y; - dst.w = src.w; - dst.h = src.h; - if(outline) { - src2.x = 0; - src2.y = 0; - src2.w = sf2->w; - src2.h = sf2->h; - - dst2.x = x - (outline_px); - dst2.y = y - (outline_px); - dst2.w = src2.w; - dst2.h = src2.h; - } - - if(ctx->Accelerated()) { - SDL_Texture *tmp1 = NULL, *tmp2 = NULL; - - tmp1 = SDL_CreateTextureFromSurface(ctx->Renderer(), sf1); - if(outline) - tmp2 = SDL_CreateTextureFromSurface(ctx->Renderer(), sf2); - - ctx->OverlayBlit(tmp2, &src2, &dst2, NULL); - ctx->OverlayBlit(tmp1, &src, &dst, NULL); + UDisplayable* r_sf2 = new UDisplayable(ctx, Normal, sf2); + r_sf2->SetOverlay(true); + r_sf2->SetXY(x-outline_px, y-outline_px); - SDL_DestroyTexture(tmp2); - SDL_DestroyTexture(tmp1); - - } - else { - ctx->OverlayBlit(sf2, &src, &dst, NULL); - ctx->OverlayBlit(sf1, &src, &dst, NULL); + r_sf2->Blit(); + + delete r_sf2; } - SDL_FreeSurface(sf2); - SDL_FreeSurface(sf1); + UDisplayable* r_sf1 = new UDisplayable(ctx, Normal, sf1); + r_sf1->SetOverlay(true); + r_sf1->SetXY(x, y); + r_sf1->Blit(); + delete r_sf1; } int TextManager::TestLen(char* text) { @@ -157,43 +138,48 @@ void TextManager::SetFontUsed(int index) // So your string will likely not be usable as before. void TextManager::SplitStringByWidth(char* string, int max_w, int* OUT_num, char*** OUT_ptrs) { if(TestLen(string) > max_w) { + /* new algo */ + char** ptrs = NULL; + int lines = 0; + int len = strlen(string); - /* new algo */ - char** ptrs = NULL; - int lines = 0; + int counted = 0; - int len = strlen(string); + while(counted < len) { + char* pt_start = &string[counted]; + char* pt_end = &pt_start[strlen(pt_start)]; - int counted = 0; + while(pt_end > pt_start && TestLen(pt_start) > max_w) { + *pt_end = ' '; + --pt_end; + while (*pt_end != ' ' && pt_end > pt_start) --pt_end; - while(counted < len) { - char* pt_start = &string[counted]; - char* pt_end = &pt_start[strlen(pt_start)]; - - while(pt_end > pt_start && TestLen(pt_start) > max_w) { - *pt_end = ' '; - --pt_end; - - while (*pt_end != ' ' && pt_end > pt_start) --pt_end; + *pt_end = '\0'; + } - *pt_end = '\0'; - } + #ifdef DEBUG_OVERKILL + printf("Reduced line %d: %s\n", lines, pt_start); + #endif - #ifdef DEBUG_OVERKILL - printf("Reduced line %d: %s\n", lines, pt_start); - #endif + ptrs = (char**)realloc(ptrs, sizeof(char*)*(lines+1)); - ptrs = (char**)realloc(ptrs, sizeof(char*)*(lines+1)); + ptrs[lines] = pt_start; - ptrs[lines] = pt_start; + counted += strlen(pt_start) + 1; - counted += strlen(pt_start) + 1; + ++lines; + } - ++lines; - } + *OUT_num = lines; - OUT_num[0] = lines; + *OUT_ptrs = ptrs; + } + else { + char** ptrs = (char**)calloc(sizeof(char*), 1); + ptrs[0] = string; - OUT_ptrs[0] = ptrs; - } + // We pass thru values anyways, regardless of there being one line. + *OUT_num = 1; + *OUT_ptrs = ptrs; + } } diff --git a/external/zero/src/UDisplayable.cpp b/external/zero/src/UDisplayable.cpp index 3d82e1a..b2639f8 100644 --- a/external/zero/src/UDisplayable.cpp +++ b/external/zero/src/UDisplayable.cpp @@ -194,6 +194,9 @@ // From SDL_Surface. UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp) { + + DefaultVars(); + this->x = 0; this->y = 0; this->loc.x = 0; @@ -241,8 +244,10 @@ // Sets the position on screen. void UDisplayable::SetXY(double x, double y) { - if (Error) + if (Error) { + fprintf(stderr, "[WARN] Error flag set.\n"); return; + } this->x = x; this->y = y; @@ -254,23 +259,41 @@ this->y = 0; if(frameIndex == -1) { - if(this->x > frame[2] - this->bmp_w) - this->x = (double)(frame[2] - this->bmp_w); + if(over) { + if(this->x > ctx->GetWidth() - this->bmp_w) + this->x = (double)(ctx->GetWidth() - this->bmp_w); + } + else { + if(this->x > frame[2] - this->bmp_w) + this->x = (double)(frame[2] - this->bmp_w); + } } else { - if(this->x > frame[2] - this->frameWidth) - this->x = (double)(frame[2] - this->frameWidth); + if(over) { + if(this->x > ctx->GetWidth() - this->bmp_w) + this->x = (double)(ctx->GetWidth() - this->frameWidth); + } + else { + if(this->x > frame[2] - this->frameWidth) + this->x = (double)(frame[2] - this->frameWidth); + } } - if(this->y > frame[3] - this->bmp_h) - this->y = (double)(frame[3] - this->bmp_h); + if(over) { + if(this->y > ctx->GetHeight() - this->bmp_h) + this->y = (double)(ctx->GetHeight() - this->bmp_h); + } + else { + if(this->y > frame[3] - this->bmp_h) + this->y = (double)(frame[3] - this->bmp_h); + } this->loc.x = (int)this->x; this->loc.y = (int)this->y; - #ifdef DEBUG_OVERKILL - printf("[UDisplayable::SetXY] x:%d y:%d w:%d h:%d\n", frame[0], frame[1], frame[2], frame[3]); - #endif +// #ifdef DEBUG_OVERKILL + printf("[UDisplayable::SetXY] x:%d y:%d\n", this->loc.x, this->loc.y); +// #endif } // Modifies the position on screen. Meant to avoid embedded retrievals. @@ -290,16 +313,34 @@ this->y = 0; if(frameIndex == -1) { - if(this->x > frame[2] - this->bmp_w) - this->x = (double)(frame[2] - this->bmp_w); + if(over) { + if(this->x > ctx->GetWidth() - this->bmp_w) + this->x = (double)(ctx->GetWidth() - this->bmp_w); + } + else { + if(this->x > frame[2] - this->bmp_w) + this->x = (double)(frame[2] - this->bmp_w); + } } else { - if(this->x > frame[2] - this->frameWidth) - this->x = (double)(frame[2] - this->frameWidth); + if(over) { + if(this->x > ctx->GetWidth() - this->bmp_w) + this->x = (double)(ctx->GetWidth() - this->frameWidth); + } + else { + if(this->x > frame[2] - this->frameWidth) + this->x = (double)(frame[2] - this->frameWidth); + } } - if(this->y > frame[3] - this->bmp_h) - this->y = (double)(frame[3] - this->bmp_h); + if(over) { + if(this->y > ctx->GetHeight() - this->bmp_h) + this->y = (double)(ctx->GetHeight() - this->bmp_h); + } + else { + if(this->y > frame[3] - this->bmp_h) + this->y = (double)(frame[3] - this->bmp_h); + } this->loc.x = (int)this->x; this->loc.y = (int)this->y; @@ -378,7 +419,7 @@ SDL_Rect src; src.x = 0; src.y = 0; - src.w = frameWidth; + src.w = bmp_w; src.h = bmp_h; if (frameIndex == -1) { @@ -397,16 +438,10 @@ frameClip.h = bmp_h; if(ctx->GLMode()) { - SDL_Rect image_rect; - - image_rect.x = 0; - 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. + ctx->OverlayBlit(bitmap, &frameClip, &loc_adj, &src); // 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, &src); // GL needs data that isn't inside of bitmap. } else { diff --git a/vndc/src/Data.cpp b/vndc/src/Data.cpp index a79abe2..8b05151 100644 --- a/vndc/src/Data.cpp +++ b/vndc/src/Data.cpp @@ -75,15 +75,14 @@ void DumpSave(char* fname) { // Dump script file. // A save actually ends up as a mini-script. - // So, to load a save you load this as the - // main script - // For example: + // So, to load a save you load something like this as the + // main script: + // setvar data1 = 6 // setvar data2 = 9 // music mus // bgload bg // jump script.scr 60 - // The call command runs a scr, and returns here. FILE* save_to = fopen(fname, "w"); @@ -101,8 +100,7 @@ void DumpSave(char* fname) { fprintf(save_to, "music %s\n", &(GetData()->current_music[6])); fprintf(save_to, "bgload %s\n", &(GetData()->current_bg[11])); - fprintf(save_to, "jump %s %d\n", &(GetData()->current_scr[7]), GetData()->currentLine - 1); // The text never completely displayed - // So restore back one to replay - + fprintf(save_to, "jump %s %d\n", &(GetData()->current_scr[7]), GetData()->currentLine - 1); // The text ack'd with leftclick + // So restore back one to replay fclose(save_to); } diff --git a/vndc/src/Loop.cpp b/vndc/src/Loop.cpp index f4625e4..2418d6e 100644 --- a/vndc/src/Loop.cpp +++ b/vndc/src/Loop.cpp @@ -27,8 +27,8 @@ void Loop() { if(GetData()->ctx->GetQuit()) return; Parse(); - // We don't clear. This system uses dirty blits. ;P - GetData()->ctx->Flush(); + // We don't clear. This system uses dirty blits. ;P + GetData()->ctx->Flush(); GetData()->ctx->StartSync(); diff --git a/vndc/src/op_bgload.cpp b/vndc/src/op_bgload.cpp index 3cfa12e..3f2c231 100644 --- a/vndc/src/op_bgload.cpp +++ b/vndc/src/op_bgload.cpp @@ -11,14 +11,10 @@ void op_bgload(char* file, int* fadetime) { if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit()) return; - // Fadeout not implemented yet. - memset(GetData()->current_bg, 0, 400); snprintf(GetData()->current_bg, 400, "background/%s", file); - //printf("Attempt to load file %s as BG\n", path); - // Load displayable. UDisplayable* disp = new UDisplayable(GetData()->ctx, GetData()->current_bg); @@ -29,19 +25,11 @@ void op_bgload(char* file, int* fadetime) { if(fadetime != NULL) transp_incr = 255 / *fadetime; - // Transition effect. - - // SDL_Texture* tx = NULL; - // tx = SDL_CreateTextureFromSurface(GetData()->ctx->Renderer(), sfc); - // SDL_SetTextureBlendMode(tx, SDL_BLENDMODE_BLEND); - - // SDL_FreeSurface(sfc); + // FIXME - Implement proper fading out functionality. int delay = 1; for(int tr = 0; tr < 255; tr += transp_incr) { disp->Blit(); op_delay(&delay); } - -// SDL_DestroyTexture(tx); } diff --git a/vndc/src/op_text.cpp b/vndc/src/op_text.cpp index 87aa3ca..de37750 100644 --- a/vndc/src/op_text.cpp +++ b/vndc/src/op_text.cpp @@ -11,8 +11,6 @@ void op_text(char* string) { if (GetData()->if_fail != 0 || GetData()->ctx->GetQuit()) return; - // Search thru for vars and rebuild string. - // Linebreak on zero-length, and render size exceed. if (GetData()->text_y > (GetData()->render_y2) || strlen(string) < 1) op_cleartext(); @@ -66,59 +64,22 @@ void op_text(char* string) { TextManager* txt = GetData()->ctx->Text(); - if(txt->TestLen(string) > (GetData()->render_x2 - GetData()->render_x1)) { - - /* new algo */ - char** ptrs = NULL; - int lines = 0; - - int len = strlen(string); - - int counted = 0; - - while(counted < len) { - char* pt_start = &string[counted]; - char* pt_end = &pt_start[strlen(pt_start)]; - - while(pt_end > pt_start && txt->TestLen(pt_start) > (GetData()->render_x2 - GetData()->render_x1)) { - *pt_end = ' '; - --pt_end; - - while (*pt_end != ' ' && pt_end > pt_start) --pt_end; - - *pt_end = '\0'; - } + int lines = 0; + char** ptrs = NULL; - #ifdef DEBUG_OVERKILL - printf("Reduced line %d: %s\n", lines, pt_start); - #endif + txt->SplitStringByWidth(string, GetData()->render_x2 - GetData()->render_x1, &lines, &ptrs); - ptrs = (char**)realloc(ptrs, sizeof(char*)*(lines+1)); + if( ( lines * GetData()->text_gap + GetData()->text_y ) > GetData()->render_y2 ) + op_cleartext(); - ptrs[lines] = pt_start; - - counted += strlen(pt_start) + 1; - - ++lines; - } - - if( ( lines * GetData()->text_gap + GetData()->text_y ) > GetData()->render_y2 ) - op_cleartext(); - - for(int i=0; i < lines; i++) { - //printf("[br] %s\n", ptrs[i]); - txt->Render(ptrs[i], GetData()->text_x, GetData()->text_y); - GetData()->text_y += GetData()->text_gap; - } - - free(ptrs); - - } - else { - txt->Render(string, GetData()->text_x, GetData()->text_y); + for(int i=0; i < lines; i++) { + printf("[br] %s\n", ptrs[i]); + txt->Render(ptrs[i], GetData()->text_x, GetData()->text_y); GetData()->text_y += GetData()->text_gap; } + free(ptrs); + if(!noclick) { GetData()->wait_input = true; }