BOOL PlayListPane::OnButton(UINT idx) { TRACEST(_T("PlayListPane::OnCommand"), idx); switch (idx) { case MI_ShowNumbers: m_PlayList.SetConfigurationOption(CPlayListListCtrl::C_ShowNumbers, m_PlayList.GetConfigurationOption(CPlayListListCtrl::C_ShowNumbers) == 0 ? 1 : 0); break; default: { PrgAPI* pAPI = PRGAPI(); MediaPlayer* pPlayer = pAPI->GetMediaPlayer(); MenuManager* pMM = pAPI->GetMenuManager(); MenuCommandsEnum cmd = (MenuCommandsEnum) idx; if (!pMM->HandlePlayerCommands(*pPlayer, cmd, pPlayer->GetPlayListPos()) || (pMM->HandleGeneralCommands(cmd))) return FALSE; } } return TRUE;; }
BOOL CTeenSpiritDlg::OnStateChanged(UINT stateMessage) { if (stateMessage == SM_MediaChanged) { MediaPlayListItem mpli; PrgAPI* pAPI = PRGAPI(); MediaPlayer* pMP = pAPI->GetMediaPlayer(); INT nPos = pMP->GetPlayListPos(); if (nPos != -1 && pMP->GetPlayListItem(mpli, nPos)) { if (mpli.artist == NULL) mpli.artist = _T(""); if (mpli.title == NULL) mpli.title = mpli.url; //=== Show Tray ToolTip //pAPI->GetTrayToolTipDlg()->OnMediaChanged(pAPI->GetOption(OPT_GEN_ShowToolTipOnMediaChanged)); //==== NOTIFIERS TrackerTrack track; track.artist = mpli.artist; track.title = mpli.title; track.rating = mpli.rating; track.length = (UINT)pMP->GetMediaLength(); pAPI->GetTracker()->SubmitTrack(ITracker::ACT_Started, track, GetCurrentUnixTimeStamp()); } return TRUE; } // case SM_MediaChanged: // { // MediaPlayer* pPlayer = pAPI->GetMediaPlayer(); // INT curMediaIdx = pPlayer->GetPlayListPos(); // if (curMediaIdx >= 0) // { // MediaPlayListItem mpli; // if (pPlayer->GetPlayListItem(mpli, curMediaIdx)) // { // //==== NOTIFIERS // if (mpli.artist == NULL) mpli.artist = _T(""); // if (mpli.title == NULL) mpli.title = mpli.url; // TrackerTrack track; // track.artist = mpli.artist; // track.title = mpli.title; // track.rating = mpli.rating; // track.length = (UINT)pPlayer->GetMediaLength(); // pAPI->GetTracker()->SubmitTrack(ITracker::ACT_Started, track, GetCurrentUnixTimeStamp()); // //==== Info Control // if (pAPI->GetOption(OPT_VIEWER_Auto))// m_ViewerPane.GetAutoViewerMode()) // { // TrackTypesEnum tt = GetTrackType(mpli.url); // if (tt < TTYPE_FIRSTVIDEO) // { // m_ViewerPane.SetMode(CViewerPane::MOD_NormalInfo); // } // else if (tt < TTYPE_FIRSTVIRTUAL) // { // m_ViewerPane.SetMode(CViewerPane::MOD_Visualizations); // } // else // { // m_ViewerPane.SetMode(CViewerPane::MOD_Browser); // } // } // if (m_ViewerPane.GetMode() == CViewerPane::MOD_NormalInfo && pAPI->GetOption(OPT_VIEWER_SyncWithPlayer)) // { // MediaPlayListItem mpli; // if (pPlayer->GetPlayListItem(mpli, curMediaIdx)) // { // FullTrackRecordSP rec; // if (pAPI->GetSQLManager()->GetFullTrackRecordByLocation(rec, mpli.url)) // { // CInfoCtrl* pIC = m_ViewerPane.GetInfoControl(); // if (pIC != NULL) // { // pIC->SetActiveItem(rec); // pIC->SetStyle(IT_Track); // pIC->Refresh(100); // } // } // } // } // } // // } // // } // // break; return FALSE; }
void TrayToolTipDlg::Draw(CDC& dc) { TRACEST(_T("TrayToolTipDlg::Draw")); CRect rcMemDC(0, 0, m_ff.GetWidth(), m_ff.GetHeight()); PrgAPI* pAPI = PRGAPI(); MediaPlayer* pMP = pAPI->GetMediaPlayer(); //FullTrackRecordSP m_rec; MediaPlayListItem mpli; BOOL mpliIsValid = FALSE; INT playListPos = pMP->GetPlayListPos(); if (playListPos != -1) mpliIsValid = pMP->GetPlayListItem(mpli, playListPos); CRect rcCalc(rcMemDC); dc.SetBkMode(TRANSPARENT); dc.SelectStockObject(NULL_BRUSH); dc.SelectStockObject(DC_PEN); INT maxTextWidth = 0; m_pictureWidth = 0; INT textLine1Width = 0; INT textLine2Width = 0; using namespace Gdiplus; Graphics graphics(dc.GetSafeHdc()); graphics.SetSmoothingMode(SmoothingModeAntiAlias); graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic); COLORREF outlineColor = RGB(220,220,220); INT r = GetRValue(m_colors[COL_TitleText]) + GetGValue(m_colors[COL_TitleText]) + GetBValue(m_colors[COL_TitleText]); if (r > (256 * 3) / 2) outlineColor = RGB(30,30,30); if (mpliIsValid == FALSE) { Gdiplus::SolidBrush br(GdiplusUtilities::COLORREF2Color(m_colors[COL_Bk])); graphics.FillRectangle(&br, GdiplusUtilities::RECT2GdiplusRect(rcMemDC)); //rcMemDC.bottom = GetTotalHeight(); //CFont* pOldFont = dc.SelectObject(&m_font[FNT_Title]); //dc.SetTextColor(m_colors[COL_TitleText]); //rcMemDC.right = m_minWidth; //dc.DrawText(CTeenSpiritApp::sAppTitle, -1, &rcMemDC, DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_NOPREFIX | DT_CENTER); //dc.SelectObject(pOldFont); //maxTextWidth = rcCalc.Width(); CRect rcItem = rcMemDC; rcItem.bottom = GetTotalHeight() - 30; rcItem.right = m_minWidth; LOGFONT lf; m_font[FNT_Title].GetLogFont(&lf); GdiplusUtilities::DrawTextOutline(graphics, CTeenSpiritApp::sAppTitle, _tcslen(CTeenSpiritApp::sAppTitle), &rcItem, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_CENTER, lf, m_colors[COL_TitleText], outlineColor, 2); } else { SQLManager* pSM = pAPI->GetSQLManager(); FullTrackRecordSP rec; BOOL bRecIsValid = pSM->GetFullTrackRecordByLocation(rec, mpli.url); if (bRecIsValid) { mpli.artist = rec->artist.name.c_str(); mpli.title = rec->track.name.c_str(); mpli.rating = rec->track.rating; if (mpli.length == 0) mpli.length = rec->track.duration; } //=== Picture if (bRecIsValid) { LocalPictureManager* pLPM = pAPI->GetLocalPictureManager(); SQLManager* pSM = pAPI->GetSQLManager(); LPCTSTR imgPath = NULL; FullAlbumRecordSP albumRec; if (pSM->GetFullAlbumRecordByID(albumRec, rec->album.ID)) { imgPath = pLPM->GetMainAlbumPicture(albumRec->artist.name.c_str(), albumRec->album.name.c_str(), TRUE); if (imgPath == NULL) imgPath = pLPM->GetMainArtistPicture(albumRec->artist.name.c_str(), TRUE); } if (imgPath != NULL) { GdiPlusPicDrawer pic; pic.GetDrawParams().zoomLockMode = GdiPlusPicDrawer::ZLM_FillArea; pic.GetDrawParams().positionY = 0; CRect rcPicture; if (pic.LoadFile(imgPath)) { INT pictureHeight = rcMemDC.Height() - 2 * s_marginHeight; CSize sz = pic.GetPictureSize(); m_pictureWidth = pictureHeight * sz.cx / sz.cy; if (m_pictureWidth > 2 * pictureHeight) m_pictureWidth = 2 * pictureHeight; else if (m_pictureWidth < pictureHeight) m_pictureWidth = pictureHeight; rcPicture.left = s_marginWidth; rcPicture.top = s_marginHeight; rcPicture.right = rcPicture.left + m_pictureWidth; rcPicture.bottom = rcPicture.top + pictureHeight; pic.Draw(graphics, GdiplusUtilities::RECT2GdiplusRect(rcMemDC)); Gdiplus::SolidBrush br(GdiplusUtilities::COLORREF2Color(m_colors[COL_Bk], 50)); graphics.FillRectangle(&br, GdiplusUtilities::RECT2GdiplusRect(rcMemDC)); if (pic.Draw(graphics, GdiplusUtilities::RECT2GdiplusRect(rcPicture))) { dc.SelectStockObject(NULL_BRUSH); dc.SelectStockObject(DC_PEN); dc.SetDCPenColor(m_colors[COL_PictureBorder]); dc.Rectangle(&rcPicture); //INT shadowDist = 4; //COLORREF clrSshadow = DarkenColor(m_colors[COL_Bk2], .8); //dc.SelectStockObject(DC_BRUSH); //dc.SelectStockObject(NULL_PEN); //dc.SetDCBrushColor(clrSshadow); //dc.Rectangle(rcPicture.left + shadowDist, rcPicture.bottom, rcPicture.right + shadowDist, rcPicture.bottom + shadowDist); //dc.Rectangle(rcPicture.right, rcPicture.top + shadowDist, rcPicture.right + shadowDist, rcPicture.bottom + shadowDist); } } } else { Gdiplus::SolidBrush br(GdiplusUtilities::COLORREF2Color(m_colors[COL_Bk])); graphics.FillRectangle(&br, GdiplusUtilities::RECT2GdiplusRect(rcMemDC)); } } INT totalFontHeight = m_fontHeight[FNT_Title] + m_fontHeight[FNT_Subtitle];// + m_fontHeight[FNT_Text]; CRect rcItem(rcMemDC); LOGFONT lf; //=== AppTitle rcItem.top = s_internalMarginHeight; rcItem.left += s_marginWidth + m_pictureWidth + s_marginWidth; rcItem.right -= s_marginWidth; rcItem.bottom = rcItem.top + m_fontHeight[FNT_AppTitle]; //m_font[FNT_AppTitle].GetLogFont(&lf); //GdiplusUtilities::DrawTextOutline(graphics, CTeenSpiritApp::sAppTitle, _tcslen(CTeenSpiritApp::sAppTitle), &rcItem, // DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_NOPREFIX | DT_LEFT, // lf, m_colors[COL_TitleText], outlineColor, 2); //=== Title rcItem.top = 10; rcItem.bottom = rcItem.top + m_fontHeight[FNT_Title]; m_font[FNT_Title].GetLogFont(&lf); //Gdiplus::RectF rf = GdiplusUtilities::DrawTextMeasure(graphics, mpli.title, _tcslen(mpli.title), lf); CRect rcCalc; GdiplusUtilities::DrawTextOutline(graphics, mpli.title, _tcslen(mpli.title), &rcItem, DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_NOPREFIX | DT_LEFT, lf, m_colors[COL_TitleText], outlineColor, 2, FALSE, &rcCalc); INT textWidth = rcCalc.Width(); maxTextWidth = textWidth; //=== SubTitle rcItem.top = rcItem.bottom + 3 * s_internalMarginHeight; rcItem.bottom = rcItem.top + m_fontHeight[FNT_Subtitle]; m_font[FNT_Subtitle].GetLogFont(&lf); //rf = GdiplusUtilities::DrawTextMeasure(graphics, mpli.artist, _tcslen(mpli.artist), lf); GdiplusUtilities::DrawTextOutline(graphics, mpli.artist, _tcslen(mpli.artist), &rcItem, DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_NOPREFIX | DT_LEFT, lf, m_colors[COL_SubTitleText], outlineColor, 2, FALSE, &rcCalc); textWidth = rcCalc.Width(); if (textWidth > maxTextWidth) maxTextWidth = textWidth; maxTextWidth += 4 * s_marginWidth; // dc.SelectObject(pOldBrush); // dc.SelectObject(pOldPen); } INT buttonsWidth = SBTN_Last * s_systemButtonWidth + s_distanceBetweenButtonsWidth + BTN_Last * s_normalButtonWidth; if (buttonsWidth > maxTextWidth) maxTextWidth = buttonsWidth; INT desiredWith = s_marginWidth + m_pictureWidth + s_marginWidth + maxTextWidth + s_marginWidth; if (desiredWith > m_maxWidth) desiredWith = m_maxWidth; else if (desiredWith < m_minWidth) desiredWith = m_minWidth; CRect rcWindow; GetWindowRect(&rcWindow); if (rcWindow.Width() != desiredWith) { m_windowWidth = desiredWith; SetWindowPos(NULL, rcWindow.right - desiredWith, rcWindow.top, m_windowWidth, GetTotalHeight(), SWP_NOACTIVATE | SWP_NOZORDER); } m_bDataAreInvalid = FALSE; //=== Text 20% //if (m_hits > 0) //{ // rcItem.top = rcItem.bottom; // rcItem.bottom = rcItem.top + rc.Height() * m_fontHeight[FNT_Text] / totalFontHeight; // dc.SelectObject(&m_font[FNT_Text]); // TCHAR text[500]; // _sntprintf(text, 500, _T("%s: %d %s: %d"), pAPI->GetString(IDS_RANK), m_rank, pAPI->GetString(IDS_HITS), m_hits); // dc.DrawText(text, -1, &rcItem, DT_SINGLELINE | DT_END_ELLIPSIS | DT_VCENTER | DT_NOPREFIX | DT_LEFT); //} }
LRESULT CTeenSpiritDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_GETTEXT && wParam > GTB_First && wParam < GTB_Last && lParam != 0)//External commands interface { INT ret = 0; LPCTSTR str = NULL; LPTSTR externalBuffer = (LPTSTR) lParam; externalBuffer[0] = 0; MediaPlayer* pPlayer = PRGAPI()->GetMediaPlayer(); INT curTrack = pPlayer->GetPlayListPos(); if (curTrack >= 0) { MediaPlayListItem mpli; if (pPlayer->GetPlayListItem(mpli, curTrack)) { switch (wParam) { case GTB_Artist: str = mpli.artist; break; case GTB_Title: str = mpli.title; break; default: ASSERT(0); break; } } } if (str == NULL) return 0; _tcsncpy(externalBuffer, str, wParam); return _tcslen(str); } else if (message == WM_COMMAND)//External commands interface { MediaPlayer* pPlayer = PRGAPI()->GetMediaPlayer(); if (pPlayer != NULL) { BOOL bHandled = TRUE; switch (wParam) { case EXTERNALCOMMAND_Play: //Returns 0 on success pPlayer->Start(); break; case EXTERNALCOMMAND_Pause: //Returns 0 on success pPlayer->Pause(); break; case EXTERNALCOMMAND_Stop: //Returns 0 on success pPlayer->Stop(); break; case EXTERNALCOMMAND_Next: //Returns 0 on success pPlayer->Next(); break; case GTB_Artist: case EXTERNALCOMMAND_Previous: //Returns 0 on success pPlayer->Previous(); break; case EXTERNALCOMMAND_ShowHidePlayer: //lparam=1 to show. 0 to hide. Returns 0 on success if (IsWindowVisible() && lParam == 0) PostMessage(WM_SYSCOMMAND, SC_MINIMIZE); else if (!IsWindowVisible() && lParam == 1) PostMessage(WM_SYSCOMMAND, SC_RESTORE); break; case EXTERNALCOMMAND_GetVolume: //Return vol 0-100. Returns 0-100 on success return pPlayer->GetVolume(); case EXTERNALCOMMAND_SetVolume: //lParam is the new value(0-100) retunrns 0 on success pPlayer->SetVolume(lParam); PRGAPI()->GetStateManager()->SendMessage(SM_PlayerVolumeChanged); break; case EXTERNALCOMMAND_GetMute: //Returns 1 on mute ON. 0 on Mute off return pPlayer->GetMute(); case EXTERNALCOMMAND_SetMute: //lparam=1 for mute ON. 0 Returns 0 on success pPlayer->SetMute(lParam != 0); PRGAPI()->GetStateManager()->PostMessage(SM_PlayerSettingsChanged); break; case EXTERNALCOMMAND_GetMediaLength: //returns the number of seconds return INT(pPlayer->GetMediaLength()); case EXTERNALCOMMAND_GetMediaPos: //returns the number of seconds return INT(pPlayer->GetMediaPos()); case EXTERNALCOMMAND_SetMediaPos: //lparam=1 for mute ON. 0 Returns 0 on success pPlayer->SetMediaPos(lParam); break; default: bHandled = FALSE; } if (bHandled) return 0; } } else if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) { TRACE(_T("CTeenSpiritDlg::WindowProc. KeyDown: %d-%d\r\n"), wParam, lParam); } return CDialog::WindowProc(message, wParam, lParam); }