brighten color on hover instead of using col_highlight
This commit is contained in:
parent
c680a1b5c3
commit
2ba48f8784
2 changed files with 51 additions and 10 deletions
|
@ -1,3 +1,38 @@
|
||||||
|
constexpr f32 max3(f32 a, f32 b, f32 c)
|
||||||
|
{
|
||||||
|
return (a > b) ? (a > c) ? a : (b > c) ? b : c : (b > c) ? b : c;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Color_Rgb { f32 r, g, b; };
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/141855/programmatically-lighten-a-color
|
||||||
|
internal
|
||||||
|
Color_Rgb redist_rgb(Color_Rgb c)
|
||||||
|
{
|
||||||
|
f32 r = c.r;
|
||||||
|
f32 g = c.g;
|
||||||
|
f32 b = c.b;
|
||||||
|
f32 threshold = 255.999;
|
||||||
|
f32 m = max3(r, g, b);
|
||||||
|
if (m <= threshold)
|
||||||
|
return { r, g, b };
|
||||||
|
f32 total = r + g + b;
|
||||||
|
if (total >= 3 * threshold)
|
||||||
|
return { threshold, threshold, threshold };
|
||||||
|
f32 x = (3 * threshold - total) / (3 * m - total);
|
||||||
|
f32 gray = threshold - x * m;
|
||||||
|
return { gray + x * r, gray + x * g, gray + x * b };
|
||||||
|
}
|
||||||
|
|
||||||
|
internal
|
||||||
|
Color_Rgb brighten(Color_Rgb c, f32 amt)
|
||||||
|
{
|
||||||
|
f32 a = 1.f + amt;
|
||||||
|
Color_Rgb cb = { c.r * a, c.g * a, c.b * a };
|
||||||
|
cb = redist_rgb(cb);
|
||||||
|
return cb;
|
||||||
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
void accum_dt_ms(Delta_Time_Accum &accum, f32 dt)
|
void accum_dt_ms(Delta_Time_Accum &accum, f32 dt)
|
||||||
{
|
{
|
||||||
|
@ -22,9 +57,13 @@ f32 calc_avg_dt_ms(const Delta_Time_Accum &accum)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
ImColor imcol(const f32 col[3])
|
ImColor imcol(const f32 col[3], f32 brighten_amt = 0)
|
||||||
{
|
{
|
||||||
return ImColor(col[0], col[1], col[2]);
|
Color_Rgb c = { col[0], col[1], col[2] };
|
||||||
|
if (brighten_amt != 0)
|
||||||
|
c = brighten(c, brighten_amt);
|
||||||
|
|
||||||
|
return ImColor(c.r, c.g, c.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
|
@ -33,17 +72,18 @@ u32 mem_edit_bg_color_fn(const u8 *, u64 off, void *user_data)
|
||||||
App_State *app = reinterpret_cast<App_State *>(user_data);
|
App_State *app = reinterpret_cast<App_State *>(user_data);
|
||||||
off += app->base_display_addr;
|
off += app->base_display_addr;
|
||||||
|
|
||||||
|
f32 brighten = 0;
|
||||||
if (app->viewer.hovered_range.start <= off && off < app->viewer.hovered_range.end())
|
if (app->viewer.hovered_range.start <= off && off < app->viewer.hovered_range.end())
|
||||||
return imcol(app->viewer.col_highlight);
|
brighten = 0.3;
|
||||||
|
|
||||||
i64 hilite_cluster = app->viewer.highlight_cluster ? app->viewer.highlighted_cluster : -1;
|
i64 hilite_cluster = app->viewer.highlight_cluster ? app->viewer.highlighted_cluster : -1;
|
||||||
Section section = find_section(*app, off, hilite_cluster);
|
Section section = find_section(*app, off, hilite_cluster);
|
||||||
|
|
||||||
if (section.highlighted) return imcol(app->viewer.col_highlight);
|
if (section.highlighted) return imcol(app->viewer.col_highlight, brighten);
|
||||||
if (section.id == Sec_Page && off == section.range.start) return imcol(app->viewer.col_page_start);
|
if (section.id == Sec_Page && off == section.range.start) return imcol(app->viewer.col_page_start, brighten);
|
||||||
if (off < section.range.start) return imcol(app->viewer.col_key);
|
if (off < section.range.start) return imcol(app->viewer.col_key, brighten);
|
||||||
if (section.range.end() - section.post_size <= off && off < section.range.end()) return imcol(app->viewer.col_checksum);
|
if (section.range.end() - section.post_size <= off && off < section.range.end()) return imcol(app->viewer.col_checksum, brighten);
|
||||||
return imcol(app->viewer.col_section[section.id]);
|
return imcol(app->viewer.col_section[section.id], brighten);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
|
@ -101,8 +141,7 @@ void make_viewer(App_State &app, u16 n_cols)
|
||||||
internal
|
internal
|
||||||
void viewer_jump_to(App_State &app, u64 addr)
|
void viewer_jump_to(App_State &app, u64 addr)
|
||||||
{
|
{
|
||||||
app.base_display_addr = addr;
|
app.viewer.mem_edit.GotoAddr = addr;
|
||||||
app.viewer.mem_edit.GotoAddr = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
internal
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
// We are forced to use our own RNTuple anchor struct because we cannot
|
||||||
|
// write into the private members of the real RNTuple class from RMicroFileReader.
|
||||||
struct RNTuple_Anchor {
|
struct RNTuple_Anchor {
|
||||||
/// Version of the RNTuple binary format that the writer supports (see specification).
|
/// Version of the RNTuple binary format that the writer supports (see specification).
|
||||||
/// Changing the epoch indicates backward-incompatible changes
|
/// Changing the epoch indicates backward-incompatible changes
|
||||||
|
|
Loading…
Reference in a new issue