Skip to content

Commit

Permalink
updated to work on beta 0.1.074b
Browse files Browse the repository at this point in the history
improved quality of text in images
  • Loading branch information
farzher committed Sep 2, 2023
1 parent 33c43f9 commit 1a2eb15
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 179 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Nowhere near as advanced as Ditto, but this does support db encryption https://g
- database encryption
- streamer mode - everytime clipman's opened all information is censored until you click or hit tab
- images compressed using webp to keep the .db file small
- the original image is saved to the %temp% folder and will be used until it's gone
- start typing to filter to clips containing that text
- right click -> Context - goto the first time a clip was copied to see what else was copied around that same time
- hover over the right half of a clip to get a quick detailed view of it
Expand All @@ -21,7 +22,7 @@ Nowhere near as advanced as Ditto, but this does support db encryption https://g
Download the repo then run `release/clipman.exe`

# Build From Source
0. have #the_compiler(v0.1.56)
0. have #the_compiler(beta 0.1.074b, built on 26 August 2023)
1. run `dev.bat` or `build_release.bat`

# Understanding The Source Code
Expand Down
Binary file added bin/release.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions first.jai
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/


RELEASE :: #run get_build_options().optimization_level == .RELEASE;
RELEASE :: #run get_build_options().array_bounds_check == .OFF;
main_filepath :: "src/main.jai";
exe_icon_path :: "bin/tray.ico";
exe_name :: "clipman";
Expand Down Expand Up @@ -70,8 +70,8 @@ replace_autogenerated :: (filepath: string, name: string, value: string) {

compiler_version_string :: #run -> string {
compiler_version_info: Version_Info;
compiler_get_version_info(*compiler_version_info);
return tprint("v%.%.%", compiler_version_info.major, compiler_version_info.minor, compiler_version_info.micro);
return compiler_get_version_info(*compiler_version_info);
// return tprint("v%.%.%", compiler_version_info.major, compiler_version_info.minor, compiler_version_info.micro);
};


