123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751 |
- #include "api__vis_milk2.h"
- #include "state.h"
- #include "menu.h"
- #include "plugin.h"
- #include <stdio.h>
- #include <math.h>
- #include <assert.h>
- #include "resource.h"
- extern CPlugin g_plugin;
- CMilkMenuItem::CMilkMenuItem()
- {
- WASABI_API_LNGSTRINGW_BUF(IDS_UNTITLED_MENU_ITEM,m_szName,64);
- m_szToolTip[0] = 0;
- m_type = MENUITEMTYPE_BUNK;
- m_fMin = 0.0f;
- m_fMax = 0.0f;
- m_var_offset = NULL;
- m_pCallbackFn = NULL;
- m_pNext = NULL;
- m_original_value = NULL;
- m_nLastCursorPos = 0;
- m_bEnabled = true;
- }
- CMilkMenuItem::~CMilkMenuItem()
- {
- if (m_pNext)
- {
- delete m_pNext;
- m_pNext = NULL;
- }
- }
- CMilkMenu::CMilkMenu()
- {
-
- }
- CMilkMenu::~CMilkMenu()
- {
-
- }
- bool CMilkMenu::ItemIsEnabled(int j)
- {
- if (j < m_nChildMenus)
- return m_ppChildMenu[j]->IsEnabled();
-
- int i = m_nChildMenus;
- CMilkMenuItem *pChild = m_pFirstChildItem;
- while (pChild && i<j)
- {
- pChild = pChild->m_pNext;
- i++;
- }
- if (pChild)
- return pChild->m_bEnabled;
- return false;
- }
- void CMilkMenu::EnableItem(wchar_t* szName, bool bEnable)
- {
-
- int i = 0;
- for (i=0; i<m_nChildMenus; i++) {
- if (!wcscmp(m_ppChildMenu[i]->GetName(), szName))
- {
- m_ppChildMenu[i]->Enable(bEnable);
- if (!bEnable)
- {
- while (m_nCurSel > 0 && !ItemIsEnabled(m_nCurSel))
- m_nCurSel--;
- if (m_nCurSel==0 && !ItemIsEnabled(m_nCurSel))
- while (m_nCurSel < m_nChildMenus+m_nChildItems-1 && !ItemIsEnabled(m_nCurSel))
- m_nCurSel++;
- }
- return;
- }
- }
-
- CMilkMenuItem *pChild = m_pFirstChildItem;
- while (pChild)
- {
- if (!wcscmp(pChild->m_szName, szName))
- {
- pChild->m_bEnabled = bEnable;
- if (!bEnable)
- {
- while (m_nCurSel > 0 && !ItemIsEnabled(m_nCurSel))
- m_nCurSel--;
- if (m_nCurSel==0 && !ItemIsEnabled(m_nCurSel))
- while (m_nCurSel < m_nChildMenus+m_nChildItems-1 && !ItemIsEnabled(m_nCurSel))
- m_nCurSel++;
- }
- return;
- }
- pChild = pChild->m_pNext;
- i++;
- }
- }
- void CMilkMenu::Reset()
- {
- m_pParentMenu = NULL;
- for (int i=0; i<MAX_CHILD_MENUS; i++)
- m_ppChildMenu[i] = NULL;
- m_pFirstChildItem = NULL;
- WASABI_API_LNGSTRINGW_BUF(IDS_UNTITLED_MENU,m_szMenuName,64);
- m_nChildMenus = 0;
- m_nChildItems = 0;
- m_nCurSel = 0;
- m_bEditingCurSel = false;
- m_bEnabled = true;
- }
- void CMilkMenu::Init(wchar_t *szName)
- {
- Reset();
- if (szName && szName[0])
- wcsncpy(m_szMenuName, szName, 64);
- }
- void CMilkMenu::Finish()
- {
- if (m_pFirstChildItem)
- {
- delete m_pFirstChildItem;
- m_pFirstChildItem = NULL;
- }
- }
- void CMilkMenu::AddChildMenu(CMilkMenu *pMenu)
- {
- if (m_nChildMenus < MAX_CHILD_MENUS)
- {
- m_ppChildMenu[m_nChildMenus++] = pMenu;
- pMenu->SetParentPointer(this);
- }
- }
- void CMilkMenu::AddItem(wchar_t *szName, void *var, MENUITEMTYPE type, wchar_t *szToolTip,
- float min, float max, MilkMenuCallbackFnPtr pCallback,
- unsigned int wParam, unsigned int lParam)
- {
- CMilkMenuItem *pLastItem = NULL;
-
- if (!m_pFirstChildItem)
- {
-
- m_pFirstChildItem = new CMilkMenuItem;
- pLastItem = m_pFirstChildItem;
- }
- else
- {
- pLastItem = m_pFirstChildItem;
- while (pLastItem->m_pNext)
- pLastItem = pLastItem->m_pNext;
-
-
- pLastItem->m_pNext = new CMilkMenuItem;
- pLastItem = pLastItem->m_pNext;
- }
-
- wcsncpy(pLastItem->m_szName, szName, 64);
- wcsncpy(pLastItem->m_szToolTip, szToolTip, 1024);
- pLastItem->m_var_offset = (size_t)var - (size_t)(g_plugin.m_pState);
- pLastItem->m_type = type;
- pLastItem->m_fMin = min;
- pLastItem->m_fMax = max;
- pLastItem->m_wParam = wParam;
- pLastItem->m_lParam = lParam;
- if ((type==MENUITEMTYPE_LOGBLENDABLE || type==MENUITEMTYPE_LOGFLOAT) && min==max)
- {
-
- pLastItem->m_fMin = 0.01f;
- pLastItem->m_fMax = 100.0f;
- }
- pLastItem->m_pCallbackFn = pCallback;
- m_nChildItems++;
- }
- void MyMenuTextOut(eFontIndex font_index, wchar_t* str, DWORD color, RECT* pRect, int bCalcRect, RECT* pCalcRect)
- {
- if (bCalcRect)
- {
- RECT t = *pRect;
- pRect->top += g_plugin.m_text.DrawTextW(g_plugin.GetFont(font_index), str, -1, &t, DT_SINGLELINE | DT_END_ELLIPSIS | DT_CALCRECT, 0xFFFFFFFF, false);
- pCalcRect->bottom += t.bottom - t.top;
-
-
- pCalcRect->right = max(pCalcRect->right, pCalcRect->left + t.right - t.left);
- }
- else
- {
- pRect->top += g_plugin.m_text.DrawTextW(g_plugin.GetFont(font_index), str, -1, pRect, DT_SINGLELINE | DT_END_ELLIPSIS, color, false);
- }
- }
- void CMilkMenu::DrawMenu(RECT rect, int xR, int yB, int bCalcRect, RECT* pCalcRect)
- {
-
-
-
-
- if (bCalcRect!=0 && pCalcRect==NULL)
- return;
- if (bCalcRect)
- {
- pCalcRect->left = rect.left;
- pCalcRect->right = rect.left;
- pCalcRect->top = rect.top;
- pCalcRect->bottom = rect.top;
- }
-
- if (!m_bEditingCurSel)
- {
- int nLines = (rect.bottom - rect.top - PLAYLIST_INNER_MARGIN*2) / g_plugin.GetFontHeight(SIMPLE_FONT) - 1;
- if (nLines<1) return;
- int nStart = (m_nCurSel/nLines)*nLines;
- int nLinesDrawn = 0;
- int i = 0;
- for (i=0; i < m_nChildMenus; i++)
- {
- if (i >= nStart && i < nStart+nLines)
- {
-
- if (m_ppChildMenu[i]->IsEnabled()) {
- MyMenuTextOut(SIMPLE_FONT, m_ppChildMenu[i]->m_szMenuName, (i == m_nCurSel) ? MENU_HILITE_COLOR : MENU_COLOR, &rect, bCalcRect, pCalcRect);
- nLinesDrawn++;
- }
- if (g_plugin.m_bShowMenuToolTips && i == m_nCurSel && !bCalcRect)
- {
-
- g_plugin.DrawTooltip(WASABI_API_LNGSTRINGW(IDS_SZ_MENU_NAV_TOOLTIP), xR, yB);
- }
- }
- }
- CMilkMenuItem *pItem = m_pFirstChildItem;
- while (pItem && nLinesDrawn < nStart+nLines)
- {
- if (!pItem->m_bEnabled)
- {
- pItem = pItem->m_pNext;
- i++;
- continue;
- }
- size_t addr = pItem->m_var_offset + (size_t)g_plugin.m_pState;
- if (i >= nStart)
- {
- wchar_t szItemText[256];
- switch(pItem->m_type)
- {
- case MENUITEMTYPE_STRING:
- lstrcpyW(szItemText, pItem->m_szName);
- break;
- case MENUITEMTYPE_BOOL:
- swprintf(szItemText, L"%s [%s]", pItem->m_szName,
- WASABI_API_LNGSTRINGW(*((bool *)(addr)) ? IDS_ON : IDS_OFF));
- break;
- default:
- lstrcpyW(szItemText, pItem->m_szName);
- break;
- }
- if (i == m_nCurSel)
- {
- MyMenuTextOut(SIMPLE_FONT, szItemText, MENU_HILITE_COLOR, &rect, bCalcRect, pCalcRect);
- if (g_plugin.m_bShowMenuToolTips && !bCalcRect)
- {
-
- g_plugin.DrawTooltip(pItem->m_szToolTip, xR, yB);
- }
- }
- else
- {
- MyMenuTextOut(SIMPLE_FONT, szItemText, MENU_COLOR, &rect, bCalcRect, pCalcRect);
- }
- nLinesDrawn++;
- }
- pItem = pItem->m_pNext;
- i++;
- }
- }
- else
- {
-
-
- CMilkMenuItem *pItem = m_pFirstChildItem;
- for (int i=m_nChildMenus; i < m_nCurSel; i++)
- pItem = pItem->m_pNext;
- size_t addr = pItem->m_var_offset + (size_t)g_plugin.m_pState;
- wchar_t buf[256];
- MyMenuTextOut(SIMPLE_FONT, WASABI_API_LNGSTRINGW(IDS_USE_UP_DOWN_ARROW_KEYS), MENU_COLOR, &rect, bCalcRect, pCalcRect);
- swprintf(buf, WASABI_API_LNGSTRINGW(IDS_CURRENT_VALUE_OF_X), pItem->m_szName);
- MyMenuTextOut(SIMPLE_FONT, buf, MENU_COLOR, &rect, bCalcRect, pCalcRect);
- switch(pItem->m_type)
- {
- case MENUITEMTYPE_INT:
- swprintf(buf, L" %d ", *((int*)(addr)) );
- break;
- case MENUITEMTYPE_FLOAT:
- case MENUITEMTYPE_LOGFLOAT:
- swprintf(buf, L" %5.3f ", *((float*)(addr)) );
- break;
- case MENUITEMTYPE_BLENDABLE:
- case MENUITEMTYPE_LOGBLENDABLE:
- swprintf(buf, L" %5.3f ", ((CBlendableFloat*)addr)->eval(-1) );
- break;
- default:
- lstrcpyW(buf, L" ? ");
- break;
- }
- MyMenuTextOut(SIMPLE_FONT, buf, MENU_HILITE_COLOR, &rect, bCalcRect, pCalcRect);
-
- if (g_plugin.m_bShowMenuToolTips && !bCalcRect)
- {
- g_plugin.DrawTooltip(pItem->m_szToolTip, xR, yB);
- }
- }
- }
- void CMilkMenu::OnWaitStringAccept(wchar_t *szNewString)
- {
- m_bEditingCurSel = false;
-
- CMilkMenuItem *pItem = m_pFirstChildItem;
- for (int i=m_nChildMenus; i < m_nCurSel; i++)
- pItem = pItem->m_pNext;
- size_t addr = pItem->m_var_offset + (size_t)g_plugin.m_pState;
-
- assert(pItem->m_type == MENUITEMTYPE_STRING);
-
- lstrcpyW((wchar_t *)(addr), szNewString);
-
- if (pItem->m_pCallbackFn)
- {
- pItem->m_pCallbackFn(0, 0);
- }
-
- pItem->m_nLastCursorPos = g_plugin.m_waitstring.nCursorPos;
- }
- LRESULT CMilkMenu::HandleKeydown(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
-
-
-
-
- int nRepeat = LOWORD(lParam);
- int rep;
- if (!m_bEditingCurSel)
- {
- switch(wParam)
- {
- case VK_UP:
- for (rep=0; rep<nRepeat; rep++)
- {
- if (m_nCurSel==0)
- break;
- do {
- m_nCurSel--;
- } while (m_nCurSel > 0 && !ItemIsEnabled(m_nCurSel));
- }
- if (m_nCurSel < 0) m_nCurSel = 0;
- while (m_nCurSel < m_nChildMenus + m_nChildItems - 1 && !ItemIsEnabled(m_nCurSel))
- m_nCurSel++;
- return 0;
- case VK_DOWN:
- for (rep=0; rep<nRepeat; rep++)
- {
- if (m_nCurSel == m_nChildMenus + m_nChildItems - 1)
- break;
- do {
- m_nCurSel++;
- } while (m_nCurSel < m_nChildMenus + m_nChildItems - 1 && !ItemIsEnabled(m_nCurSel));
- }
- if (m_nCurSel >= m_nChildMenus + m_nChildItems) m_nCurSel = m_nChildMenus + m_nChildItems - 1;
- while (m_nCurSel > 0 && !ItemIsEnabled(m_nCurSel))
- m_nCurSel--;
- return 0;
- case VK_HOME:
- m_nCurSel = 0;
- return 0;
- case VK_END:
- m_nCurSel = m_nChildMenus + m_nChildItems - 1;
- return 0;
- case VK_ESCAPE:
- g_plugin.m_UI_mode = UI_REGULAR;
- return 0;
- case VK_BACK:
- case VK_LEFT:
- if (m_pParentMenu)
- g_plugin.m_pCurMenu = m_pParentMenu;
- else
- g_plugin.m_UI_mode = UI_REGULAR;
- return 0;
- case VK_RETURN:
- case VK_RIGHT:
- case VK_SPACE:
- if (m_nCurSel < m_nChildMenus)
- {
-
- g_plugin.m_pCurMenu = m_ppChildMenu[m_nCurSel];
- }
- else
- {
-
- CMilkMenuItem *pItem = GetCurItem();
- size_t addr = pItem->m_var_offset + (size_t)g_plugin.m_pState;
- float fTemp;
-
- switch(pItem->m_type)
- {
- case MENUITEMTYPE_UIMODE:
- g_plugin.m_UI_mode = (ui_mode)pItem->m_wParam;
- if (g_plugin.m_UI_mode==UI_IMPORT_WAVE ||
- g_plugin.m_UI_mode==UI_EXPORT_WAVE ||
- g_plugin.m_UI_mode==UI_IMPORT_SHAPE ||
- g_plugin.m_UI_mode==UI_EXPORT_SHAPE)
- {
- g_plugin.m_bPresetLockedByCode = true;
-
- g_plugin.m_waitstring.bActive = true;
- g_plugin.m_waitstring.bFilterBadChars = false;
- g_plugin.m_waitstring.bDisplayAsCode = false;
- g_plugin.m_waitstring.nSelAnchorPos = -1;
- g_plugin.m_waitstring.nMaxLen = min(sizeof(g_plugin.m_waitstring.szText)-1, MAX_PATH - wcslen(g_plugin.GetPresetDir()) - 6);
- swprintf(g_plugin.m_waitstring.szText, L"%sfile.dat", g_plugin.m_szPresetDir);
- if (g_plugin.m_UI_mode==UI_IMPORT_WAVE || g_plugin.m_UI_mode==UI_IMPORT_SHAPE)
- WASABI_API_LNGSTRINGW_BUF(IDS_LOAD_FROM_FILE,g_plugin.m_waitstring.szPrompt,512);
- else
- WASABI_API_LNGSTRINGW_BUF(IDS_SAVE_TO_FILE,g_plugin.m_waitstring.szPrompt,512);
- g_plugin.m_waitstring.szToolTip[0] = 0;
- g_plugin.m_waitstring.nCursorPos = wcslen(g_plugin.m_waitstring.szText);
- }
- break;
- case MENUITEMTYPE_BOOL:
- *((bool *)addr) = !(*((bool *)addr));
- break;
- case MENUITEMTYPE_INT:
- m_bEditingCurSel = true;
- pItem->m_original_value = (LPARAM)(*((int*)(addr)));
- break;
- case MENUITEMTYPE_FLOAT:
- case MENUITEMTYPE_LOGFLOAT:
- m_bEditingCurSel = true;
- pItem->m_original_value = (LPARAM)(*((float*)(addr))*10000L);
- break;
- case MENUITEMTYPE_BLENDABLE:
- case MENUITEMTYPE_LOGBLENDABLE:
- m_bEditingCurSel = true;
- {
-
-
- fTemp = ((CBlendableFloat*)addr)->eval(-1);
- }
- pItem->m_original_value = (LPARAM)(fTemp*10000L);
- break;
- case MENUITEMTYPE_STRING:
-
-
- g_plugin.m_UI_mode = UI_EDIT_MENU_STRING;
- g_plugin.m_waitstring.bActive = true;
- g_plugin.m_waitstring.bFilterBadChars = false;
- g_plugin.m_waitstring.bDisplayAsCode = true;
- g_plugin.m_waitstring.nSelAnchorPos = -1;
- g_plugin.m_waitstring.nMaxLen = pItem->m_wParam ? pItem->m_wParam : 8190;
- g_plugin.m_waitstring.nMaxLen = min(g_plugin.m_waitstring.nMaxLen, sizeof(g_plugin.m_waitstring.szText)-16);
-
- lstrcpyA((char*)g_plugin.m_waitstring.szText, (char*)addr);
- swprintf(g_plugin.m_waitstring.szPrompt, WASABI_API_LNGSTRINGW(IDS_ENTER_THE_NEW_STRING), pItem->m_szName);
- lstrcpyW(g_plugin.m_waitstring.szToolTip, pItem->m_szToolTip);
- g_plugin.m_waitstring.nCursorPos = strlen((char*)g_plugin.m_waitstring.szText);
- if (pItem->m_nLastCursorPos < g_plugin.m_waitstring.nCursorPos)
- g_plugin.m_waitstring.nCursorPos = pItem->m_nLastCursorPos;
- break;
-
- }
- }
- return 0;
- default:
-
- return TRUE;
- break;
- }
- }
- else
- {
- float fMult = 1.0f;
- bool bDec;
-
- CMilkMenuItem *pItem = m_pFirstChildItem;
- for (int i=m_nChildMenus; i < m_nCurSel; i++)
- pItem = pItem->m_pNext;
- size_t addr = pItem->m_var_offset + (size_t)g_plugin.m_pState;
- switch(wParam)
- {
- case VK_ESCAPE:
-
- switch(pItem->m_type)
- {
- case MENUITEMTYPE_INT:
- m_bEditingCurSel = false;
- *((int *)addr) = (int)pItem->m_original_value;
- break;
- case MENUITEMTYPE_FLOAT:
- m_bEditingCurSel = false;
- *((float *)addr) = ((float)pItem->m_original_value)*0.0001f;
- break;
- case MENUITEMTYPE_LOGFLOAT:
- m_bEditingCurSel = false;
- *((float *)addr) = ((float)pItem->m_original_value)*0.0001f;
- break;
- case MENUITEMTYPE_BLENDABLE:
- m_bEditingCurSel = false;
- *((CBlendableFloat *)(addr)) = ((float)(pItem->m_original_value))*0.0001f;
- break;
- case MENUITEMTYPE_LOGBLENDABLE:
- m_bEditingCurSel = false;
- *((CBlendableFloat *)(addr)) = ((float)(pItem->m_original_value))*0.0001f;
- break;
-
-
- }
- return 0;
- case VK_RETURN:
-
-
- m_bEditingCurSel = false;
- return 0;
- case VK_NEXT:
- case VK_PRIOR:
- fMult *= 10.0f;
-
- case VK_UP:
- case VK_DOWN:
- {
- USHORT mask = 1 << (sizeof(USHORT)*8 - 1);
- bool bShiftHeldDown = (GetKeyState(VK_SHIFT) & mask) != 0;
-
- if (bShiftHeldDown && (wParam==VK_UP || wParam==VK_DOWN))
- fMult *= 0.1f;
- }
-
- bDec = (wParam == VK_DOWN || wParam == VK_NEXT);
- switch(pItem->m_type)
- {
- case MENUITEMTYPE_INT:
- {
- int *pInt = ((int *)addr);
- if (fMult<1) fMult=1;
- (*pInt) += (int)((bDec) ? -fMult : fMult);
- if (*pInt < pItem->m_fMin) *pInt = (int)pItem->m_fMin;
- if (*pInt > pItem->m_fMax) *pInt = (int)pItem->m_fMax;
- }
- break;
- case MENUITEMTYPE_FLOAT:
- {
- float *pFloat = ((float *)addr);
- float fInc = (pItem->m_fMax - pItem->m_fMin)*0.01f*fMult;
- (*pFloat) += (bDec) ? -fInc : fInc;
- if (*pFloat < pItem->m_fMin) *pFloat = pItem->m_fMin;
- if (*pFloat > pItem->m_fMax) *pFloat = pItem->m_fMax;
- }
- break;
- case MENUITEMTYPE_LOGFLOAT:
- {
- float *pFloat = ((float *)addr);
- (*pFloat) *= (bDec) ? powf(1.0f/1.01f, fMult) : powf(1.01f, fMult);
- if (*pFloat < pItem->m_fMin) *pFloat = pItem->m_fMin;
- if (*pFloat > pItem->m_fMax) *pFloat = pItem->m_fMax;
- }
- break;
- case MENUITEMTYPE_BLENDABLE:
- {
- CBlendableFloat *pBlend = ((CBlendableFloat *)addr);
- float fInc = (pItem->m_fMax - pItem->m_fMin)*0.01f*fMult;
- (*pBlend) += (bDec) ? -fInc : fInc;
- if (pBlend->eval(-1) < pItem->m_fMin) *pBlend = pItem->m_fMin;
- if (pBlend->eval(-1) > pItem->m_fMax) *pBlend = pItem->m_fMax;
- }
- break;
- case MENUITEMTYPE_LOGBLENDABLE:
- {
- CBlendableFloat *pBlend = ((CBlendableFloat *)addr);
- (*pBlend) *= (bDec) ? powf(1.0f/1.01f, fMult) : powf(1.01f, fMult);
- if (pBlend->eval(-1) < pItem->m_fMin) *pBlend = pItem->m_fMin;
- if (pBlend->eval(-1) > pItem->m_fMax) *pBlend = pItem->m_fMax;
- }
- break;
-
- }
- return 0;
- default:
-
- return TRUE;
- break;
- }
- }
- return TRUE;
- }
|