changes for dpi

This commit is contained in:
Allen Webster 2016-03-19 23:09:00 -04:00
parent 091c9d1f45
commit 73cc788e65
10 changed files with 97 additions and 64 deletions

View File

@ -246,6 +246,8 @@ enum Hook_ID{
hook_start, hook_start,
hook_open_file, hook_open_file,
hook_frame, hook_frame,
hook_new_file,
hook_file_out_of_sync,
// never below this // never below this
hook_type_count hook_type_count
}; };

42
4ed.cpp
View File

@ -3300,31 +3300,29 @@ App_Init_Sig(app_init){
i32 pt_size; i32 pt_size;
}; };
#define LitStr(n) n, sizeof(n)-1
int font_size = 16; int font_size = 16;
if (font_size < 8) font_size = 8; if (font_size < 8) font_size = 8;
Font_Setup font_setup[] = { Font_Setup font_setup[] = {
{LitStr("LiberationSans-Regular.ttf"), {literal("LiberationSans-Regular.ttf"),
LitStr("liberation sans"), literal("liberation sans"),
font_size}, font_size},
{LitStr("liberation-mono.ttf"), {literal("liberation-mono.ttf"),
LitStr("liberation mono"), literal("liberation mono"),
font_size}, font_size},
{LitStr("Hack-Regular.ttf"), {literal("Hack-Regular.ttf"),
LitStr("hack"), literal("hack"),
font_size}, font_size},
{LitStr("CutiveMono-Regular.ttf"), {literal("CutiveMono-Regular.ttf"),
LitStr("cutive mono"), literal("cutive mono"),
font_size}, font_size},
{LitStr("Inconsolata-Regular.ttf"), {literal("Inconsolata-Regular.ttf"),
LitStr("inconsolata"), literal("inconsolata"),
font_size}, font_size},
}; };
i32 font_count = ArrayCount(font_setup); i32 font_count = ArrayCount(font_setup);
@ -3334,7 +3332,7 @@ App_Init_Sig(app_init){
font_setup[i].file_name_len); font_setup[i].file_name_len);
String name = make_string(font_setup[i].c_name, String name = make_string(font_setup[i].c_name,
font_setup[i].name_len); font_setup[i].name_len);
i32 pt_size = font_setup[i].pt_size; i32 pt_size = DpiMultiplier(font_setup[i].pt_size, target->dpi);
font_set_add(partition, models->font_set, file_name, name, pt_size); font_set_add(partition, models->font_set, file_name, name, pt_size);
} }
@ -3430,11 +3428,16 @@ App_Step_Sig(app_step){
time_stamp = system->file_time_stamp(make_c_str(file->name.source_path)); time_stamp = system->file_time_stamp(make_c_str(file->name.source_path));
// TODO(allen): This is a bit wasteful! Let's dial it in a bit.
if (time_stamp > 0){ if (time_stamp > 0){
File_Sync_State prev_sync = buffer_get_sync(file);
file->state.last_sys_write_time = time_stamp; file->state.last_sys_write_time = time_stamp;
file->state.sync = buffer_get_sync(file);
if (file->state.last_sys_write_time != file->state.last_4ed_write_time){ if (file->state.last_sys_write_time != file->state.last_4ed_write_time){
app_result.redraw = 1; if (file->state.sync != prev_sync){
app_result.redraw = 1;
}
} }
} }
} }
@ -4338,6 +4341,15 @@ App_Step_Sig(app_step){
view_set_file(view, file, models, system, models->hooks[hook_open_file], &app_links); view_set_file(view, file, models, system, models->hooks[hook_open_file], &app_links);
view->map = app_get_map(models, file->settings.base_map_id); view->map = app_get_map(models, file->settings.base_map_id);
Hook_Function *new_file_fnc = models->hooks[hook_new_file];
if (new_file_fnc){
models->buffer_param_indices[models->buffer_param_count++] = file->id.id;
new_file_fnc(&app_links);
models->buffer_param_count = 0;
file->settings.is_initialized = 1;
}
#if BUFFER_EXPERIMENT_SCALPEL <= 0 #if BUFFER_EXPERIMENT_SCALPEL <= 0
if (file->settings.tokens_exist) if (file->settings.tokens_exist)
file_first_lex_parallel(system, general, file); file_first_lex_parallel(system, general, file);

View File

@ -120,14 +120,14 @@ delayed_action_repush(Delay *delay, Delayed_Action *act){
return(new_act); return(new_act);
} }
#define delayed_open(delay, ...) delayed_action_(delay, DACT_OPEN, __VA_ARGS__) #define delayed_open(delay, ...) delayed_action_(delay, DACT_OPEN, ##__VA_ARGS__)
#define delayed_open_background(delay, ...) delayed_action_(delay, DACT_OPEN_BACKGROUND, __VA_ARGS__) #define delayed_open_background(delay, ...) delayed_action_(delay, DACT_OPEN_BACKGROUND, ##__VA_ARGS__)
#define delayed_set_line(delay, ...) delayed_action_(delay, DACT_SET_LINE, __VA_ARGS__) #define delayed_set_line(delay, ...) delayed_action_(delay, DACT_SET_LINE, ##__VA_ARGS__)
#define delayed_save_as(delay, ...) delayed_action_(delay, DACT_SAVE_AS, __VA_ARGS__) #define delayed_save_as(delay, ...) delayed_action_(delay, DACT_SAVE_AS, ##__VA_ARGS__)
#define delayed_save(delay, ...) delayed_action_(delay, DACT_SAVE, __VA_ARGS__) #define delayed_save(delay, ...) delayed_action_(delay, DACT_SAVE, ##__VA_ARGS__)
#define delayed_new(delay, ...) delayed_action_(delay, DACT_NEW, __VA_ARGS__) #define delayed_new(delay, ...) delayed_action_(delay, DACT_NEW, ##__VA_ARGS__)
#define delayed_switch(delay, ...) delayed_action_(delay, DACT_SWITCH, __VA_ARGS__) #define delayed_switch(delay, ...) delayed_action_(delay, DACT_SWITCH, ##__VA_ARGS__)
#define delayed_try_kill(delay, ...) delayed_action_(delay, DACT_TRY_KILL, __VA_ARGS__) #define delayed_try_kill(delay, ...) delayed_action_(delay, DACT_TRY_KILL, ##__VA_ARGS__)
#define delayed_kill(delay, ...) delayed_action_(delay, DACT_KILL, __VA_ARGS__) #define delayed_kill(delay, ...) delayed_action_(delay, DACT_KILL, ##__VA_ARGS__)
#define delayed_touch_file(delay, ...) delayed_action_(delay, DACT_TOUCH_FILE, __VA_ARGS__) #define delayed_touch_file(delay, ...) delayed_action_(delay, DACT_TOUCH_FILE, ##__VA_ARGS__)
#define delayed_close(delay, ...) delayed_action_(delay, DACT_CLOSE, ##__VA_ARGS__) #define delayed_close(delay, ...) delayed_action_(delay, DACT_CLOSE, ##__VA_ARGS__)

