///////////////////////////////////////////////////// // Set Font Properties ///////////////////////////////////////////////////// #include "CKAll.h" #include "CKFontManager.h" CKObjectDeclaration *FillBehaviorSetFontPropertiesDecl(); CKERROR CreateSetFontPropertiesProto(CKBehaviorPrototype **); int SetFontProperties(const CKBehaviorContext& behcontext); CKERROR SetFontPropertiesCallback(const CKBehaviorContext& behcontext); CKObjectDeclaration *FillBehaviorSetFontPropertiesDecl() { CKObjectDeclaration *od = CreateCKObjectDeclaration("Set Font Properties"); od->SetDescription("Sets the visual appearance of a font."); /* rem: In: triggers the process.
Out: is activated when the process is completed.

Font: font created with the building blocks "Create Font" or "Create System Font".
Space: space between characters (can be negative).
Scale: multiplicative scale of the characters.
Italic Offset: italic offset (positive is for right italic, negative is for left).
Color: color of the font (top color of the font if gradient is enabled).
End Color: bottom color of the font if gradient is enabled.
Shadow Color: color of the shadow, if the shadow is enabled.
Shadow Angle: angle of the projection of the shadow.
Shadow Distance: distance of the shadow from the main font.
Shadow Size: scale of the shadow.
Lit Material: material to use for the font if the lighting is enabled for the font.

Font Properties: properties of the font:

*/ od->SetType(CKDLL_BEHAVIORPROTOTYPE); od->SetVersion(0x00010000); od->SetCreationFunction(CreateSetFontPropertiesProto); od->SetCategory("Interface/Fonts"); od->SetGuid(CKGUID(0xDACFBD61,0x7A6E65E7)); od->SetAuthorGuid(VIRTOOLS_GUID); od->SetAuthorName("Virtools"); od->SetCompatibleClassId(CKCID_BEOBJECT); return od; } CKERROR CreateSetFontPropertiesProto(CKBehaviorPrototype **pproto) { CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Set Font Properties"); if(!proto) return CKERR_OUTOFMEMORY; //--- Inputs declaration proto->DeclareInput("In"); //--- Outputs declaration proto->DeclareOutput("Out"); //----- Input Parameters Declaration proto->DeclareInParameter("Font",CKPGUID_FONT); proto->DeclareInParameter("Space",CKPGUID_2DVECTOR,"0,0"); proto->DeclareInParameter("Scale",CKPGUID_2DVECTOR,"1,1"); proto->DeclareInParameter("Italic Offset",CKPGUID_FLOAT,"0"); proto->DeclareInParameter("Color",CKPGUID_COLOR,"255,255,255,255"); proto->DeclareInParameter("End Color",CKPGUID_COLOR,"0,0,0,255"); proto->DeclareInParameter("Shadow Color",CKPGUID_COLOR,"0,0,0,128"); proto->DeclareInParameter("Shadow Angle",CKPGUID_ANGLE,"0:120"); proto->DeclareInParameter("Shadow Distance",CKPGUID_FLOAT,"4"); proto->DeclareInParameter("Shadow Size",CKPGUID_2DVECTOR,"1,1"); proto->DeclareInParameter("Lit Material",CKPGUID_MATERIAL); proto->DeclareSetting("Font Properties",CKPGUID_FONTPROPERTIES); proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); proto->SetFunction(SetFontProperties); proto->SetBehaviorCallbackFct( SetFontPropertiesCallback ); *pproto = proto; return CK_OK; } int SetFontProperties(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; beh->ActivateInput(0,FALSE); beh->ActivateOutput(0); CKFontManager* fm = (CKFontManager*)ctx->GetManagerByGuid(FONT_MANAGER_GUID); int fontindex = 0; beh->GetInputParameterValue(0,&fontindex); CKTextureFont* font = fm->GetFont(fontindex); if(!font) return CKBR_OK; // We get the leading beh->GetInputParameterValue(1,&font->m_Leading); // We get the scale beh->GetInputParameterValue(2,&font->m_Scale); // We get the italic offset beh->GetInputParameterValue(3,&font->m_ItalicOffset); /// // colors VxColor col; // We get the start color if(!beh->GetInputParameterValue(4,&col)) { font->m_StartColor = RGBAFTOCOLOR(&col); } // We get the end color if(!beh->GetInputParameterValue(5,&col)) { font->m_EndColor = RGBAFTOCOLOR(&col); } // We get the shadow color if(!beh->GetInputParameterValue(6,&col)) { font->m_ShadowColor = RGBAFTOCOLOR(&col); } float shadowangle= 1.0f; if(!beh->GetInputParameterValue(7,&shadowangle)) { float shadowdistance= 4.0f; beh->GetInputParameterValue(8,&shadowdistance); font->m_ShadowOffset.x = -shadowdistance*cosf(shadowangle); font->m_ShadowOffset.y = shadowdistance*sinf(shadowangle); } // We get the shadow scale beh->GetInputParameterValue(9,&font->m_ShadowScale); // We get the lighted material beh->GetInputParameterValue(10,&font->m_Material); // Text Properties beh->GetLocalParameterValue(0,&font->m_Properties); return CKBR_OK; } CKERROR SetFontPropertiesCallback(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; switch(behcontext.CallbackMessage) { case CKM_BEHAVIORCREATE: case CKM_BEHAVIORSETTINGSEDITED: { DWORD flags = 0; beh->GetLocalParameterValue(0,&flags); // Gradient beh->EnableInputParameter(5,flags & FONT_GRADIENT); // Shadow beh->EnableInputParameter(6,flags & FONT_SHADOW); beh->EnableInputParameter(7,flags & FONT_SHADOW); beh->EnableInputParameter(8,flags & FONT_SHADOW); beh->EnableInputParameter(9,flags & FONT_SHADOW); // Lighted Material beh->EnableInputParameter(10,flags & FONT_LIGHTING); if (flags & FONT_LIGHTING) { beh->EnableInputParameter(4,!(flags & FONT_LIGHTING)); beh->EnableInputParameter(5,!(flags & FONT_LIGHTING)); } else { beh->EnableInputParameter(4,TRUE); } } break; } return CKBR_OK; }