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,80 +186,91 @@ 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;
// white: false, black: true
var color: bool = false;
while (i < file_docmaps.items[0].contents.len) : (i += 1) {
if (file_docmaps.items[0].contents[i] == 10) {
y += 1;
if (y > window_height) {
y = 0;
column += 1;
// std.debug.print("Column: {any}, x: {any}\n", .{column, column*column_width});
}
x = column * column_width;
continue; 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");
} }
if (file_docmaps.items[0].contents[i] == 32 and color) { y += docmap.title_text.rect.h;
color = false; // white: false, black: true
const white_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); var color: bool = false;
if (white_color_result != 0) { while (i < docmap.contents.len) : (i += 1) {
c.SDL_Log("Unable to set draw color: %d", white_color_result); if (docmap.contents[i] == 10) {
return error.SDLInitializationFailed; y += 1;
} if (y > window_height) {
} else if (file_docmaps.items[0].contents[i] != 32 and !color) { y = 0;
color = true; column += 1;
const black_color_result = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // std.debug.print("Column: {any}, x: {any}\n", .{column, column*column_width});
if (black_color_result != 0) { }
c.SDL_Log("Unable to set draw color: %d", black_color_result); x = column * column_width;
return error.SDLInitializationFailed;
}
}
if (x < (column + 1) * column_width) { continue;
const draw_result = c.SDL_RenderDrawPoint(renderer, x, y);
if (draw_result != 0) {
c.SDL_Log("Unable to draw point: %d", draw_result);
return error.SDLDrawingFailed;
}
} else {
const red_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
if (red_color_result != 0) {
c.SDL_Log("Unable to set draw color: %d", red_color_result);
return error.SDLInitializationFailed;
} }
const draw_result = c.SDL_RenderDrawPoint(renderer, (column + 1) * column_width - 1, y); if (docmap.contents[i] == 32 and color) {
if (draw_result != 0) { color = false;
c.SDL_Log("Unable to draw point: %d", draw_result);
return error.SDLDrawingFailed;
}
if (!color) {
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 { } else if (docmap.contents[i] != 32 and !color) {
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) {
c.SDL_Log("Unable to set draw color: %d", black_color_result); c.SDL_Log("Unable to set draw color: %d", black_color_result);
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
} }
} }
if (x < (column + 1) * column_width) {
const draw_result = c.SDL_RenderDrawPoint(renderer, x, y);
if (draw_result != 0) {
c.SDL_Log("Unable to draw point: %d", draw_result);
return error.SDLDrawingFailed;
}
} else {
const red_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
if (red_color_result != 0) {
c.SDL_Log("Unable to set draw color: %d", red_color_result);
return error.SDLInitializationFailed;
}
const draw_result = c.SDL_RenderDrawPoint(renderer, (column + 1) * column_width - 1, y);
if (draw_result != 0) {
c.SDL_Log("Unable to draw point: %d", draw_result);
return error.SDLDrawingFailed;
}
if (!color) {
const white_color_result = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
if (white_color_result != 0) {
c.SDL_Log("Unable to set draw color: %d", white_color_result);
return error.SDLInitializationFailed;
}
} else {
const black_color_result = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
if (black_color_result != 0) {
c.SDL_Log("Unable to set draw color: %d", black_color_result);
return error.SDLInitializationFailed;
}
}
}
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);