View File

@ -81,6 +81,12 @@ struct Undo_Data{
b32 current_block_normal; b32 current_block_normal;
}; };
enum File_Sync_State{
SYNC_GOOD,
SYNC_BEHIND_OS,
SYNC_UNSAVED
};
struct Text_Effect{ struct Text_Effect{
i32 start, end; i32 start, end;
u32 color; u32 color;
@ -122,6 +128,7 @@ struct Editing_File_State{
Text_Effect paste_effect; Text_Effect paste_effect;
File_Sync_State sync;
u64 last_4ed_write_time; u64 last_4ed_write_time;
u64 last_4ed_edit_time; u64 last_4ed_edit_time;
u64 last_sys_write_time; u64 last_sys_write_time;
@ -747,12 +754,6 @@ hot_directory_first_match(Hot_Directory *hot_directory,
return result; return result;
} }
enum File_Sync_State{
SYNC_GOOD,
SYNC_BEHIND_OS,
SYNC_UNSAVED
};
inline File_Sync_State inline File_Sync_State
buffer_get_sync(Editing_File *file){ buffer_get_sync(Editing_File *file){
File_Sync_State result = SYNC_GOOD; File_Sync_State result = SYNC_GOOD;

View File

@ -280,6 +280,7 @@ file_synchronize_times(System_Functions *system, Editing_File *file, char *filen
file->state.last_4ed_edit_time = stamp; file->state.last_4ed_edit_time = stamp;
file->state.last_sys_write_time = stamp; file->state.last_sys_write_time = stamp;
} }
file->state.sync = buffer_get_sync(file);
} }
internal i32 internal i32
@ -1295,7 +1296,6 @@ view_set_file(
if (file_is_ready(file)){ if (file_is_ready(file)){
view_measure_wraps(system, &models->mem.general, view); view_measure_wraps(system, &models->mem.general, view);
view->cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos); view->cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos);
view->reinit_scrolling = 1; view->reinit_scrolling = 1;
} }
} }

