📄 eb_effect.h
字号:
// May override for mouse/keyboard messages
virtual void MouseMove(HWND hWnd, int x, int y)
{ return; }
virtual void MouseButton(HWND hWnd, eButtonID Button, bool bDown, int x, int y)
{ return; }
// Override either one of these, not both
virtual void Keyboard(DWORD dwKey, UINT nFlags, bool bDown, int x, int y)
{ Keyboard(dwKey, nFlags, bDown); }
virtual void Keyboard(DWORD dwKey, UINT nFlags, bool bDown)
{ return; }
// Window resizing callback. The default implementation does two things. It
// saves the window's width, height and aspect in local member variables for
// use by derived classes. By default it also updates the graphics viewport
// for OpenGL. If you wish to call the parent class but not update the
// viewport, pass false in the fourth argument (currently unimplemented, see
// below).
//
// You are guaranteed to get at least one Resize call after Initialize() and
// before Tick().
//
virtual void Resize(HWND hWnd, int w, int h, bool fUpdateViewport)
{
if ((w <= 0) || (h <= 0))
return;
m_iWidth = (UINT) w;
m_iHeight = (UINT) h;
m_fAspect = ((float) w ) / ((float) h);
};
// Update the properties for this effect (must call this base class version if
// you inherit from it). The default properties listed below are the 'interface'
// to the effects browser. It's easy to extend the interface to the browser by
// exporting new properties from the EBEffect and having the browser recognise
// them - this doesn't break the class interface between the two.
//
virtual void UpdateProperties()
{
// Discard existing properties
EBPropertySet::UpdateProperties();
m_nAboutLines = 0;
// Add the effect name, location, and effect version (not the API version)
AddProperty(new EBProperty("EffectName", OBJECT_MEMBER(m_strEffectName),
EBTYPE_STRING_PROP, PROPFLAG_PRIVATE));
AddProperty(new EBProperty("EffectLocation", OBJECT_MEMBER(m_strEffectLocation),
EBTYPE_STRING_PROP, PROPFLAG_PRIVATE));
AddProperty(new EBProperty("EffectVersion", OBJECT_MEMBER(m_strEffectVersion),
EBTYPE_STRING_PROP, PROPFLAG_PRIVATE));
AddProperty(new EBProperty("EffectAboutIcon", OBJECT_MEMBER(m_idAboutIcon),
EBTYPE_DWORD_PROP, PROPFLAG_PRIVATE));
// Add the administrative properties
AddProperty(new EBProperty("LastError", OBJECT_MEMBER(m_strLastError),
EBTYPE_STRING_PROP, PROPFLAG_PRIVATE));
AddProperty(new EBProperty("EffectDirtyFlags", OBJECT_MEMBER(m_dwEffectDirtyFlags),
EBTYPE_DWORD_PROP, PROPFLAG_PRIVATE));
// Add the additional effect About information (optionally can be set with SetAboutInfo())
m_pAboutLabelEnum = new EBEnumProperty("EffectAboutLabel",
/* no default member */ (DWORD) -1, EBTYPE_STRING_PROP, PROPFLAG_PRIVATE);
AddProperty(m_pAboutLabelEnum);
m_pAboutValueEnum = new EBEnumProperty("EffectAboutValue",
/* no default member */ (DWORD) -1, EBTYPE_STRING_PROP, PROPFLAG_PRIVATE);
AddProperty(m_pAboutValueEnum);
m_pAboutLinkEnum = new EBEnumProperty("EffectAboutLink",
/* no default member */ (DWORD) -1, EBTYPE_STRING_PROP, PROPFLAG_PRIVATE);
AddProperty(m_pAboutLinkEnum);
// D3D vertex/pixel shader info
m_pVertexShaderEnum = new EBEnumProperty("EffectVertexShader",
OBJECT_MEMBER(m_strEffectVertexShader), EBTYPE_STRING_PROP,
PROPFLAG_PRIVATE | PROPFLAG_CALLBACK);
AddProperty(m_pVertexShaderEnum);
m_pPixelShaderEnum = new EBEnumProperty("EffectPixelShader",
OBJECT_MEMBER(m_strEffectPixelShader), EBTYPE_STRING_PROP,
PROPFLAG_PRIVATE | PROPFLAG_CALLBACK);
AddProperty(m_pPixelShaderEnum);
// OpenGL VP/TS/RC shader info
m_pVertexProgramEnum = new EBEnumProperty("EffectVertexProgram",
OBJECT_MEMBER(m_strEffectVertexProgram), EBTYPE_STRING_PROP,
PROPFLAG_PRIVATE | PROPFLAG_CALLBACK);
AddProperty(m_pVertexProgramEnum);
m_pTextureShaderEnum = new EBEnumProperty("EffectTextureShader",
OBJECT_MEMBER(m_strEffectTextureShader), EBTYPE_STRING_PROP,
PROPFLAG_PRIVATE | PROPFLAG_CALLBACK);
AddProperty(m_pTextureShaderEnum);
m_pRegCombStateEnum = new EBEnumProperty("EffectRegisterCombiner",
OBJECT_MEMBER(m_strEffectRegCombState), EBTYPE_STRING_PROP,
PROPFLAG_PRIVATE | PROPFLAG_CALLBACK);
AddProperty(m_pRegCombStateEnum);
};
//////////////////////////////////////////////////////////////////////////////
// These methods may be used to setup state in the Effect more easily
//////////////////////////////////////////////////////////////////////////////
protected:
// Sets up the effect's About dialog information
//
// The current effect About dialog contains up to three lines. Each call
// to this function defines one of these lines. NULL may be legally passed
// as the label and/or link argument. If a label and value are both
// specified the line will be displayed as:
//
// Label: Value
//
// If just a label is provided, it will be displayed centered on the line.
// Additionally, in either case, if a link is provided, the value text will
// be linked to the provided URL.
//
// For example, an effect might say:
//
// m_strEffectName = "SpookyEffect";
// m_strEffectLocation = "Foobar Inc.\\Spooky Effect";
// m_strEffectVersion = "1.1a5";
//
// SetAboutInfo(NULL, _T("My Effect Page"), _T("http://www.doe.com/john/spookyeffect.html"));
// SetAboutInfo(_T("Author"), _T("John Doe"), _T("http://www.doe.com/john"));
// SetAboutInfo(_T("Company"), _T("Foobar Inc."));
//
// And the about dialog would be displayed as:
//
// +================================+
// | |
// | SpookyEffect (version 1.1a5) |
// | (Effect API version 2.0) |
// | |
// | ******* |
// | ******* |
// | ******* |
// | |
// | My Effect Page |
// | Author: John Doe |
// | Company: Foobar Inc. |
// | |
// | O K |
// | |
// +================================+
//
// NOTE: the dialog size is not dynamic. Do not make your labels/values
// too long!
//
virtual HRESULT SetAboutInfo(LPCTSTR lpLabel, LPCTSTR lpValue, LPCTSTR lpLink=NULL)
{
// Make sure that the properties are updated first
if (!m_pAboutLabelEnum)
return E_FAIL;
if (!lpLabel) lpLabel = _T("");
if (!lpLink) lpLink = _T("");
// Make sure that we don't have too many lines...
if (m_nAboutLines++ >= 3)
return E_FAIL;
EBString strLabel = lpLabel;
EBString strValue = lpValue;
EBString strLink = lpLink;
m_pAboutLabelEnum->AddEnumerant(new EBEnumValue(m_pAboutLabelEnum, "About Label",
strLabel, EBTYPE_STRING_PROP));
m_pAboutValueEnum->AddEnumerant(new EBEnumValue(m_pAboutValueEnum, "About Value",
strValue, EBTYPE_STRING_PROP));
m_pAboutLinkEnum->AddEnumerant(new EBEnumValue(m_pAboutLinkEnum, "About Link",
strLink, EBTYPE_STRING_PROP));
return S_OK;
}
// Set the default pane that will first be selected when this effect is displayed.
// The title should match the title of one of the shaders added in a call to
// AddShaderCodeFile() or AddShaderCodeBuffer().
//
virtual HRESULT SetDefaultCodePane(EBSHADERTYPE ShaderType, const char *strTitle)
{
switch (ShaderType) {
case SHADERTYPE_VERTEXSHADER: m_strEffectVertexShader = strTitle; break;
case SHADERTYPE_PIXELSHADER: m_strEffectPixelShader = strTitle; break;
case SHADERTYPE_VERTEXPROG: m_strEffectVertexProgram = strTitle; break;
case SHADERTYPE_TEXTURESHADER: m_strEffectTextureShader = strTitle; break;
case SHADERTYPE_REGCOMBSTATE: m_strEffectRegCombState = strTitle; break;
default: return E_FAIL;
}
return S_OK;
}
// Add a new shader to the list for this effect. Provide the type of shader, a text
// title for the tab control, and a file name containing the shader code itself.
//
virtual HRESULT AddShaderCodeFile(EBSHADERTYPE ShaderType, const char *strTitle, const char *strFile)
{
EBEnumProperty *pEnumProp = NULL;
switch (ShaderType) {
case SHADERTYPE_VERTEXSHADER: pEnumProp = m_pVertexShaderEnum; break;
case SHADERTYPE_PIXELSHADER: pEnumProp = m_pPixelShaderEnum; break;
case SHADERTYPE_VERTEXPROG: pEnumProp = m_pVertexProgramEnum; break;
case SHADERTYPE_TEXTURESHADER: pEnumProp = m_pTextureShaderEnum; break;
case SHADERTYPE_REGCOMBSTATE: pEnumProp = m_pRegCombStateEnum; break;
default: return E_FAIL;
}
if (!pEnumProp)
return E_FAIL;
EBEnumValue *pValue = new EBEnumValue(pEnumProp, strTitle, GetFilePath(strFile), EBTYPE_STRING_PROP);
pEnumProp->AddEnumerant(pValue);
return S_OK;
}
// Add a new shader to the list for this effect. Provide the type of shader, a text
// title for the tab control, and the text of the shader itself.
//
virtual HRESULT AddShaderCodeBuffer(EBSHADERTYPE ShaderType, const char *strTitle, const char *strBuffer)
{
EBEnumProperty *pEnumProp = NULL;
switch (ShaderType) {
case SHADERTYPE_VERTEXSHADER: pEnumProp = m_pVertexShaderEnum; break;
case SHADERTYPE_PIXELSHADER: pEnumProp = m_pPixelShaderEnum; break;
case SHADERTYPE_VERTEXPROG: pEnumProp = m_pVertexProgramEnum; break;
case SHADERTYPE_TEXTURESHADER: pEnumProp = m_pTextureShaderEnum; break;
case SHADERTYPE_REGCOMBSTATE: pEnumProp = m_pRegCombStateEnum; break;
default: return E_FAIL;
}
if (!pEnumProp)
return E_FAIL;
// Prepend to a '-' to signify that this is not a file name, but the code itself...
std::string strCode = "-";
strCode += strBuffer;
EBEnumValue *pValue = new EBEnumValue(pEnumProp, strTitle, strCode, EBTYPE_STRING_PROP);
pEnumProp->AddEnumerant(pValue);
return S_OK;
}
// This method can be used to translate a key code into an action
//
virtual eEBKeyAction TranslateEffectKey(DWORD dwKeyCode, DWORD nFlags, bool bDown)
{
if (!bDown)
return EB_UNKNOWN;
switch (dwKeyCode) {
case 'H':
case VK_F1: return EB_HELP;
case 'W': return EB_WIREFRAME;
case VK_HOME :
case VK_NUMPAD7 :
case '7' : return EB_RESET;
case VK_ESCAPE: return EB_QUIT;
case VK_F12:
case VK_TAB: return EB_HUD;
case '`':
case '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -