diff --git a/includes/list.h b/includes/list.h index 1ad3bf8..44cac82 100644 --- a/includes/list.h +++ b/includes/list.h @@ -18,6 +18,6 @@ typedef struct { List* CreateList(SDL_FRect boundingBox); void AddStringToList(char* text, List* list); -void RenderList(SDL_Renderer* renderer, SDL_FPoint motion, TTF_Font* font, unsigned short fontSize, List* list); +void RenderList(SDL_Renderer* renderer, SDL_Point motion, TTF_Font* font, unsigned short fontSize, List* list); #endif \ No newline at end of file diff --git a/src/list.c b/src/list.c index 67e873a..8f02f34 100644 --- a/src/list.c +++ b/src/list.c @@ -36,9 +36,12 @@ void AddStringToList(char* text, List* list) { list->Size++; } -void RenderList(SDL_Renderer* renderer, SDL_FPoint motion, TTF_Font* font, unsigned short fontSize, List* list) { +void RenderList(SDL_Renderer* renderer, SDL_Point motion, TTF_Font* font, unsigned short fontSize, List* list) { //SDL_Surface* surface = TTF_RenderText_Blended_Wrapped(font, list->Strings[0], (SDL_Color){255, 255, 255, 0}, 90); TextureDetails* details = GetTextureFromCache(list->TextureCache, 0); + SDL_FRect contentsBox = { .x = list->BoundingBox.x + list->BoundingBox.w * .125, .y = list->BoundingBox.y, .w = list->BoundingBox.w * 0.75, .h = list->BoundingBox.h * 0.15 }; + + SDL_RenderDrawRectF(renderer, &list->BoundingBox); if (!details || fontSize != details->FontSize) { SDL_Rect textSize; @@ -55,9 +58,45 @@ void RenderList(SDL_Renderer* renderer, SDL_FPoint motion, TTF_Font* font, unsig else details = AddTextureToCache(tex, fontSize, textSize, list->TextureCache); } + for (int i = 0; i < list->Size; i++) { + SDL_RenderDrawRectF(renderer, &contentsBox); + TextureDetails* details = GetTextureFromCache(list->TextureCache, i + 1); + char* item = list->Strings[i]; + + if (!details || fontSize != details->FontSize) { + SDL_Rect textSize; + TTF_SizeUTF8(font, item, &textSize.w, &textSize.h); + SDL_Surface* surface = TTF_RenderText_Shaded(font, item, (SDL_Color){255, 255, 255, 0}, (SDL_Color){0, 0, 0, 0}); + + SDL_Texture* tex = SDL_CreateTextureFromSurface(renderer, surface); + + SDL_FreeSurface(surface); + + if (details) UpdateTextureDetails(tex, fontSize, textSize, i+1, list->TextureCache); + else details = AddTextureToCache(tex, fontSize, textSize, list->TextureCache); + } + + SDL_FRect textArea; + textArea.x = contentsBox.x + contentsBox.w * 0.50 - details->TextSize.w * 0.50; + textArea.y = contentsBox.h * ( i + 1 ); + textArea.w = details->TextSize.w; + textArea.h = details->TextSize.h; + + //contentsBox.x = xOrg + contentsBox.w - details->TextSize.w * 0.50; + + + SDL_RenderCopyF(renderer, details->Texture, NULL, &textArea); + } + SDL_FRect size; - size.x = list->BoundingBox.x; - size.y = list->BoundingBox.y; + + float y = list->BoundingBox.y + motion.y - details->TextSize.h; + + if (y < list->BoundingBox.y) y = 0; + else if (y > list->BoundingBox.h) y = list->BoundingBox.h - details->TextSize.h; + + size.x = contentsBox.x; + size.y = y; size.h = details->TextSize.h; size.w = details->TextSize.w; diff --git a/src/main.c b/src/main.c index af76be3..5f8dc44 100644 --- a/src/main.c +++ b/src/main.c @@ -119,9 +119,10 @@ int main(int argc, char** argv){ SDL_FreeSurface(surface); - SDL_FRect boundingBox = {650, 700, 300, 90}; + SDL_FRect boundingBox = {SCREEN_WIDTH * 0.25, 0, SCREEN_WIDTH * 0.50, SCREEN_HEIGHT}; List* list = CreateList(boundingBox); + AddStringToList("Hello World!", list); // Uint64 start = 0; // Uint64 end = 0; @@ -166,7 +167,7 @@ int main(int argc, char** argv){ SDL_RenderCopyF(app.renderer, texture, NULL, &(SDL_FRect){rect2.x + XRel, rect2.y + YRel, textSize.w * ZoomLevel, textSize.h * ZoomLevel}); - RenderList(app.renderer, (SDL_FPoint) {0,0}, GetFont(app.DefaultFontSize * ZoomLevel, app.FontCache), app.DefaultFontSize * ZoomLevel, list); + RenderList(app.renderer, (SDL_Point) {XRel,YRel}, GetFont(app.DefaultFontSize * ZoomLevel, app.FontCache), app.DefaultFontSize * ZoomLevel, list); SDL_RenderPresent(app.renderer);