View File

@ -241,7 +241,7 @@ char delayed_action_specialized_bottom[] =
"}\n\n"; "}\n\n";
char delayed_action_macro[] = char delayed_action_macro[] =
"#define delayed_%s(delay, ...) delayed_action_(delay, DACT_%s, __VA_ARGS__)\n"; "#define delayed_%s(delay, ...) delayed_action_(delay, DACT_%s, ##__VA_ARGS__)\n";
char delayed_action_repush_function[] = char delayed_action_repush_function[] =
"inline Delayed_Action*\n" "inline Delayed_Action*\n"

View File

@ -386,7 +386,8 @@ draw_font_load(void *base_block, i32 size,
Render_Font *font_out, Render_Font *font_out,
char *filename_untranslated, char *filename_untranslated,
i32 pt_size, i32 pt_size,
i32 tab_width){ i32 tab_width,
i32 oversample){
char space_[1024]; char space_[1024];
String filename = make_fixed_width_string(space_); String filename = make_fixed_width_string(space_);
@ -402,7 +403,6 @@ draw_font_load(void *base_block, i32 size,
stbtt_packedchar *chardata = font_out->chardata; stbtt_packedchar *chardata = font_out->chardata;
i32 oversample = 2;
i32 tex_width, tex_height; i32 tex_width, tex_height;
tex_width = pt_size*128*oversample; tex_width = pt_size*128*oversample;
@ -444,7 +444,7 @@ draw_font_load(void *base_block, i32 size,
if (stbtt_PackBegin(&spc, (u8*)block, tex_width, tex_height, tex_width, 1, partition)){ if (stbtt_PackBegin(&spc, (u8*)block, tex_width, tex_height, tex_width, 1, partition)){
stbtt_PackSetOversampling(&spc, oversample, oversample); stbtt_PackSetOversampling(&spc, oversample, oversample);
if (stbtt_PackFontRange(&spc, (u8*)file.data, 0, if (stbtt_PackFontRange(&spc, (u8*)file.data, 0,
STBTT_POINT_SIZE((f32)pt_size), 0, 128, chardata)){ STBTT_POINT_SIZE((f32)pt_size), 0, 128, chardata)){
// do nothing // do nothing
} }
else{ else{

View File

@ -187,8 +187,12 @@ struct Render_Target{
Draw_Push_Clip *push_clip; Draw_Push_Clip *push_clip;
Draw_Pop_Clip *pop_clip; Draw_Pop_Clip *pop_clip;
Draw_Push_Piece *push_piece; Draw_Push_Piece *push_piece;
i32 dpi;
}; };
#define DpiMultiplier(n,dpi) ((n) * (dpi) / 96)
inline i32_Rect inline i32_Rect
rect_from_target(Render_Target *target){ rect_from_target(Render_Target *target){
return i32R(0, 0, target->width, target->height); return i32R(0, 0, target->width, target->height);

View File

@ -63,16 +63,17 @@
; [X] mouse not working on interactive view ; [X] mouse not working on interactive view
; [X] reopen effects other view too? ; [X] reopen effects other view too?
; [X] allen's segfaults on linux launch ; [X] allen's segfaults on linux launch
; [X] open empty file bug
; [X] chronal's map setting issue
; [] indication on failure to save ; [] indication on failure to save
; [] clean whitespace doesn't appear to be cleaning trailing whitespace anymore??? ; [] clean whitespace doesn't appear to be cleaning trailing whitespace anymore???
; [] sometimes the main cursor is not the same width as the mark cursor in the same spot ; [] sometimes the main cursor is not the same width as the mark cursor in the same spot
; [] tab character wrong width ; [] tab character wrong width
; [] bouncing when scrolling down ; [] bouncing when scrolling down
; [] miblo's off screen cursor thing ; [] miblo's off screen cursor thing
;
; [] linux save jankieness ; [] linux save jankieness
; ;
; [] open empty file bug
; [] chronal's map setting issue
; ;
; ;
@ -96,10 +97,10 @@
; [X] improve file limit (now is > 8 million I think) ; [X] improve file limit (now is > 8 million I think)
; [X] get key stroke in custom callback ; [X] get key stroke in custom callback
; [X] tab option for auto-indent ; [X] tab option for auto-indent
; [X] catch unsaved files on close
; ;
; [] File status (saved, needs saving, out of sync) ; [] file status in custom API
; [] user file bar string ; [] user file bar string
; [] catch unsaved files on close
; ;
; [] feedback messages ; [] feedback messages
; [] command meta data ; [] command meta data
@ -113,8 +114,9 @@
; search related tech ; search related tech
; [X] replace word (incremental and/or in range) ; [X] replace word (incremental and/or in range)
; [] optimize search ; [] optimize search
; [] make search wrap around beginning/end ; [] allow search wrap around beginning/end
; [] polish for seeking ; [] improved custom API for text "streams"
; [] caps insensitivety
; ;
; GUI related tech ; GUI related tech
; [X] consolidate all GUI code properly ; [X] consolidate all GUI code properly

View File

@ -1437,6 +1437,7 @@ Win32Callback(HWND hwnd, UINT uMsg,
} }
Font_Load_Parameters *params = win32vars.fnt.params + lParam; Font_Load_Parameters *params = win32vars.fnt.params + lParam;
i32 oversample = DpiMultiplier(2, win32vars.target.dpi);
for (b32 success = 0; success == 0;){ for (b32 success = 0; success == 0;){
success = draw_font_load(win32vars.fnt.part.base, success = draw_font_load(win32vars.fnt.part.base,
@ -1444,7 +1445,8 @@ Win32Callback(HWND hwnd, UINT uMsg,
params->font_out, params->font_out,
params->filename, params->filename,
params->pt_size, params->pt_size,
params->tab_width); params->tab_width,
oversample);
if (!success){ if (!success){
Win32ScratchPartitionDouble(&win32vars.fnt.part); Win32ScratchPartitionDouble(&win32vars.fnt.part);
@ -1893,6 +1895,9 @@ main(int argc, char **argv){
window_style |= WS_MAXIMIZE; window_style |= WS_MAXIMIZE;
} }
// TODO(allen): not Windows XP compatible, do we care?
SetProcessDPIAware();
HWND window_handle = {}; HWND window_handle = {};
window_handle = CreateWindowA( window_handle = CreateWindowA(
window_class.lpszClassName, window_class.lpszClassName,
@ -1911,6 +1916,14 @@ main(int argc, char **argv){
HDC hdc = GetDC(window_handle); HDC hdc = GetDC(window_handle);
win32vars.window_hdc = hdc; win32vars.window_hdc = hdc;
i32 xdpi = GetDeviceCaps(hdc, LOGPIXELSX);
i32 ydpi = GetDeviceCaps(hdc, LOGPIXELSY);
win32vars.target.dpi = xdpi;
if (win32vars.target.dpi < ydpi){
win32vars.target.dpi = ydpi;
}
GetClientRect(window_handle, &window_rect); GetClientRect(window_handle, &window_rect);
static PIXELFORMATDESCRIPTOR pfd = { static PIXELFORMATDESCRIPTOR pfd = {
@ -1976,7 +1989,6 @@ main(int argc, char **argv){
} }
} }
File_Slot file_slots[32]; File_Slot file_slots[32];
sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0); sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0);