4coder » Forums » punctuation coloring?
hoekkii
2 posts

Lead software engineer - serious gaming

#20635 punctuation coloring?
6 months, 3 weeks ago Edited by hoekkii on March 4, 2019, 10:58 a.m. Reason: Initial post

I tried to create a custom theme. This was really easy to do, but I couldn't find a way to change the color of the punctuation e.g. operators, braces, parenthesis... I tried to seek in the project for Style_Tag and style_tag_name, but I couldn't find anything useful. Adding them with PSAT didn't work either.

Is it possible to change the coloring of punctuation?



P.S. I really love 4coder, keep up the great work!

mrmixer
Simon Anciaux
663 posts
#20672 punctuation coloring?
6 months, 2 weeks ago

I think this is possible but you'll have to modify the default_render_caller hook (or create a copy and modify the copy) that you can find in 4coder_default_hooks.h. In the default one there is a part that changes the color of parenthesis to highlight matching ones with the same color.
hoekkii
2 posts

Lead software engineer - serious gaming

#20693 punctuation coloring?
6 months, 2 weeks ago

Thank you mrmixer for pointing me in the right direction.
I only got only one problem remaining, which is the coloring is also applied in the comments.
It should only change the color when the character has the default text color.
I already tried `marker_visual_set_priority` to `VisualPriority_Lowes`, but this did not work.

Below is the code I added to `default_render_caller` in `4coder_default_hooks.cpp`.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// NOTE(hoekkii): punctuation
{
	// Load punctuation color
	Theme_Color color { 0 };
	color.tag = Stag_Punctuation; 
	get_theme_colors(app, &color, 1); // TODO: This returns black...?
	color.color = 0xFFEEEE22; // Test/temporary fix
	
	// Text range to check
	auto temp = begin_temp_memory(scratch);
	auto text_size = on_screen_range.one_past_last - on_screen_range.first;
	auto text = push_array(scratch, char, text_size);
        buffer_read_range(app, &buffer, on_screen_range.first, on_screen_range.one_past_last, text);
	
	for (int32_t i = 0; i < text_size; ++i)
	{
		if (!is_punctuation(text[i]))
			continue;
		
		auto o = alloc_buffer_markers_on_buffer(
			app, buffer.buffer_id, 1, &render_scope);
		
		Marker range_markers {on_screen_range.first + i};
		managed_object_store_data(app, o, 0, 1, &range_markers);
		
		auto visual = create_marker_visual(app, o);
		marker_visual_set_effect(
			app, visual, 
			VisualType_CharacterBlocks, 
			SymbolicColor_Transparent, 
			color.color, 0);
		
		marker_visual_set_priority(app, visual, VisualPriority_Lowest);
	}
	
	end_temp_memory(temp);
}