Expand Down
Binary file modified release/clipman.exe
Binary file not shown.
8 changes: 3 additions & 5 deletions src/functions.jai
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,11 @@ save_bitmap_to_file :: (bitmapinfobytes: string, filepath: string) -> bool {
case "png";
return stbi.stbi_write_png(name, bitmap.width, bitmap.height, components, data, stride) != 0;
case "tga";
return stbi.stbi_write_tga(name, bitmap.width, bitmap.height, components, data, stride) != 0;
return stbi.stbi_write_tga(name, bitmap.width, bitmap.height, components, data) != 0;
case "bmp";
return stbi.stbi_write_bmp(name, bitmap.width, bitmap.height, components, data, stride) != 0;
case "hdr";
return stbi.stbi_write_hdr(name, bitmap.width, bitmap.height, components, data, stride) != 0;
return stbi.stbi_write_bmp(name, bitmap.width, bitmap.height, components, data) != 0;
case "jpg";
return stbi.stbi_write_jpg(name, bitmap.width, bitmap.height, components, data, stride, quality=80) != 0;
return stbi.stbi_write_jpg(name, bitmap.width, bitmap.height, components, data, quality=80) != 0;
case;
mylog("Bitmap extension", extension, "is not understood by this code.");
return false;
Expand Down
85 changes: 47 additions & 38 deletions src/main.jai
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ main :: () {

// create the main window
hwnd = create_window(
window_name=#run _("%{APP_NAME} %{VERSION}"),
width=window_width, height=window_height,
background_color_rgb=COLORS.to_3f(COLORS.DARK),
style=WS_POPUP,
style_ex=WS_EX_LAYERED | WS_EX_TOOLWINDOW
window_name = #run interp("%{APP_NAME} %{VERSION}"),
width = window_width,
height = window_height,
background_color_rgb = COLORS.to_3f(COLORS.DARK),
style = WS_POPUP,
style_ex = WS_EX_LAYERED | WS_EX_TOOLWINDOW
);
set_window_pos_to_mouse(hwnd);
show_window(false);
Expand All @@ -65,7 +66,7 @@ main :: () {
init_everything();

// create tray icon
trayicon_create(tooltip=#run _("%{APP_NAME} %{VERSION}"));
trayicon_create(tooltip=#run interp("%{APP_NAME} %{VERSION}"));

// main game loop
while 1 {
Expand Down Expand Up @@ -183,7 +184,7 @@ init_db :: (key: string = "") {
total_copy_count = db.select_int("select count(1) from copy");

if !is_db_locked && total_copy_count==0 {
insert_into_db(#run _(#string STR
insert_into_db(#run interp(#string STR
%{APP_NAME} %{VERSION} by farzher
Alt + ` (backtick/tilde ~) to toggle
Hover over the right half of this clip to expand it
Expand Down Expand Up @@ -394,7 +395,6 @@ render :: () {
i := records.count-1; while i >= 0 { defer i -= 1;
record := records[i];

render_record_background();
render_record_background :: () #expand {

background_color := COLORS.DARK;
Expand All @@ -415,21 +415,21 @@ render :: () {
Simp.set_shader_for_color();
Simp.immediate_quad(cast(float)0, window_height - cast(float)i*config.record_height, cast(float)window_width, window_height - cast(float)i*config.record_height-record_height, background_color);
}
render_record_background();

render_metadata();
render_metadata :: () #expand {
if hover_index == i {
metatext := utc_to_time_ago(record.first_seen_at);
if order_by == "bytecount" {
metatext = _("bytecount = ${record.bytecount}; ${metatext}");
metatext = interp("bytecount = ${record.bytecount}; ${metatext}");
}
text_width := Simp.prepare_text(my_tiny_font, metatext);
Simp.draw_prepared_text(my_tiny_font, window_width-text_width-10, window_height - i*config.record_height - config.record_height+12, COLORS.TEXT);
}
}
render_metadata();


render_lines_of_text_or_img();
render_lines_of_text_or_img :: () #expand {

// if it's an img, or at least sometimes an img (ex imgur)
Expand All @@ -447,7 +447,14 @@ render :: () {
width := texture.width * ratio;
height := texture.height * ratio;
Simp.set_shader_for_images(texture);
Simp.immediate_quad(x, y, x + width, y - height, COLORS.WHITE);

// why are these different?????????? one of them is upside down. i don't get it
if record.type == .BITMAP || record.type == .WEBP {
Simp.immediate_quad(x, y, x + width, y - height, COLORS.WHITE);
} else {
Simp.immediate_quad(x, y - height, x + width, y, COLORS.WHITE);
}

return;
}

Expand Down Expand Up @@ -497,12 +504,12 @@ render :: () {

}
}
render_lines_of_text_or_img();
}

render_errors();
render_errors :: () #expand {
if is_config_parse_error {
for line, line_i: string.["CONFIG IS CORRUPT", #run _("Fix or delete your %{CONFIG_PATH} file")] {
for line, line_i: string.["CONFIG IS CORRUPT", #run interp("Fix or delete your %{CONFIG_PATH} file")] {
text_width := Simp.prepare_text(my_font, line);
Simp.draw_prepared_text(my_font, (window_width-text_width)/2, window_height - (my_font.character_height*(2+line_i)), COLORS.TEXT);
}
Expand All @@ -518,9 +525,9 @@ render :: () {
}
}
}
render_errors();


render_search_string();
render_search_string :: () #expand {
ms := getms();
if ms - search_input.last_keypress_time >= 1000 then return;
Expand Down Expand Up @@ -555,9 +562,9 @@ render :: () {
// }
// }
}
render_search_string();


render_scroll_bar();
render_scroll_bar :: () #expand {
if scroll_offset > 0 && total_copy_count>0 {
scroll_percent := cast(float)(scroll_offset + records.count) / total_copy_count;
Expand All @@ -574,6 +581,7 @@ render :: () {
}
}
}
render_scroll_bar();

Simp.swap_buffers(hwnd);
DwmFlush(); // simp opengl vsync burns 100% cpu without this
Expand Down Expand Up @@ -617,15 +625,15 @@ update_records :: () {
id_str := substr(<<search_string, "id:".count, -"id:".count);
id := parse_int(*id_str);
if id {
rows = db.select(to_c_string(_("${the_select_from} where id=? limit 1"), temp), id);
rows = db.select(to_c_string(interp("${the_select_from} where id=? limit 1"), temp), id);
}
} else if search_string.count {
// todo split search into multiples on space
// map(split(search_string), "preview like '%'||?||'%'"
// join(, " AND ")
rows = db.select(to_c_string(_("${the_select_from} where type=? and preview like '%'||?||'%' ORDER BY %{order_by} DESC LIMIT ? OFFSET ?"), temp), cast(int)COPY_TYPE.TEXT, <<search_string, max_records, scroll_offset);
rows = db.select(to_c_string(interp("${the_select_from} where type=? and preview like '%'||?||'%' ORDER BY %{order_by} DESC LIMIT ? OFFSET ?"), temp), cast(int)COPY_TYPE.TEXT, <<search_string, max_records, scroll_offset);
} else {
rows = db.select(to_c_string(_("${the_select_from} ORDER BY %{order_by} DESC LIMIT ? OFFSET ?"), temp), max_records, scroll_offset);
rows = db.select(to_c_string(interp("${the_select_from} ORDER BY %{order_by} DESC LIMIT ? OFFSET ?"), temp), max_records, scroll_offset);
}

for row: rows {
Expand Down Expand Up @@ -848,7 +856,6 @@ insert_into_db :: (_str: string, _copy_type: COPY_TYPE = .TEXT) {
copy_type := _copy_type; // to make it not immutable
if _copy_type == .BITMAP then str = compress(str);

if_the_image_is_big_compress_it();
if_the_image_is_big_compress_it :: () #expand {
if _copy_type == .BITMAP {
// if str.count > 10000 {
Expand All @@ -859,6 +866,7 @@ insert_into_db :: (_str: string, _copy_type: COPY_TYPE = .TEXT) {
// }
}
}
if_the_image_is_big_compress_it();

// if this record has already been inserted, just update it instead of inserting a copy
existing_record_id: int;
Expand Down Expand Up @@ -893,7 +901,7 @@ insert_into_db :: (_str: string, _copy_type: COPY_TYPE = .TEXT) {
}
if !record_id {
} else {
write_entire_file_to_clipman_cache_temp_folder(_("${record_id}"), compress(_str));
write_entire_file_to_clipman_cache_temp_folder(interp("${record_id}"), compress(_str));
}

}
Expand All @@ -903,6 +911,24 @@ insert_into_db :: (_str: string, _copy_type: COPY_TYPE = .TEXT) {
}

import_from_ditto_db :: (ditto_filepath: string) {

tmp_insert_into_db :: (str: string, first_seen_at: int, last_seen_at: int, copy_type: COPY_TYPE = .TEXT) -> success: bool {
exists_id: int = db.select_int("select id from copy where preview = ? and type=? limit 1", str, cast(int)copy_type);

if exists_id return false;

success := db.query("INSERT INTO copy (preview, last_seen_at, first_seen_at, type) VALUES (?, ?, ?, ?)", str, last_seen_at, first_seen_at, cast(int)copy_type);
if !success then {
mylog("!success", first_seen_at);
return false;
}

total_copy_count += 1;
selected_index = 0;
scroll_offset = 0;
return true;
}

MAXIMUM_CLIP_LENGTH :: 10_000;

mylog("starting ditto import");
Expand Down Expand Up @@ -937,23 +963,6 @@ import_from_ditto_db :: (ditto_filepath: string) {
if inserted mylog(ooData);
}

tmp_insert_into_db :: (str: string, first_seen_at: int, last_seen_at: int, copy_type: COPY_TYPE = .TEXT) -> success: bool {
exists_id: int = db.select_int("select id from copy where preview = ? and type=? limit 1", str, cast(int)copy_type);

if exists_id return false;

success := db.query("INSERT INTO copy (preview, last_seen_at, first_seen_at, type) VALUES (?, ?, ?, ?)", str, last_seen_at, first_seen_at, cast(int)copy_type);
if !success then {
mylog("!success", first_seen_at);
return false;
}

total_copy_count += 1;
selected_index = 0;
scroll_offset = 0;
return true;
}

mylog("ditto import finished");
}

Expand Down
31 changes: 16 additions & 15 deletions src/modules/Simp/backend/gl.jai
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ backend_init :: (info: *Window_Info) {
the_gl_context = hglrc;
the_hdc_for_pixel_format_cloning = hdc;
info.specific.hdc = hdc;
}
#if OS == .LINUX {
} else #if OS == .LINUX {
the_gl_context, the_gl_fbc = glx_create_context(MINIMUM_GL_MAJOR_VERSION, MINIMUM_GL_MINOR_VERSION);
}
#if OS == .MACOS {
} else #if OS == .MACOS {
the_gl_context = nsgl_create_context(MINIMUM_GL_MAJOR_VERSION, MINIMUM_GL_MINOR_VERSION);
autorelease(the_gl_context);
}
Expand Down Expand Up @@ -370,12 +368,11 @@ draw_generated_quads :: (font: *Dynamic_Font, color := Vector4.{1, 1, 1, 1}) {
if page.bitmap_data.width <= 1 return;
if page.bitmap_data.height <= 1 return;

// @Speed: Get rid of these silly make_vector2s.
using quad;
uv0 := make_vector2(u0, v0);
uv1 := make_vector2(u1, v0);
uv2 := make_vector2(u1, v1);
uv3 := make_vector2(u0, v1);
uv0 := Vector2.{u0, v0};
uv1 := Vector2.{u1, v0};
uv2 := Vector2.{u1, v1};
uv3 := Vector2.{u0, v1};

immediate_quad(p0, p1, p2, p3, color, uv0, uv1, uv2, uv3);
}
Expand All @@ -387,8 +384,6 @@ draw_generated_quads :: (font: *Dynamic_Font, color := Vector4.{1, 1, 1, 1}) {

last_texture: s64 = -1;

glBegin(GL_TRIANGLES);

for quad, i: quads {
page := quad.glyph.page;
map := *page.texture;
Expand All @@ -402,24 +397,20 @@ draw_generated_quads :: (font: *Dynamic_Font, color := Vector4.{1, 1, 1, 1}) {
immediate_flush();
handle := map.gl_handle;
last_texture = handle;
glEnd();

shader := state.current_shader;
loc := glGetUniformLocation(shader.gl_handle, "text_sampler");
if loc < 0 log_error("Unable to find text_sampler in shader_text!");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, handle); // Bind handle to slot 0.
glUniform1i(loc, 0);

glBegin(GL_TRIANGLES); // @Speed!
}

draw_letter_quad(font, quad, color);
}

immediate_flush();

glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
Expand Down Expand Up @@ -647,7 +638,11 @@ backend_update_texture :: (texture: *Texture, bitmap: *Bitmap) {
texture_target :: GL_TEXTURE_2D;
glBindTexture(texture_target, texture.gl_handle);

bpp := get_image_bytes_per_texel(bitmap.format);
stride_in_pixels := ifx bpp then bitmap.stride/bpp else bitmap.width;

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, xx stride_in_pixels);
glTexImage2D(texture_target, 0, xx internal_format, xx bitmap.width, xx bitmap.height, 0, gl_format, gl_type, bitmap.data.data);

// resource_size := update_texture_2d(map, compressed, gl_format, gl_type, bittexture.data);
Expand Down Expand Up @@ -676,6 +671,12 @@ backend_set_texture :: (shader: *Shader, texture: *Texture) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture.gl_handle); // Bind handle to slot 0.
glUniform1i(loc, 0);

// farzher hack
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// glGenerateMipmap(GL_TEXTURE_2D);
}

backend_resize_render_target :: (info: Window_Info) {
Expand Down
Loading

0 comments on commit 1a2eb15

Please sign in to comment.