]> Chaos Git - vn/vndc.git/commitdiff
Everything is now backend/SDL dependent. How the backend does it's job is of no conce...
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 30 Sep 2014 05:54:02 +0000 (01:54 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 30 Sep 2014 05:54:02 +0000 (01:54 -0400)
external/zero/src/TextManager.cpp
external/zero/src/UDisplayable.cpp
vndc/src/Data.cpp
vndc/src/Loop.cpp
vndc/src/op_bgload.cpp
vndc/src/op_text.cpp

index abf3dd0ae0a701a153bae4441461a4fb1caa722c..b976180623bc6bdbb0613cf09d06a25d30e65bb0 100644 (file)
@@ -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;
+       }
 }
index 3d82e1a5e9987a749e5f24b02c94401b7b446574..b2639f8061f5caa812494796801596fd2d7ca5a1 100644 (file)
 
        // From SDL_Surface.
        UDisplayable::UDisplayable(ContextManager* cx, UDisplayableMode mode, SDL_Surface* bitmap_tmp) {
+
+               DefaultVars();
+
                this->x = 0;
                this->y = 0;
                this->loc.x = 0;
        // 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;
 
                        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.
                        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;
                SDL_Rect src;
                src.x = 0;
                src.y = 0;
-               src.w = frameWidth;
+               src.w = bmp_w;
                src.h = bmp_h;
 
                if (frameIndex == -1) {
                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 {
index a79abe29703bfdaf6f6d84db07b99da0c823cb45..8b05151f182e0e72476517e0a1e4324207adf1df 100644 (file)
@@ -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);
 }
index f4625e4e0cbc1d8d1e1e4f34f598bcaf51f0d3da..2418d6efd3261d6a2bc1e891320c7bec3647bb58 100644 (file)
@@ -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();
 
index 3cfa12ede2a6c69c893d066139a6c37657d9ccca..3f2c2311dc00dcaae047af96805881f0360c8f6c 100644 (file)
@@ -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);
 }
index 87aa3ca88a1b21b064730b3888b79ccee28a53fb..de37750fecdc3b736e5b7605f0b84d2d4d81c463 100644 (file)
@@ -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;
                }