UI: Dim Text Editor and Console Cursors When Inactive #117462

Open
Harley Acheson wants to merge 3 commits from Harley/blender:HideCursors into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 83 additions and 7 deletions

View File

@ -87,7 +87,9 @@ struct SpaceType {
void (*listener)(const wmSpaceTypeListenerParams *params);
/* called when the mouse moves out of the area */
void (*deactivate)(ScrArea *area);
void (*deactivate)(bContext *C, ScrArea *area);
/* called when the mouse moves into the area */
void (*activate)(bContext *C, struct ScrArea *sa);
/** Refresh context, called after file-reads, #ED_area_tag_refresh(). */
void (*refresh)(const bContext *C, ScrArea *area);

View File

@ -982,7 +982,12 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2])
LISTBASE_FOREACH (ARegion *, region, &area_iter->regionbase) {
/* Call old area's deactivate if assigned. */
if (region == region_prev && area_iter->type && area_iter->type->deactivate) {
area_iter->type->deactivate(area_iter);
area_iter->type->deactivate(C, area_iter);
}
/* call new area's activate handler if defined */
if (region == screen->active_region && area_iter->type->activate) {
area_iter->type->activate(C, area_iter);
}
if (region == region_prev && region != screen->active_region) {

View File

@ -132,9 +132,9 @@ static void console_cursor_wrap_offset(
static void console_textview_draw_cursor(TextViewContext *tvc, int cwidth, int columns)
{
const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
int pen[2];
{
const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
int offl = 0, offc = 0;
@ -151,14 +151,26 @@ static void console_textview_draw_cursor(TextViewContext *tvc, int cwidth, int c
}
/* cursor */
GPU_blend(GPU_BLEND_ALPHA);
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformThemeColor(TH_CONSOLE_CURSOR);
float color[4];
UI_GetThemeColor4fv(TH_CONSOLE_CURSOR, color);
if (sc->hide_cursor) {
float gray = rgb_to_grayscale(color);
color[0] = gray;
color[1] = gray;
color[2] = gray;
color[3] = 0.7f;
}
immUniformColor4fv(color);
immRectf(pos, pen[0] - U.pixelsize, pen[1], pen[0] + U.pixelsize, pen[1] + tvc->lheight);
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
}
static void console_textview_const_colors(TextViewContext * /*tvc*/, uchar bg_sel[4])

View File

@ -321,6 +321,24 @@ static void console_space_blend_write(BlendWriter *writer, SpaceLink *sl)
BLO_write_struct(writer, SpaceConsole, sl);
}
static void console_activate(bContext *C, struct ScrArea *area)
{
SpaceConsole *sc = static_cast<SpaceConsole *>(area->spacedata.first);
sc->hide_cursor = false;
/* Redraw to show active caret. */
ED_region_tag_redraw(BKE_area_find_region_type(area, RGN_TYPE_WINDOW));
}
static void console_deactivate(bContext *C, struct ScrArea *area)
{
SpaceConsole *sc = static_cast<SpaceConsole *>(area->spacedata.first);
sc->hide_cursor = true;
/* Redraw to remove active caret. */
ED_region_tag_redraw(BKE_area_find_region_type(area, RGN_TYPE_WINDOW));
}
void ED_spacetype_console()
{
std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
@ -338,6 +356,8 @@ void ED_spacetype_console()
st->dropboxes = console_dropboxes;
st->blend_read_data = console_blend_read_data;
st->blend_write = console_space_blend_write;
st->activate = console_activate;
st->deactivate = console_deactivate;
/* regions: main window */
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype console region"));

View File

@ -487,7 +487,7 @@ static void outliner_foreach_id(SpaceLink *space_link, LibraryForeachIDData *dat
}
}
static void outliner_deactivate(ScrArea *area)
static void outliner_deactivate(bContext * /*C*/, ScrArea *area)
{
/* Remove hover highlights */
SpaceOutliner *space_outliner = static_cast<SpaceOutliner *>(area->spacedata.first);

View File

@ -399,6 +399,25 @@ static void text_space_blend_write(BlendWriter *writer, SpaceLink *sl)
BLO_write_struct(writer, SpaceText, sl);
}
static void text_activate(bContext *C, struct ScrArea *area)
{
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
st->runtime->hide_cursor = false;
/* Redraw to show active text caret. */
ED_region_tag_redraw(BKE_area_find_region_type(area, RGN_TYPE_WINDOW));
}
static void text_deactivate(bContext *C, struct ScrArea *area)
{
SpaceText *st = static_cast<SpaceText *>(area->spacedata.first);
st->runtime->hide_cursor = true;
/* Redraw to remove active text caret. */
ED_region_tag_redraw(BKE_area_find_region_type(area, RGN_TYPE_WINDOW));
}
/********************* registration ********************/
void ED_spacetype_text()
@ -423,6 +442,8 @@ void ED_spacetype_text()
st->blend_read_data = text_space_blend_read_data;
st->blend_read_after_liblink = nullptr;
st->blend_write = text_space_blend_write;
st->activate = text_activate;
st->deactivate = text_deactivate;
/* regions: main window */
art = static_cast<ARegionType *>(MEM_callocN(sizeof(ARegionType), "spacetype text region"));

View File

@ -1305,7 +1305,18 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
y += st->runtime->scroll_ofs_px[1];
}
immUniformThemeColor(TH_HILITE);
GPU_blend(GPU_BLEND_ALPHA);
float color[4];
UI_GetThemeColor4fv(TH_HILITE, color);
if (st->runtime->hide_cursor) {
float gray = rgb_to_grayscale(color);
color[0] = gray;
color[1] = gray;
color[2] = gray;
color[3] = 0.5;
}
immUniformColor4fv(color);
if (st->overwrite) {
char ch = text->sell->line[text->selc];
@ -1322,6 +1333,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
else {
immRecti(pos, x - U.pixelsize, y, x + U.pixelsize, y - lheight);
}
GPU_blend(GPU_BLEND_NONE);
}
immUnbindProgram();

View File

@ -216,6 +216,8 @@ struct SpaceText_Runtime {
*/
int scroll_ofs_px[2]{0, 0};
bool hide_cursor;
/** Cache for faster drawing. */
void *drawcache = nullptr;
};

View File

@ -1699,7 +1699,9 @@ typedef struct SpaceConsole {
/* space vars */
int lheight;
char _pad[4];
char hide_cursor;
char _pad[3];
/** ConsoleLine; output. */
ListBase scrollback;