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);
defer file_paths.deinit();
try file_paths.append("GapProbeScan.cs");
try file_paths.append("src/main.zig");
// const file_name = "GapProbeScan.cs";
// const source_code = @embedFile(file_name);
try file_paths.append("GapProbeScan.cs");
var file_docmaps = std.ArrayList(FileDocMap).init(allocator);
defer file_docmaps.deinit();
@ -172,6 +170,7 @@ pub fn main() !void {
return error.SDLInitializationFailed;
}
// Draw white background
var x: c_int = 0;
while (x < window_width) : (x += 1) {
var y: c_int = 0;
@ -187,80 +186,91 @@ pub fn main() !void {
var i: usize = 0;
var column: c_int = 0;
x = 0;
var y: c_int = file_docmaps.items[0].title_text.rect.h;
// 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;
var y: c_int = 0;
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) {
color = false;
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 if (file_docmaps.items[0].contents[i] != 32 and !color) {
color = true;
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;
}
}
y += docmap.title_text.rect.h;
// white: false, black: true
var color: bool = false;
while (i < docmap.contents.len) : (i += 1) {
if (docmap.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;
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;
continue;
}
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) {
if (docmap.contents[i] == 32 and color) {
color = false;
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 {
} else if (docmap.contents[i] != 32 and !color) {
color = true;
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;
}
}
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);