void ocio_colorspace_combo_t::set_default() { OCIO::ConstConfigRcPtr config = app().ocio_manager().config(); std::string default_cs_name = config->getColorSpace( OCIO::ROLE_SCENE_LINEAR)->getName(); int index = 0; int num_color_spaces = config->getNumColorSpaces(); for(int i = 0; i < num_color_spaces; i++) { if( config->getColorSpaceNameByIndex( i) == default_cs_name) index = i; } setCurrentIndex( index); current_colorspace_ = default_cs_name; }
bool ColorSpacePopUpMenu(OCIO::ConstConfigRcPtr config, std::string &colorSpace, bool selectRoles, const void *hwnd) { HMENU menu = CreatePopupMenu(); for(int i=0; i < config->getNumColorSpaces(); ++i) { const char *colorSpaceName = config->getColorSpaceNameByIndex(i); OCIO::ConstColorSpaceRcPtr colorSpacePtr = config->getColorSpace(colorSpaceName); const char *family = colorSpacePtr->getFamily(); std::string colorSpacePath; if(family == NULL) { colorSpacePath = colorSpaceName; } else { colorSpacePath = std::string(family) + "/" + colorSpaceName; } std::vector<std::string> pathComponents; tokenize(pathComponents, colorSpacePath, "/"); HMENU currentMenu = menu; for(int j=0; j < pathComponents.size(); j++) { const std::string &componentName = pathComponents[j]; if(j == (pathComponents.size() - 1)) { UINT flags = MF_STRING; if(componentName == colorSpace) flags |= MF_CHECKED; const BOOL inserted = AppendMenu(currentMenu, flags, i + 1, componentName.c_str()); assert(inserted); } else { int componentMenuPos = -1; for(int k=0; k < GetMenuItemCount(currentMenu) && componentMenuPos < 0; k++) { CHAR buf[256]; const int strLen = GetMenuString(currentMenu, k, buf, 255, MF_BYPOSITION); assert(strLen > 0); if(componentName == buf) componentMenuPos = k; } if(componentMenuPos < 0) { HMENU subMenu = CreateMenu(); const BOOL inserted = AppendMenu(currentMenu, MF_STRING | MF_POPUP, (UINT_PTR)subMenu, componentName.c_str()); assert(inserted); componentMenuPos = (GetMenuItemCount(currentMenu) - 1); } currentMenu = GetSubMenu(currentMenu, componentMenuPos); } } } if(config->getNumRoles() > 0) { HMENU rolesMenu = CreatePopupMenu(); const BOOL rolesInserted = InsertMenu(menu, 0, MF_STRING | MF_BYPOSITION | MF_POPUP, (UINT_PTR)rolesMenu, "Roles"); assert(rolesInserted); for(int i=0; i < config->getNumRoles(); i++) { const std::string roleName = config->getRoleName(i); OCIO::ConstColorSpaceRcPtr colorSpacePtr = config->getColorSpace(roleName.c_str()); const std::string colorSpaceName = colorSpacePtr->getName(); int colorSpaceIndex = -1; for(int k=0; k < config->getNumColorSpaces() && colorSpaceIndex < 0; k++) { const std::string colorSpaceName2 = config->getColorSpaceNameByIndex(k); if(colorSpaceName2 == colorSpaceName) colorSpaceIndex = k; } HMENU roleSubmenu = CreatePopupMenu(); UINT roleFlags = MF_STRING | MF_POPUP; if(selectRoles && roleName == colorSpace) roleFlags |= MF_CHECKED; const BOOL roleInserted = AppendMenu(rolesMenu, roleFlags, (UINT_PTR)roleSubmenu, roleName.c_str()); assert(roleInserted); UINT colorSpaceFlags = MF_STRING; if(colorSpaceName == colorSpace) colorSpaceFlags |= MF_CHECKED; const BOOL colorSpaceInsterted = AppendMenu(roleSubmenu, colorSpaceFlags, colorSpaceIndex + 1, colorSpaceName.c_str()); assert(colorSpaceInsterted); } const BOOL dividerInserted = InsertMenu(menu, 1, MF_STRING | MF_BYPOSITION | MF_SEPARATOR, 0, "Sep"); assert(dividerInserted); } POINT pos; GetCursorPos(&pos); int result = TrackPopupMenuEx(menu, (TPM_NONOTIFY | TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD), pos.x, pos.y, (HWND)hwnd, NULL); DestroyMenu(menu); if(result > 0) { colorSpace = config->getColorSpaceNameByIndex(result - 1); return true; } else return false; }