4coder/4ed_style.cpp

152 lines
4.3 KiB
C++
Raw Normal View History

2016-03-01 07:06:12 +00:00
/*
* Mr. 4th Dimention - Allen Webster
*
* 28.08.2015
*
* Styles for 4coder
*
*/
// TOP
2016-03-03 00:50:04 +00:00
// TODO(allen):
// Font changing UI should be in the library menu now, it's not tied to the fonts any more
// Get the import export stuff up and running for styles again
struct Style_Font{
i16 font_id;
i16 font_changed;
};
2016-03-01 07:06:12 +00:00
struct Style{
char name_[24];
String name;
Style_Main_Data main;
};
internal void
style_copy(Style *dst, Style *src){
*dst = *src;
dst->name.str = dst->name_;
}
internal void
style_set_name(Style *style, String name){
i32 count = ArrayCount(style->name_);
style->name = make_string(style->name_, 0, count - 1);
copy(&style->name, name);
2016-03-03 00:50:04 +00:00
terminate_with_null(&style->name);
2016-03-01 07:06:12 +00:00
}
inline u32*
style_index_by_tag(Style *s, u32 tag){
u32 *result = 0;
switch (tag){
2016-03-03 00:50:04 +00:00
case Stag_Bar: result = &s->main.file_info_style.bar_color; break;
case Stag_Bar_Active: result = &s->main.file_info_style.bar_active_color; break;
2016-03-04 23:10:00 +00:00
case Stag_Base: result = &s->main.file_info_style.base_color; break;
case Stag_Pop1: result = &s->main.file_info_style.pop1_color; break;
case Stag_Pop2: result = &s->main.file_info_style.pop2_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Back: result = &s->main.back_color; break;
case Stag_Margin: result = &s->main.margin_color; break;
case Stag_Margin_Hover: result = &s->main.margin_hover_color; break;
case Stag_Margin_Active: result = &s->main.margin_active_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Cursor: result = &s->main.cursor_color; break;
case Stag_At_Cursor: result = &s->main.at_cursor_color; break;
case Stag_Highlight: result = &s->main.highlight_color; break;
case Stag_At_Highlight: result = &s->main.at_highlight_color; break;
case Stag_Mark: result = &s->main.mark_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Default: result = &s->main.default_color; break;
case Stag_Comment: result = &s->main.comment_color; break;
case Stag_Keyword: result = &s->main.keyword_color; break;
case Stag_Str_Constant: result = &s->main.str_constant_color; break;
case Stag_Char_Constant: result = &s->main.char_constant_color; break;
case Stag_Int_Constant: result = &s->main.int_constant_color; break;
case Stag_Float_Constant: result = &s->main.float_constant_color; break;
case Stag_Bool_Constant: result = &s->main.bool_constant_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Preproc: result = &s->main.preproc_color; break;
case Stag_Include: result = &s->main.include_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Special_Character: result = &s->main.special_character_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Highlight_Junk: result = &s->main.highlight_junk_color; break;
case Stag_Highlight_White: result = &s->main.highlight_white_color; break;
2016-03-01 07:06:12 +00:00
2016-03-03 00:50:04 +00:00
case Stag_Paste: result = &s->main.paste_color; break;
case Stag_Undo: result = &s->main.undo_color; break;
2016-03-01 07:06:12 +00:00
}
return result;
}
2016-03-04 23:10:00 +00:00
struct Style_Library{
Style styles[64];
i32 count, max;
};
#if 0
struct Style_Color_Specifier{
u32 tag;
u32 color;
};
struct Style_File_Format{
i32 name_size;
char name[24];
i32 color_specifier_count;
};
2016-03-01 07:06:12 +00:00
internal b32
style_library_add(Style_Library *library, Style *style){
b32 result = 0;
i32 count = library->count;
String my_name = style->name;
Style *ostyle = library->styles;
Style *out = 0;
// TODO(allen): hashtable for name lookup?
for (i32 i = 0; i < count; ++i, ++ostyle){
if (match(my_name, ostyle->name)){
out = ostyle;
break;
}
}
if (!out && count < library->max){
out = library->styles + library->count++;
}
if (out){
style_copy(out, style);
result = 1;
}
return result;
}
internal Style_File_Format*
style_format_for_file(Font_Set *set, Style *style, Style_File_Format *out){
out->name_size = style->name.size;
memcpy(out->name, style->name.str, ArrayCount(out->name));
Style_Color_Specifier *spec = (Style_Color_Specifier*)(out + 1);
i32 count = 0;
2016-03-03 00:50:04 +00:00
for (u32 i = 0; i < Stag_Count; ++i){
2016-03-01 07:06:12 +00:00
u32 *color = style_index_by_tag(style, i);
if (color){
spec->tag = i;
spec->color = *color;
++count;
++spec;
}
}
out->color_specifier_count = count;
return (Style_File_Format*)spec;
}
2016-03-04 23:10:00 +00:00
#endif
2016-03-01 07:06:12 +00:00
// BOTTOM