static ButtonVector* ButtonVectorFromDef(TxtNode* structDef) { CrashIf(!structDef->IsStructWithName("ButtonVector")); ButtonVectorDef *def = DeserializeButtonVectorDef(structDef); ButtonVector *b = new ButtonVector(); b->SetName(def->name); b->SetNamedEventClick(def->clicked); if (def->path ){ GraphicsPath *gp = svg::GraphicsPathFromPathData(def->path); b->SetGraphicsPath(gp); } if (def->styleDefault) { Style *style = StyleByName(def->styleDefault); CrashIf(!style); b->SetDefaultStyle(style); } if (def->styleMouseOver) { Style *style = StyleByName(def->styleMouseOver); CrashIf(!style); b->SetMouseOverStyle(style); } FreeButtonVectorDef(def); return b; }
static Button* ButtonFromDef(TxtNode* structDef) { CrashIf(!structDef->IsStructWithName("Button")); ButtonDef* def = DeserializeButtonDef(structDef); Style* style = StyleByName(def->style); Button* b = new Button(def->text, style, style); b->SetName(def->name); FreeButtonDef(def); return b; }
void SetMainWndBgCol(EbookControls *ctrls) { COLORREF bgColor = gGlobalPrefs->ebookUI.backgroundColor; if (gGlobalPrefs->useSysColors) bgColor = GetSysColor(COLOR_WINDOW); Style *styleMainWnd = StyleByName("styleMainWnd"); CrashIf(!styleMainWnd); styleMainWnd->Set(Prop::AllocColorSolid(PropBgColor, GetRValueSafe(bgColor), GetGValueSafe(bgColor), GetBValueSafe(bgColor))); ctrls->mainWnd->SetStyle(styleMainWnd); Style *styleStatus = StyleByName("styleStatus"); styleStatus->Set(Prop::AllocColorSolid(PropBgColor, GetRValueSafe(bgColor), GetGValueSafe(bgColor), GetBValueSafe(bgColor))); ctrls->status->SetStyle(styleStatus); // TODO: should also allow to change text color // TODO: also match the colors of progress bar to be based on background color // note: callers are expected to update the background of tree control and // other colors that are supposed to match background color }
static ScrollBar* ScrollBarFromDef(TxtNode* structDef) { CrashIf(!structDef->IsStructWithName("ScrollBar")); ScrollBarDef* def = DeserializeScrollBarDef(structDef); ScrollBar* sb = new ScrollBar(); Style* style = StyleByName(def->style); sb->SetStyle(style); sb->SetName(def->name); // TODO: support def->cursor FreeScrollBarDef(def); return sb; }
Control *CreatePageControl(TxtNode *structDef) { CrashIf(!structDef->IsStructWithName("EbookPage")); EbookPageDef *def = DeserializeEbookPageDef(structDef); PageControl *c = new PageControl(); Style *style = StyleByName(def->style); c->SetStyle(style); if (def->name) c->SetName(def->name); FreeEbookPageDef(def); return c; }
// styles are cached globally, so we only add a style if it doesn't // exist already static void CacheStyleFromStruct(TxtNode* def) { CrashIf(!def->IsStructWithName("style")); TxtNode* nameNode = TxtChildNodeWithKey(def, "name"); CrashIf(!nameNode); // must have name or else no way to refer to it AutoFree tmp(nameNode->ValDup()); if (StyleByName(tmp)) return; Style* style = new Style(); for (TxtNode* node = def->firstChild; node != nullptr; node = node->sibling) { CrashIf(!node->IsText()); AddStyleProp(style, node); } CacheStyle(style, nullptr); }
// styles are cached globally, so we only add a style if it doesn't // exist already static void CacheStyleFromStruct(TxtNode* def) { CrashIf(!def->IsStructWithName("style")); TxtNode *nameNode = TxtChildNodeWithKey(def, "name"); CrashIf(!nameNode); // must have name or else no way to refer to it ScopedMem<char> tmp(nameNode->ValDup()); if (StyleByName(tmp)) return; Style *style = new Style(); size_t n = def->children->Count(); for (size_t i = 0; i < n; i++) { TxtNode *node = def->children->At(i); CrashIf(!node->IsText()); AddStyleProp(style, node); } CacheStyle(style, NULL); }
static void AddStyleProp(Style* style, TxtNode* prop) { AutoFree tmp(prop->ValDup()); if (prop->IsTextWithKey("name")) { style->SetName(tmp); return; } if (prop->IsTextWithKey("bg_col")) { style->Set(Prop::AllocColorSolid(PropBgColor, tmp)); return; } if (prop->IsTextWithKey("col")) { style->Set(Prop::AllocColorSolid(PropColor, tmp)); return; } if (prop->IsTextWithKey("parent")) { Style* parentStyle = StyleByName(tmp); CrashIf(!parentStyle); style->SetInheritsFrom(parentStyle); return; } if (prop->IsTextWithKey("border_width")) { style->SetBorderWidth(ParseFloat(tmp)); return; } if (prop->IsTextWithKey("padding")) { ParsedPadding padding = {0}; ParsePadding(tmp, padding); style->SetPadding(padding.top, padding.right, padding.bottom, padding.left); return; } if (prop->IsTextWithKey("stroke_width")) { style->Set(Prop::AllocWidth(PropStrokeWidth, ParseFloat(tmp))); return; } if (prop->IsTextWithKey("fill")) { style->Set(Prop::AllocColorSolid(PropFill, tmp)); return; } if (prop->IsTextWithKey("vert_align")) { style->Set(Prop::AllocAlign(PropVertAlign, ParseElAlign(tmp))); return; } if (prop->IsTextWithKey("text_align")) { style->Set(Prop::AllocTextAlign(ParseAlignAttr(tmp))); return; } if (prop->IsTextWithKey("font_size")) { style->Set(Prop::AllocFontSize(ParseFloat(tmp))); return; } if (prop->IsTextWithKey("font_weight")) { style->Set(Prop::AllocFontWeight(ParseFontWeight(tmp))); return; } CrashIf(true); }