Display multiple files

This commit is contained in:
Nathan McRae 2023-06-19 23:09:23 -07:00
parent aade06e600
commit 0da13751d5

View File

@ -84,10 +84,8 @@ pub fn main() !void {
var file_paths = std.ArrayList([]const u8).init(allocator); var file_paths = std.ArrayList([]const u8).init(allocator);
defer file_paths.deinit(); defer file_paths.deinit();
try file_paths.append("GapProbeScan.cs");
try file_paths.append("src/main.zig"); try file_paths.append("src/main.zig");
// const file_name = "GapProbeScan.cs"; try file_paths.append("GapProbeScan.cs");
// const source_code = @embedFile(file_name);
var file_docmaps = std.ArrayList(FileDocMap).init(allocator); var file_docmaps = std.ArrayList(FileDocMap).init(allocator);
defer file_docmaps.deinit(); defer file_docmaps.deinit();
@ -172,6 +170,7 @@ pub fn main() !void {
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
} }
// Draw white background
var x: c_int = 0; var x: c_int = 0;
while (x < window_width) : (x += 1) { while (x < window_width) : (x += 1) {
var y: c_int = 0; var y: c_int = 0;
@ -187,11 +186,28 @@ pub fn main() !void {
var i: usize = 0; var i: usize = 0;
var column: c_int = 0; var column: c_int = 0;
x = 0; x = 0;
var y: c_int = file_docmaps.items[0].title_text.rect.h; var y: c_int = 0;
for (file_docmaps.items) |docmap| {
i = 0;
var rect = c.SDL_Rect {
.x = x,
.y = y,
.w = docmap.title_text.surface.*.w,
.h = docmap.title_text.surface.*.h,
};
// Display text
if (c.SDL_RenderCopy(renderer, docmap.title_text.texture, null, &rect) != 0) {
c.SDL_Log("Unable to render copy");
}
y += docmap.title_text.rect.h;
// white: false, black: true // white: false, black: true
var color: bool = false; var color: bool = false;
while (i < file_docmaps.items[0].contents.len) : (i += 1) { while (i < docmap.contents.len) : (i += 1) {
if (file_docmaps.items[0].contents[i] == 10) { if (docmap.contents[i] == 10) {
y += 1; y += 1;
if (y > window_height) { if (y > window_height) {
y = 0; y = 0;
@ -203,14 +219,14 @@ pub fn main() !void {
continue; continue;
} }
if (file_docmaps.items[0].contents[i] == 32 and color) { if (docmap.contents[i] == 32 and color) {
color = false; color = false;
const white_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); const white_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
if (white_color_result != 0) { if (white_color_result != 0) {
c.SDL_Log("Unable to set draw color: %d", white_color_result); c.SDL_Log("Unable to set draw color: %d", white_color_result);
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
} }
} else if (file_docmaps.items[0].contents[i] != 32 and !color) { } else if (docmap.contents[i] != 32 and !color) {
color = true; color = true;
const black_color_result = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); const black_color_result = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
if (black_color_result != 0) { if (black_color_result != 0) {
@ -255,12 +271,6 @@ pub fn main() !void {
x += 1; x += 1;
} }
const text = file_docmaps.items[0].title_text;
// Display text
if (c.SDL_RenderCopy(renderer, text.texture, null, &(text.rect)) != 0) {
c.SDL_Log("Unable to render copy");
} }
c.SDL_RenderPresent(renderer); c.SDL_RenderPresent(renderer);