Draw_pat.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  1. /*
  2. * draw_pat.cpp
  3. * ------------
  4. * Purpose: Code for drawing the pattern data.
  5. * Notes : Also used for updating the status bar.
  6. * Authors: Olivier Lapicque
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #include "stdafx.h"
  11. #include "Mptrack.h"
  12. #include "Mainfrm.h"
  13. #include "Moddoc.h"
  14. #include "dlg_misc.h"
  15. #include "Globals.h"
  16. #include "View_pat.h"
  17. #include "EffectVis.h"
  18. #include "ChannelManagerDlg.h"
  19. #include "../soundlib/tuning.h"
  20. #include "../soundlib/mod_specifications.h"
  21. #include "../soundlib/Tables.h"
  22. #include "../soundlib/plugins/PlugInterface.h"
  23. #include "../common/mptStringBuffer.h"
  24. #include "EffectInfo.h"
  25. #include "PatternFont.h"
  26. OPENMPT_NAMESPACE_BEGIN
  27. // Headers
  28. enum
  29. {
  30. ROWHDR_WIDTH = 32, // Row header
  31. COLHDR_HEIGHT = 16 + 4, // Column header (name + color)
  32. VUMETERS_HEIGHT = 13, // Height of vu-meters
  33. PLUGNAME_HEIGHT = 16, // Height of plugin names
  34. VUMETERS_BMPWIDTH = 32,
  35. VUMETERS_BMPHEIGHT = 10,
  36. VUMETERS_MEDWIDTH = 24,
  37. VUMETERS_LOWIDTH = 16,
  38. };
  39. enum
  40. {
  41. COLUMN_BITS_NONE = 0x00,
  42. COLUMN_BITS_NOTE = 0x01,
  43. COLUMN_BITS_INSTRUMENT = 0x02,
  44. COLUMN_BITS_VOLUME = 0x04,
  45. COLUMN_BITS_FXCMD = 0x08,
  46. COLUMN_BITS_FXPARAM = 0x10,
  47. COLUMN_BITS_FXCMDANDPARAM = 0x18,
  48. COLUMN_BITS_ALLCOLUMNS = 0x1F,
  49. COLUMN_BITS_UNKNOWN = 0x20, // Appears to be unused
  50. COLUMN_BITS_ALL = 0x3F,
  51. COLUMN_BITS_SKIP = 0x40,
  52. COLUMN_BITS_INVISIBLE = 0x80,
  53. };
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Effect colour codes
  56. // EffectType => ModColor mapping
  57. static constexpr int effectColors[] =
  58. {
  59. 0,
  60. MODCOLOR_GLOBALS,
  61. MODCOLOR_VOLUME,
  62. MODCOLOR_PANNING,
  63. MODCOLOR_PITCH,
  64. };
  65. static_assert(std::size(effectColors) == MAX_EFFECT_TYPE);
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CViewPattern Drawing Implementation
  68. static uint8 HighlightColor(int c0, int c1)
  69. {
  70. int cf0 = 0xC0 - (c1 >> 2) - (c0 >> 3);
  71. Limit(cf0, 0x40, 0xC0);
  72. int cf1 = 0x100 - cf0;
  73. return static_cast<uint8>((c0 * cf0 + c1 * cf1) >> 8);
  74. }
  75. static void MixColors(CFastBitmap &dib, ModColor target, ModColor src1, ModColor src2)
  76. {
  77. const auto c1 = TrackerSettings::Instance().rgbCustomColors[src1], c2 = TrackerSettings::Instance().rgbCustomColors[src2];
  78. auto r = HighlightColor(GetRValue(c1), GetRValue(c2));
  79. auto g = HighlightColor(GetGValue(c1), GetGValue(c2));
  80. auto b = HighlightColor(GetBValue(c1), GetBValue(c2));
  81. dib.SetColor(target, RGB(r, g, b));
  82. }
  83. void CViewPattern::UpdateColors()
  84. {
  85. m_Dib.SetAllColors(0, MAX_MODCOLORS, TrackerSettings::Instance().rgbCustomColors.data());
  86. MixColors(m_Dib, MODCOLOR_2NDHIGHLIGHT, MODCOLOR_BACKHILIGHT, MODCOLOR_BACKNORMAL);
  87. MixColors(m_Dib, MODCOLOR_DEFAULTVOLUME, MODCOLOR_VOLUME, MODCOLOR_BACKNORMAL);
  88. MixColors(m_Dib, MODCOLOR_DUMMYCOMMAND, MODCOLOR_TEXTNORMAL, MODCOLOR_BACKNORMAL);
  89. m_Dib.SetBlendColor(TrackerSettings::Instance().rgbCustomColors[MODCOLOR_BLENDCOLOR]);
  90. }
  91. bool CViewPattern::UpdateSizes()
  92. {
  93. const PATTERNFONT *pfnt = PatternFont::currentFont;
  94. int oldx = m_szCell.cx, oldy = m_szCell.cy;
  95. m_szHeader.cx = ROWHDR_WIDTH;
  96. m_szHeader.cy = COLHDR_HEIGHT;
  97. m_szPluginHeader.cx = 0;
  98. m_szPluginHeader.cy = m_Status[psShowPluginNames] ? MulDiv(PLUGNAME_HEIGHT, m_nDPIy, 96) : 0;
  99. if(m_Status[psShowVUMeters]) m_szHeader.cy += VUMETERS_HEIGHT;
  100. m_szCell.cx = 4 + pfnt->nEltWidths[0];
  101. if (m_nDetailLevel >= PatternCursor::instrColumn) m_szCell.cx += pfnt->nEltWidths[1];
  102. if (m_nDetailLevel >= PatternCursor::volumeColumn) m_szCell.cx += pfnt->nEltWidths[2];
  103. if (m_nDetailLevel >= PatternCursor::effectColumn) m_szCell.cx += pfnt->nEltWidths[3] + pfnt->nEltWidths[4];
  104. m_szCell.cy = pfnt->nHeight;
  105. m_szHeader.cx = MulDiv(m_szHeader.cx, m_nDPIx, 96);
  106. m_szHeader.cy = MulDiv(m_szHeader.cy, m_nDPIy, 96);
  107. m_szHeader.cy += m_szPluginHeader.cy;
  108. if(oldy != m_szCell.cy)
  109. {
  110. m_Dib.SetSize(m_Dib.GetWidth(), m_szCell.cy);
  111. }
  112. return (oldx != m_szCell.cx || oldy != m_szCell.cy);
  113. }
  114. UINT CViewPattern::GetColumnOffset(PatternCursor::Columns column) const
  115. {
  116. const PATTERNFONT *pfnt = PatternFont::currentFont;
  117. LimitMax(column, PatternCursor::lastColumn);
  118. UINT offset = 0;
  119. for(int i = PatternCursor::firstColumn; i < column; i++)
  120. offset += pfnt->nEltWidths[i];
  121. return offset;
  122. }
  123. int CViewPattern::GetSmoothScrollOffset() const
  124. {
  125. if((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SMOOTHSCROLL) != 0 // Actually using the smooth scroll feature
  126. && (m_Status & (psFollowSong | psDragActive)) == psFollowSong // Not drawing a selection during playback
  127. && (m_nMidRow != 0 || GetYScrollPos() > 0) // If active row is not centered, only scroll when display position is actually not at the top
  128. && IsLiveRecord() // Actually playing live (not paused or stepping)
  129. && m_nNextPlayRow != m_nPlayRow) // Don't scroll if we stay on the same row
  130. {
  131. uint32 tick = m_nPlayTick;
  132. // Avoid jerky animation with backwards-going patterns
  133. if(m_nNextPlayRow == m_nPlayRow - 1) tick = m_nTicksOnRow - m_nPlayTick - 1;
  134. return Util::muldivr_unsigned(m_szCell.cy, tick, std::max(1u, m_nTicksOnRow));
  135. }
  136. return 0;
  137. }
  138. void CViewPattern::UpdateView(UpdateHint hint, CObject *pObj)
  139. {
  140. if(pObj == this)
  141. {
  142. return;
  143. }
  144. if(hint.GetType()[HINT_MPTOPTIONS])
  145. {
  146. PatternFont::UpdateFont(m_hWnd);
  147. UpdateColors();
  148. UpdateSizes();
  149. UpdateScrollSize();
  150. InvalidatePattern(true, true);
  151. return;
  152. }
  153. const auto generalHint = hint.ToType<GeneralHint>();
  154. if(generalHint.GetType()[HINT_MODTYPE | HINT_MODCHANNELS])
  155. {
  156. InvalidateChannelsHeaders();
  157. UpdateScrollSize();
  158. }
  159. if(generalHint.GetType()[HINT_MODTYPE])
  160. {
  161. // If sequence and pattern view became inconsistent (e.g. due to rearranging patterns during cleanup), synchronize to order list again
  162. const auto &order = Order();
  163. const ORDERINDEX ord = GetCurrentOrder();
  164. if(order.IsValidPat(ord) && order.at(ord) != m_nPattern)
  165. SetCurrentPattern(order.at(ord));
  166. }
  167. if(generalHint.GetType()[HINT_MODCHANNELS]
  168. && m_quickChannelProperties.m_hWnd
  169. && pObj != &m_quickChannelProperties
  170. && (generalHint.GetChannel() >= GetDocument()->GetNumChannels() || generalHint.GetChannel() == m_quickChannelProperties.GetChannel()))
  171. {
  172. m_quickChannelProperties.UpdateDisplay();
  173. }
  174. const PatternHint patternHint = hint.ToType<PatternHint>();
  175. const PATTERNINDEX updatePat = patternHint.GetPattern();
  176. if(hint.GetType() == HINT_PATTERNDATA
  177. && m_nPattern != updatePat
  178. && updatePat != 0
  179. && updatePat != GetNextPattern()
  180. && updatePat != GetPrevPattern())
  181. return;
  182. if(patternHint.GetType()[HINT_MODTYPE | HINT_PATTERNDATA])
  183. {
  184. InvalidatePattern(false, true);
  185. } else if(patternHint.GetType()[HINT_PATTERNROW])
  186. {
  187. InvalidateRow(static_cast<const RowHint &>(hint).GetRow());
  188. }
  189. }
  190. POINT CViewPattern::GetPointFromPosition(PatternCursor cursor) const
  191. {
  192. const PATTERNFONT *pfnt = PatternFont::currentFont;
  193. POINT pt;
  194. int xofs = GetXScrollPos();
  195. int yofs = GetYScrollPos();
  196. PatternCursor::Columns imax = cursor.GetColumnType();
  197. LimitMax(imax, PatternCursor::lastColumn);
  198. // if(imax > m_nDetailLevel)
  199. // {
  200. // // Extend to next channel
  201. // imax = PatternCursor::firstColumn;
  202. // cursor.Move(0, 1, 0);
  203. // }
  204. pt.x = (cursor.GetChannel() - xofs) * GetChannelWidth();
  205. for(int i = 0; i < imax; i++)
  206. {
  207. pt.x += pfnt->nEltWidths[i];
  208. }
  209. if (pt.x < 0) pt.x = 0;
  210. pt.x += Util::ScalePixels(ROWHDR_WIDTH, m_hWnd);
  211. pt.y = (cursor.GetRow() - yofs + m_nMidRow) * m_szCell.cy;
  212. if (pt.y < 0) pt.y = 0;
  213. pt.y += m_szHeader.cy;
  214. return pt;
  215. }
  216. PatternCursor CViewPattern::GetPositionFromPoint(POINT pt) const
  217. {
  218. const PATTERNFONT *pfnt = PatternFont::currentFont;
  219. int xofs = GetXScrollPos();
  220. int yofs = GetYScrollPos();
  221. int x = xofs + (pt.x - m_szHeader.cx) / GetChannelWidth();
  222. if (pt.x < m_szHeader.cx) x = (xofs) ? xofs - 1 : 0;
  223. int y = yofs - m_nMidRow + (pt.y - m_szHeader.cy + GetSmoothScrollOffset()) / m_szCell.cy;
  224. if (y < 0) y = 0;
  225. int xx = (pt.x - m_szHeader.cx) % GetChannelWidth(), dx = 0;
  226. int imax = 4;
  227. if (imax > (int)m_nDetailLevel + 1) imax = m_nDetailLevel + 1;
  228. int i = 0;
  229. for (i=0; i<imax; i++)
  230. {
  231. dx += pfnt->nEltWidths[i];
  232. if(xx < dx)
  233. break;
  234. }
  235. return PatternCursor(static_cast<ROWINDEX>(y), static_cast<CHANNELINDEX>(x), static_cast<PatternCursor::Columns>(i));
  236. }
  237. void CViewPattern::DrawLetter(int x, int y, char letter, int sizex, int ofsx)
  238. {
  239. const PATTERNFONT *pfnt = PatternFont::currentFont;
  240. if(pfnt->dibASCII)
  241. {
  242. if(32 <= letter && letter <= 127)
  243. {
  244. m_Dib.TextBlt(x, y, sizex, pfnt->spacingY, (((unsigned char)letter) * pfnt->nNoteWidth[0]) + ofsx, 0, pfnt->dibASCII);
  245. return;
  246. }
  247. }
  248. int srcx = pfnt->nSpaceX, srcy = pfnt->nSpaceY;
  249. if ((letter >= '0') && (letter <= '9'))
  250. {
  251. srcx = pfnt->nNumX;
  252. srcy = pfnt->nNumY + (letter - '0') * pfnt->spacingY;
  253. } else
  254. if ((letter >= 'A') && (letter < 'N'))
  255. {
  256. srcx = pfnt->nAlphaAM_X;
  257. srcy = pfnt->nAlphaAM_Y + (letter - 'A') * pfnt->spacingY;
  258. } else
  259. if ((letter >= 'N') && (letter <= 'Z'))
  260. {
  261. srcx = pfnt->nAlphaNZ_X;
  262. srcy = pfnt->nAlphaNZ_Y + (letter - 'N') * pfnt->spacingY;
  263. } else
  264. switch(letter)
  265. {
  266. case '?':
  267. srcx = pfnt->nAlphaNZ_X;
  268. srcy = pfnt->nAlphaNZ_Y + 13 * pfnt->spacingY;
  269. break;
  270. case '#':
  271. srcx = pfnt->nAlphaAM_X;
  272. srcy = pfnt->nAlphaAM_Y + 13 * pfnt->spacingY;
  273. break;
  274. case '\\':
  275. srcx = pfnt->nAlphaNZ_X;
  276. srcy = pfnt->nAlphaNZ_Y + 14 * pfnt->spacingY;
  277. break;
  278. case ':':
  279. srcx = pfnt->nAlphaNZ_X;
  280. srcy = pfnt->nAlphaNZ_Y + 15 * pfnt->spacingY;
  281. break;
  282. case '*':
  283. srcx = pfnt->nAlphaNZ_X;
  284. srcy = pfnt->nAlphaNZ_Y + 16 * pfnt->spacingY;
  285. break;
  286. case ' ':
  287. srcx = pfnt->nSpaceX;
  288. srcy = pfnt->nSpaceY;
  289. break;
  290. case 'b':
  291. srcx = pfnt->nAlphaAM_X;
  292. srcy = pfnt->nAlphaAM_Y + 14 * pfnt->spacingY;
  293. break;
  294. case '-':
  295. srcx = pfnt->nAlphaAM_X;
  296. srcy = pfnt->nAlphaAM_Y + 15 * pfnt->spacingY;
  297. break;
  298. case '+':
  299. srcx = pfnt->nAlphaAM_X;
  300. srcy = pfnt->nAlphaAM_Y + 16 * pfnt->spacingY;
  301. break;
  302. case 'd':
  303. srcx = pfnt->nAlphaAM_X;
  304. srcy = pfnt->nAlphaAM_Y + 17 * pfnt->spacingY;
  305. break;
  306. case '.':
  307. srcx = pfnt->nNoteX;
  308. srcy = pfnt->nNoteY;
  309. break;
  310. }
  311. m_Dib.TextBlt(x, y, sizex, pfnt->spacingY, srcx+ofsx, srcy, pfnt->dib);
  312. }
  313. void CViewPattern::DrawLetter(int x, int y, wchar_t letter, int sizex, int ofsx)
  314. {
  315. DrawLetter(x, y, mpt::unsafe_char_convert<char>(letter), sizex, ofsx);
  316. }
  317. #if MPT_CXX_AT_LEAST(20)
  318. void CViewPattern::DrawLetter(int x, int y, char8_t letter, int sizex, int ofsx)
  319. {
  320. DrawLetter(x, y, mpt::unsafe_char_convert<char>(letter), sizex, ofsx);
  321. }
  322. #endif
  323. static MPT_FORCEINLINE void DrawPadding(CFastBitmap &dib, const PATTERNFONT *pfnt, int x, int y, int col)
  324. {
  325. if(pfnt->padding[col])
  326. dib.TextBlt(x + pfnt->nEltWidths[col] - pfnt->padding[col], y, pfnt->padding[col], pfnt->spacingY, pfnt->nClrX + pfnt->nEltWidths[col] - pfnt->padding[col], pfnt->nClrY, pfnt->dib);
  327. }
  328. void CViewPattern::DrawNote(int x, int y, UINT note, CTuning* pTuning)
  329. {
  330. const PATTERNFONT *pfnt = PatternFont::currentFont;
  331. UINT xsrc = pfnt->nNoteX, ysrc = pfnt->nNoteY, dx = pfnt->nEltWidths[0];
  332. if (!note)
  333. {
  334. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, xsrc, ysrc, pfnt->dib);
  335. } else
  336. if (note == NOTE_NOTECUT)
  337. {
  338. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, xsrc, ysrc + 13*pfnt->spacingY, pfnt->dib);
  339. } else
  340. if (note == NOTE_KEYOFF)
  341. {
  342. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, xsrc, ysrc + 14*pfnt->spacingY, pfnt->dib);
  343. } else
  344. if(note == NOTE_FADE)
  345. {
  346. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, xsrc, ysrc + 17*pfnt->spacingY, pfnt->dib);
  347. } else
  348. if(note == NOTE_PC)
  349. {
  350. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, xsrc, ysrc + 15*pfnt->spacingY, pfnt->dib);
  351. } else
  352. if(note == NOTE_PCS)
  353. {
  354. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, xsrc, ysrc + 16*pfnt->spacingY, pfnt->dib);
  355. } else
  356. {
  357. if(pTuning)
  358. {
  359. // Drawing custom note names
  360. std::wstring noteStr = mpt::ToWide(pTuning->GetNoteName(static_cast<Tuning::NOTEINDEXTYPE>(note - NOTE_MIDDLEC)));
  361. if(noteStr.size() < 3)
  362. noteStr.resize(3, L' ');
  363. DrawLetter(x, y, noteStr[0], pfnt->nNoteWidth[0], 0);
  364. DrawLetter(x + pfnt->nNoteWidth[0], y, noteStr[1], pfnt->nNoteWidth[1], 0);
  365. DrawLetter(x + pfnt->nNoteWidth[0] + pfnt->nNoteWidth[1], y, noteStr[2], pfnt->nOctaveWidth, 0);
  366. } else
  367. {
  368. // Original
  369. UINT o = (note - NOTE_MIN) / 12; //Octave
  370. UINT n = (note - NOTE_MIN) % 12; //Note
  371. // Hack for default pattern font, allowing for sharps
  372. if(TrackerSettings::Instance().accidentalFlats)
  373. {
  374. DrawLetter(x, y, NoteNamesFlat[n][0], pfnt->nNoteWidth[0], 0);
  375. DrawLetter(x + pfnt->nNoteWidth[0], y, NoteNamesFlat[n][1], pfnt->nNoteWidth[1], 0);
  376. } else
  377. {
  378. m_Dib.TextBlt(x, y, pfnt->nNoteWidth[0] + pfnt->nNoteWidth[1], pfnt->spacingY, xsrc, ysrc+(n+1)*pfnt->spacingY, pfnt->dib);
  379. }
  380. if(o <= 15)
  381. m_Dib.TextBlt(x + pfnt->nNoteWidth[0] + pfnt->nNoteWidth[1], y, pfnt->nOctaveWidth, pfnt->spacingY,
  382. pfnt->nNumX, pfnt->nNumY+o*pfnt->spacingY, pfnt->dib);
  383. else
  384. DrawLetter(x + pfnt->nNoteWidth[0] + pfnt->nNoteWidth[1], y, '?', pfnt->nOctaveWidth);
  385. }
  386. }
  387. DrawPadding(m_Dib, pfnt, x, y, 0);
  388. }
  389. void CViewPattern::DrawInstrument(int x, int y, UINT instr)
  390. {
  391. const PATTERNFONT *pfnt = PatternFont::currentFont;
  392. if (instr)
  393. {
  394. UINT dx = pfnt->nInstrHiWidth;
  395. if (instr < 100)
  396. {
  397. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, pfnt->nNumX+pfnt->nInstrOfs, pfnt->nNumY+(instr / 10)*pfnt->spacingY, pfnt->dib);
  398. } else
  399. {
  400. m_Dib.TextBlt(x, y, dx, pfnt->spacingY, pfnt->nNum10X+pfnt->nInstr10Ofs, pfnt->nNum10Y+((instr-100) / 10)*pfnt->spacingY, pfnt->dib);
  401. }
  402. m_Dib.TextBlt(x+dx, y, pfnt->nEltWidths[1]-dx, pfnt->spacingY, pfnt->nNumX+pfnt->paramLoMargin, pfnt->nNumY+(instr % 10)*pfnt->spacingY, pfnt->dib);
  403. } else
  404. {
  405. m_Dib.TextBlt(x, y, pfnt->nEltWidths[1], pfnt->spacingY, pfnt->nClrX+pfnt->nEltWidths[0], pfnt->nClrY, pfnt->dib);
  406. }
  407. DrawPadding(m_Dib, pfnt, x, y, 1);
  408. }
  409. void CViewPattern::DrawVolumeCommand(int x, int y, const ModCommand &mc, bool drawDefaultVolume)
  410. {
  411. const PATTERNFONT *pfnt = PatternFont::currentFont;
  412. if(mc.IsPcNote())
  413. {
  414. //If note is parameter control note, drawing volume command differently.
  415. const int val = std::min(ModCommand::maxColumnValue, static_cast<int>(mc.GetValueVolCol()));
  416. if(pfnt->pcParamMargin) m_Dib.TextBlt(x, y, pfnt->pcParamMargin, pfnt->spacingY, pfnt->nClrX, pfnt->nClrY, pfnt->dib);
  417. m_Dib.TextBlt(x + pfnt->pcParamMargin, y, pfnt->nVolCmdWidth, pfnt->spacingY,
  418. pfnt->nNumX, pfnt->nNumY+(val / 100)*pfnt->spacingY, pfnt->dib);
  419. m_Dib.TextBlt(x+pfnt->nVolCmdWidth, y, pfnt->nVolHiWidth, pfnt->spacingY,
  420. pfnt->nNumX, pfnt->nNumY+((val / 10)%10)*pfnt->spacingY, pfnt->dib);
  421. m_Dib.TextBlt(x+pfnt->nVolCmdWidth+pfnt->nVolHiWidth, y, pfnt->nEltWidths[2]-(pfnt->nVolCmdWidth+pfnt->nVolHiWidth), pfnt->spacingY,
  422. pfnt->nNumX, pfnt->nNumY+(val % 10)*pfnt->spacingY, pfnt->dib);
  423. } else
  424. {
  425. ModCommand::VOLCMD volcmd = mc.volcmd;
  426. int vol = (mc.vol & 0x7F);
  427. if(drawDefaultVolume)
  428. {
  429. // Displaying sample default volume if there is no volume command.
  430. volcmd = VOLCMD_VOLUME;
  431. vol = GetDefaultVolume(mc);
  432. }
  433. if(volcmd != VOLCMD_NONE && volcmd < MAX_VOLCMDS)
  434. {
  435. m_Dib.TextBlt(x, y, pfnt->nVolCmdWidth, pfnt->spacingY,
  436. pfnt->nVolX, pfnt->nVolY + volcmd * pfnt->spacingY, pfnt->dib);
  437. m_Dib.TextBlt(x+pfnt->nVolCmdWidth, y, pfnt->nVolHiWidth, pfnt->spacingY,
  438. pfnt->nNumX, pfnt->nNumY + (vol / 10) * pfnt->spacingY, pfnt->dib);
  439. m_Dib.TextBlt(x+pfnt->nVolCmdWidth + pfnt->nVolHiWidth, y, pfnt->nEltWidths[2] - (pfnt->nVolCmdWidth + pfnt->nVolHiWidth), pfnt->spacingY,
  440. pfnt->nNumX, pfnt->nNumY + (vol % 10) * pfnt->spacingY, pfnt->dib);
  441. } else
  442. {
  443. int srcx = pfnt->nEltWidths[0] + pfnt->nEltWidths[1];
  444. m_Dib.TextBlt(x, y, pfnt->nEltWidths[2], pfnt->spacingY, pfnt->nClrX+srcx, pfnt->nClrY, pfnt->dib);
  445. }
  446. }
  447. DrawPadding(m_Dib, pfnt, x, y, 2);
  448. }
  449. void CViewPattern::OnDraw(CDC *pDC)
  450. {
  451. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  452. CHAR s[256];
  453. CRect rcClient, rect, rc;
  454. const CModDoc *pModDoc;
  455. MPT_ASSERT(pDC);
  456. UpdateSizes();
  457. if ((pModDoc = GetDocument()) == nullptr) return;
  458. const int vuHeight = MulDiv(VUMETERS_HEIGHT, m_nDPIy, 96);
  459. const int colHeight = MulDiv(COLHDR_HEIGHT, m_nDPIy, 96);
  460. const int chanColorHeight = MulDiv(4, m_nDPIy, 96);
  461. const int chanColorOffset = MulDiv(2, m_nDPIy, 96);
  462. const int recordInsX = MulDiv(3, m_nDPIx, 96);
  463. const bool doSmoothScroll = (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SMOOTHSCROLL) != 0;
  464. GetClientRect(&rcClient);
  465. HDC hdc;
  466. HBITMAP oldBitmap = NULL;
  467. if(doSmoothScroll)
  468. {
  469. if(rcClient != m_oldClient)
  470. {
  471. m_offScreenBitmap.DeleteObject();
  472. m_offScreenDC.DeleteDC();
  473. m_offScreenDC.CreateCompatibleDC(pDC);
  474. m_offScreenBitmap.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height());
  475. m_oldClient = rcClient;
  476. }
  477. hdc = m_offScreenDC;
  478. oldBitmap = SelectBitmap(hdc, m_offScreenBitmap);
  479. } else
  480. {
  481. hdc = pDC->m_hDC;
  482. }
  483. const auto dcBrush = GetStockBrush(DC_BRUSH);
  484. const auto faceColor = GetSysColor(COLOR_BTNFACE);
  485. const auto shadowColor = GetSysColor(COLOR_BTNSHADOW);
  486. const auto textColor = GetSysColor(COLOR_BTNTEXT);
  487. CHANNELINDEX xofs = static_cast<CHANNELINDEX>(GetXScrollPos());
  488. ROWINDEX yofs = static_cast<ROWINDEX>(GetYScrollPos());
  489. const CSoundFile &sndFile = pModDoc->GetSoundFile();
  490. UINT nColumnWidth = m_szCell.cx;
  491. UINT ncols = sndFile.GetNumChannels();
  492. int xpaint = m_szHeader.cx;
  493. int ypaint = rcClient.top + m_szHeader.cy - GetSmoothScrollOffset();
  494. const auto &order = Order();
  495. const ORDERINDEX ordCount = Order().GetLength();
  496. if (m_nMidRow)
  497. {
  498. if (yofs >= m_nMidRow)
  499. {
  500. yofs -= m_nMidRow;
  501. } else
  502. {
  503. UINT nSkip = m_nMidRow - yofs;
  504. PATTERNINDEX nPrevPat = PATTERNINDEX_INVALID;
  505. // Display previous pattern
  506. if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SHOWPREVIOUS)
  507. {
  508. if(m_nOrder > 0 && m_nOrder < ordCount)
  509. {
  510. ORDERINDEX prevOrder = order.GetPreviousOrderIgnoringSkips(m_nOrder);
  511. //Skip +++ items
  512. if(m_nOrder < order.size() && order[m_nOrder] == m_nPattern)
  513. {
  514. nPrevPat = order[prevOrder];
  515. }
  516. }
  517. }
  518. if(sndFile.Patterns.IsValidPat(nPrevPat))
  519. {
  520. ROWINDEX nPrevRows = sndFile.Patterns[nPrevPat].GetNumRows();
  521. ROWINDEX n = std::min(static_cast<ROWINDEX>(nSkip), nPrevRows);
  522. ypaint += (nSkip - n) * m_szCell.cy;
  523. rect.SetRect(0, m_szHeader.cy, nColumnWidth * ncols + m_szHeader.cx, ypaint - 1);
  524. m_Dib.SetBlendMode(true);
  525. DrawPatternData(hdc, nPrevPat, false, false,
  526. nPrevRows - n, nPrevRows, xofs, rcClient, &ypaint);
  527. m_Dib.SetBlendMode(false);
  528. } else
  529. {
  530. ypaint += nSkip * m_szCell.cy;
  531. rect.SetRect(0, m_szHeader.cy, nColumnWidth * ncols + m_szHeader.cx, ypaint - 1);
  532. }
  533. if ((rect.bottom > rect.top) && (rect.right > rect.left))
  534. {
  535. ::SetDCBrushColor(hdc, faceColor);
  536. ::FillRect(hdc, &rect, dcBrush);
  537. auto shadowRect = rect;
  538. shadowRect.top = shadowRect.bottom++;
  539. ::SetDCBrushColor(hdc, shadowColor);
  540. ::FillRect(hdc, &shadowRect, dcBrush);
  541. }
  542. yofs = 0;
  543. }
  544. }
  545. UINT nrows = sndFile.Patterns.IsValidPat(m_nPattern) ? sndFile.Patterns[m_nPattern].GetNumRows() : 0;
  546. int ypatternend = ypaint + (nrows-yofs)*m_szCell.cy;
  547. DrawPatternData(hdc, m_nPattern, true, (pMainFrm->GetModPlaying() == pModDoc),
  548. yofs, nrows, xofs, rcClient, &ypaint);
  549. // Display next pattern
  550. if ((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SHOWPREVIOUS) && (ypaint < rcClient.bottom) && (ypaint == ypatternend))
  551. {
  552. int nVisRows = (rcClient.bottom - ypaint + m_szCell.cy - 1) / m_szCell.cy;
  553. if ((nVisRows > 0) && (m_nMidRow))
  554. {
  555. PATTERNINDEX nNextPat = PATTERNINDEX_INVALID;
  556. ORDERINDEX nNextOrder = order.GetNextOrderIgnoringSkips(m_nOrder);
  557. if(nNextOrder == m_nOrder) nNextOrder = ORDERINDEX_INVALID;
  558. //Ignore skip items(+++) from sequence.
  559. if(m_nOrder < ordCount && nNextOrder < ordCount && order[m_nOrder] == m_nPattern)
  560. {
  561. nNextPat = order[nNextOrder];
  562. }
  563. if(sndFile.Patterns.IsValidPat(nNextPat))
  564. {
  565. ROWINDEX nNextRows = sndFile.Patterns[nNextPat].GetNumRows();
  566. ROWINDEX n = std::min(static_cast<ROWINDEX>(nVisRows), nNextRows);
  567. m_Dib.SetBlendMode(true);
  568. DrawPatternData(hdc, nNextPat, false, false,
  569. 0, n, xofs, rcClient, &ypaint);
  570. m_Dib.SetBlendMode(false);
  571. }
  572. }
  573. }
  574. // Drawing outside pattern area
  575. xpaint = m_szHeader.cx + (ncols - xofs) * nColumnWidth;
  576. if ((xpaint < rcClient.right) && (ypaint > rcClient.top))
  577. {
  578. rc.SetRect(xpaint, rcClient.top, rcClient.right, ypaint);
  579. ::SetDCBrushColor(hdc, faceColor);
  580. ::FillRect(hdc, &rc, dcBrush);
  581. }
  582. if (ypaint < rcClient.bottom)
  583. {
  584. int width = Util::ScalePixels(1, m_hWnd);
  585. rc.SetRect(0, ypaint, rcClient.right + 1, rcClient.bottom + 1);
  586. if(width == 1)
  587. DrawButtonRect(hdc, &rc, _T(""));
  588. else
  589. DrawEdge(hdc, rc, EDGE_RAISED, BF_TOPLEFT | BF_MIDDLE); // Prevent lower edge from being drawn
  590. }
  591. // Drawing pattern selection
  592. if(m_Status[psDragnDropping])
  593. {
  594. DrawDragSel(hdc);
  595. }
  596. const auto buttonBrush = GetSysColorBrush(COLOR_BTNFACE), blackBrush = GetStockBrush(BLACK_BRUSH);
  597. UINT ncolhdr = xofs;
  598. xpaint = m_szHeader.cx;
  599. ypaint = rcClient.top;
  600. rect.SetRect(0, rcClient.top, rcClient.right, rcClient.top + m_szHeader.cy);
  601. if(::RectVisible(hdc, &rect))
  602. {
  603. sprintf(s, "#%u", m_nPattern);
  604. rect.right = m_szHeader.cx;
  605. DrawButtonRect(hdc, &rect, s, FALSE,
  606. (m_bInItemRect && m_nDragItem.Type() == DragItem::PatternHeader) ? TRUE : FALSE);
  607. const int dropWidth = Util::ScalePixels(2, m_hWnd);
  608. // Drawing Channel Headers
  609. while (xpaint < rcClient.right)
  610. {
  611. rect.SetRect(xpaint, ypaint, xpaint + nColumnWidth, ypaint + m_szHeader.cy);
  612. if (ncolhdr < ncols)
  613. {
  614. const auto &channel = sndFile.ChnSettings[ncolhdr];
  615. const auto recordGroup = pModDoc->GetChannelRecordGroup(static_cast<CHANNELINDEX>(ncolhdr));
  616. const char *pszfmt = sndFile.m_bChannelMuteTogglePending[ncolhdr]? "[Channel %u]" : "Channel %u";
  617. if(channel.szName[0] != 0)
  618. pszfmt = sndFile.m_bChannelMuteTogglePending[ncolhdr] ? "%u: [%s]" : "%u: %s";
  619. else if(m_nDetailLevel < PatternCursor::volumeColumn)
  620. pszfmt = sndFile.m_bChannelMuteTogglePending[ncolhdr] ? "[Ch%u]" : "Ch%u";
  621. else if(m_nDetailLevel < PatternCursor::effectColumn)
  622. pszfmt = sndFile.m_bChannelMuteTogglePending[ncolhdr] ? "[Chn %u]" : "Chn %u";
  623. sprintf(s, pszfmt, ncolhdr + 1, channel.szName.buf);
  624. DrawButtonRect(hdc, &rect, s,
  625. channel.dwFlags[CHN_MUTE] ? TRUE : FALSE,
  626. (m_bInItemRect && m_nDragItem.Type() == DragItem::ChannelHeader && m_nDragItem.Value() == ncolhdr) ? TRUE : FALSE,
  627. recordGroup != RecordGroup::NoGroup ? DT_RIGHT : DT_CENTER, chanColorHeight);
  628. if(channel.color != ModChannelSettings::INVALID_COLOR)
  629. {
  630. // Channel color
  631. CRect r;
  632. r.top = rect.top + chanColorOffset;
  633. r.bottom = r.top + chanColorHeight;
  634. r.left = rect.left + chanColorOffset;
  635. r.right = rect.right - chanColorOffset;
  636. ::SetDCBrushColor(hdc, channel.color);
  637. ::FillRect(hdc, r, dcBrush);
  638. }
  639. // When dragging around channel headers, mark insertion position
  640. if(m_Status[psDragging] && !m_bInItemRect
  641. && m_nDragItem.Type() == DragItem::ChannelHeader
  642. && m_nDropItem.Type() == DragItem::ChannelHeader
  643. && m_nDropItem.Value() == ncolhdr)
  644. {
  645. CRect r;
  646. r.top = rect.top;
  647. r.bottom = rect.bottom;
  648. // Drop position depends on whether hovered channel is left or right of dragged item.
  649. r.left = (m_nDropItem.Value() < m_nDragItem.Value() || m_Status[psShiftDragging]) ? rect.left : rect.right - dropWidth;
  650. r.right = r.left + dropWidth;
  651. ::SetDCBrushColor(hdc, textColor);
  652. ::FillRect(hdc, r, dcBrush);
  653. }
  654. rect.bottom = rect.top + colHeight;
  655. rect.top += chanColorHeight;
  656. if(recordGroup != RecordGroup::NoGroup)
  657. {
  658. CRect insRect;
  659. insRect.SetRect(xpaint, ypaint + chanColorHeight, xpaint + nColumnWidth / 8 + recordInsX, ypaint + colHeight);
  660. FrameRect(hdc, &rect, buttonBrush);
  661. InvertRect(hdc, &rect);
  662. s[0] = (recordGroup == RecordGroup::Group1) ? '1' : '2';
  663. s[1] = '\0';
  664. DrawButtonRect(hdc, &insRect, s, FALSE, FALSE, DT_CENTER);
  665. FrameRect(hdc, &insRect, blackBrush);
  666. }
  667. if(m_Status[psShowVUMeters])
  668. {
  669. OldVUMeters[ncolhdr] = 0;
  670. DrawChannelVUMeter(hdc, rect.left + 1, rect.bottom, ncolhdr);
  671. rect.top += vuHeight;
  672. rect.bottom += vuHeight;
  673. }
  674. if(m_Status[psShowPluginNames])
  675. {
  676. rect.top = rect.bottom;
  677. rect.bottom = rect.top + m_szPluginHeader.cy;
  678. if(PLUGINDEX mixPlug = channel.nMixPlugin; mixPlug != 0)
  679. sprintf(s, "%u: %s", mixPlug, (sndFile.m_MixPlugins[mixPlug - 1]).pMixPlugin ? sndFile.m_MixPlugins[mixPlug - 1].GetNameLocale() : "[empty]");
  680. else
  681. sprintf(s, "---");
  682. DrawButtonRect(hdc, &rect, s, channel.dwFlags[CHN_NOFX] ? TRUE : FALSE,
  683. ((m_bInItemRect) && (m_nDragItem.Type() == DragItem::PluginName) && (m_nDragItem.Value() == ncolhdr)) ? TRUE : FALSE, DT_CENTER);
  684. }
  685. } else break;
  686. ncolhdr++;
  687. xpaint += nColumnWidth;
  688. }
  689. }
  690. if(doSmoothScroll)
  691. {
  692. CRect clipRect;
  693. pDC->GetClipBox(clipRect);
  694. pDC->BitBlt(clipRect.left, clipRect.top, clipRect.Width(), clipRect.Height(), &m_offScreenDC, clipRect.left, clipRect.top, SRCCOPY);
  695. SelectBitmap(m_offScreenDC, oldBitmap);
  696. }
  697. //rewbs.fxVis
  698. if (m_pEffectVis)
  699. {
  700. //HACK: Update visualizer on every pattern redraw. Cleary there's space for opt here.
  701. if (m_pEffectVis->m_hWnd) m_pEffectVis->Update();
  702. }
  703. }
  704. static constexpr UINT EncodeRowColor(int rowBkCol, int rowCol, bool rowSelected)
  705. {
  706. return (rowBkCol << 16) | (rowCol << 8) | (rowSelected ? 1 : 0);
  707. }
  708. void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnable,
  709. bool isPlaying, ROWINDEX startRow, ROWINDEX numRows, CHANNELINDEX startChan, CRect &rcClient, int *pypaint)
  710. {
  711. uint8 selectedCols[MAX_BASECHANNELS]; // Bit mask of selected channel components
  712. static_assert(1 << PatternCursor::lastColumn <= Util::MaxValueOfType(selectedCols[0]) , "Columns are used as bitmasks.");
  713. const CSoundFile &sndFile = GetDocument()->GetSoundFile();
  714. if(!sndFile.Patterns.IsValidPat(nPattern))
  715. {
  716. return;
  717. }
  718. const CPattern &pattern = sndFile.Patterns[nPattern];
  719. const PATTERNFONT *pfnt = PatternFont::currentFont;
  720. CRect rect;
  721. int xpaint, ypaint = *pypaint;
  722. UINT nColumnWidth;
  723. CHANNELINDEX ncols = sndFile.GetNumChannels();
  724. nColumnWidth = m_szCell.cx;
  725. rect.SetRect(m_szHeader.cx, rcClient.top, m_szHeader.cx+nColumnWidth, rcClient.bottom);
  726. for(CHANNELINDEX cmk = startChan; cmk < ncols; cmk++)
  727. {
  728. selectedCols[cmk] = selEnable ? m_Selection.GetSelectionBits(cmk) : 0;
  729. if (!::RectVisible(hdc, &rect)) selectedCols[cmk] |= COLUMN_BITS_INVISIBLE;
  730. rect.left += nColumnWidth;
  731. rect.right += nColumnWidth;
  732. }
  733. // Max Visible Column
  734. CHANNELINDEX maxcol = ncols;
  735. while ((maxcol > startChan) && (selectedCols[maxcol-1] & COLUMN_BITS_INVISIBLE)) maxcol--;
  736. // Init bitmap border
  737. {
  738. UINT maxndx = sndFile.GetNumChannels() * m_szCell.cx;
  739. UINT ibmp = 0;
  740. if (maxndx > (UINT)m_Dib.GetWidth()) maxndx = m_Dib.GetWidth();
  741. do
  742. {
  743. ibmp += nColumnWidth;
  744. m_Dib.TextBlt(ibmp-4, 0, 4, m_szCell.cy, pfnt->nClrX+pfnt->nWidth-4, pfnt->nClrY, pfnt->dib);
  745. } while (ibmp + nColumnWidth <= maxndx);
  746. }
  747. const bool hexNumbers = (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_HEXDISPLAY);
  748. bool bRowSel = false;
  749. int row_col = -1, row_bkcol = -1;
  750. for(ROWINDEX row = startRow; row < numRows; row++)
  751. {
  752. UINT col, xbmp, nbmp, oldrowcolor;
  753. const int compRow = row + TrackerSettings::Instance().rowDisplayOffset;
  754. rect.left = 0;
  755. rect.top = ypaint;
  756. rect.right = rcClient.right;
  757. rect.bottom = rect.top + m_szCell.cy;
  758. if (!::RectVisible(hdc, &rect))
  759. {
  760. // No speedup for these columns next time
  761. for(CHANNELINDEX iup = startChan; iup < maxcol; iup++)
  762. selectedCols[iup] &= ~COLUMN_BITS_SKIP;
  763. // skip row
  764. ypaint += m_szCell.cy;
  765. if(ypaint >= rcClient.bottom)
  766. break;
  767. continue;
  768. }
  769. rect.right = rect.left + m_szHeader.cx;
  770. bool rowDisabled = sndFile.m_lockRowStart != ROWINDEX_INVALID && (row < sndFile.m_lockRowStart || row > sndFile.m_lockRowEnd);
  771. TCHAR s[32];
  772. if(hexNumbers)
  773. wsprintf(s, _T("%s%02X"), compRow < 0 ? _T("-") : _T(""), std::abs(compRow));
  774. else
  775. wsprintf(s, _T("%d"), compRow);
  776. DrawButtonRect(hdc, &rect, s, !selEnable || rowDisabled);
  777. oldrowcolor = EncodeRowColor(row_bkcol, row_col, bRowSel);
  778. bRowSel = (m_Selection.ContainsVertical(PatternCursor(row)));
  779. row_col = MODCOLOR_TEXTNORMAL;
  780. row_bkcol = MODCOLOR_BACKNORMAL;
  781. // time signature highlighting
  782. ROWINDEX nBeat = sndFile.m_nDefaultRowsPerBeat, nMeasure = sndFile.m_nDefaultRowsPerMeasure;
  783. if(sndFile.Patterns[nPattern].GetOverrideSignature())
  784. {
  785. nBeat = sndFile.Patterns[nPattern].GetRowsPerBeat();
  786. nMeasure = sndFile.Patterns[nPattern].GetRowsPerMeasure();
  787. }
  788. // secondary highlight (beats)
  789. ROWINDEX highlightRow = compRow;
  790. if(nMeasure > 0)
  791. highlightRow %= nMeasure;
  792. if ((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_2NDHIGHLIGHT)
  793. && nBeat > 0)
  794. {
  795. if((highlightRow % nBeat) == 0)
  796. {
  797. row_bkcol = MODCOLOR_2NDHIGHLIGHT;
  798. }
  799. }
  800. // primary highlight (measures)
  801. if((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_STDHIGHLIGHT)
  802. && nMeasure > 0)
  803. {
  804. if(highlightRow == 0)
  805. {
  806. row_bkcol = MODCOLOR_BACKHILIGHT;
  807. }
  808. }
  809. bool blendModeChanged = false;
  810. if (selEnable)
  811. {
  812. if ((row == m_nPlayRow) && (nPattern == m_nPlayPat))
  813. {
  814. row_col = MODCOLOR_TEXTPLAYCURSOR;
  815. row_bkcol = MODCOLOR_BACKPLAYCURSOR;
  816. }
  817. if (row == GetCurrentRow())
  818. {
  819. if(m_Status[psFocussed])
  820. {
  821. row_col = MODCOLOR_TEXTCURROW;
  822. row_bkcol = MODCOLOR_BACKCURROW;
  823. } else
  824. if(m_Status[psFollowSong] && isPlaying)
  825. {
  826. row_col = MODCOLOR_TEXTPLAYCURSOR;
  827. row_bkcol = MODCOLOR_BACKPLAYCURSOR;
  828. }
  829. }
  830. blendModeChanged = (rowDisabled != m_Dib.GetBlendMode());
  831. m_Dib.SetBlendMode(rowDisabled);
  832. }
  833. // Eliminate non-visible column
  834. xpaint = m_szHeader.cx;
  835. col = startChan;
  836. while ((selectedCols[col] & COLUMN_BITS_INVISIBLE) && (col < maxcol))
  837. {
  838. selectedCols[col] &= ~COLUMN_BITS_SKIP;
  839. col++;
  840. xpaint += nColumnWidth;
  841. }
  842. // Optimization: same row color ?
  843. bool useSpeedUpMask = (oldrowcolor == EncodeRowColor(row_bkcol, row_col, bRowSel)) && !blendModeChanged;
  844. xbmp = nbmp = 0;
  845. do
  846. {
  847. int x, bk_col, tx_col, col_sel, fx_col;
  848. const ModCommand *m = pattern.GetpModCommand(row, static_cast<CHANNELINDEX>(col));
  849. // Should empty volume commands be replaced with a volume command showing the default volume?
  850. const bool drawDefaultVolume = DrawDefaultVolume(m);
  851. DWORD dwSpeedUpMask = 0;
  852. if (useSpeedUpMask && (selectedCols[col] & COLUMN_BITS_SKIP) && (row))
  853. {
  854. const ModCommand *mold = m - ncols;
  855. const bool drawOldDefaultVolume = DrawDefaultVolume(mold);
  856. if (m->note == mold->note) dwSpeedUpMask |= COLUMN_BITS_NOTE;
  857. if ((m->instr == mold->instr) || (m_nDetailLevel < PatternCursor::instrColumn)) dwSpeedUpMask |= COLUMN_BITS_INSTRUMENT;
  858. if ( m->IsPcNote() || mold->IsPcNote() )
  859. {
  860. // Handle speedup mask for PC notes.
  861. if(m->note == mold->note)
  862. {
  863. if(m->GetValueVolCol() == mold->GetValueVolCol() || (m_nDetailLevel < PatternCursor::volumeColumn)) dwSpeedUpMask |= COLUMN_BITS_VOLUME;
  864. if(m->GetValueEffectCol() == mold->GetValueEffectCol() || (m_nDetailLevel < PatternCursor::effectColumn)) dwSpeedUpMask |= COLUMN_BITS_FXCMDANDPARAM;
  865. }
  866. } else
  867. {
  868. if ((m->volcmd == mold->volcmd && (m->volcmd == VOLCMD_NONE || m->vol == mold->vol) && !drawDefaultVolume && !drawOldDefaultVolume) || (m_nDetailLevel < PatternCursor::volumeColumn)) dwSpeedUpMask |= COLUMN_BITS_VOLUME;
  869. if ((m->command == mold->command) || (m_nDetailLevel < PatternCursor::effectColumn)) dwSpeedUpMask |= (m->command != CMD_NONE) ? COLUMN_BITS_FXCMD : COLUMN_BITS_FXCMDANDPARAM;
  870. }
  871. if (dwSpeedUpMask == COLUMN_BITS_ALLCOLUMNS) goto DoBlit;
  872. }
  873. selectedCols[col] |= COLUMN_BITS_SKIP;
  874. col_sel = 0;
  875. if (bRowSel) col_sel = selectedCols[col] & COLUMN_BITS_ALL;
  876. tx_col = row_col;
  877. bk_col = row_bkcol;
  878. if (col_sel)
  879. {
  880. tx_col = MODCOLOR_TEXTSELECTED;
  881. bk_col = MODCOLOR_BACKSELECTED;
  882. }
  883. // Speedup: Empty command which is either not or fully selected
  884. if (m->IsEmpty() && ((!col_sel) || (col_sel == COLUMN_BITS_ALLCOLUMNS)))
  885. {
  886. m_Dib.SetTextColor(tx_col, bk_col);
  887. m_Dib.TextBlt(xbmp, 0, nColumnWidth-4, m_szCell.cy, pfnt->nClrX, pfnt->nClrY, pfnt->dib);
  888. goto DoBlit;
  889. }
  890. x = 0;
  891. // Note
  892. if (!(dwSpeedUpMask & COLUMN_BITS_NOTE))
  893. {
  894. tx_col = row_col;
  895. bk_col = row_bkcol;
  896. if((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_EFFECTHILIGHT) && m->IsNote())
  897. {
  898. tx_col = MODCOLOR_NOTE;
  899. if(sndFile.m_SongFlags[SONG_AMIGALIMITS | SONG_PT_MODE])
  900. {
  901. // Highlight notes that exceed the Amiga's frequency range.
  902. if(sndFile.GetType() == MOD_TYPE_MOD && (m->note < NOTE_MIDDLEC - 12 || m->note >= NOTE_MIDDLEC + 2 * 12))
  903. {
  904. tx_col = MODCOLOR_DODGY_COMMANDS;
  905. } else if(sndFile.GetType() == MOD_TYPE_S3M && m->instr != 0 && m->instr <= sndFile.GetNumSamples())
  906. {
  907. uint32 period = sndFile.GetPeriodFromNote(m->note, 0, sndFile.GetSample(m->instr).nC5Speed);
  908. if(period < 113 * 4 || period > 856 * 4)
  909. {
  910. tx_col = MODCOLOR_DODGY_COMMANDS;
  911. }
  912. }
  913. }
  914. }
  915. if (col_sel & COLUMN_BITS_NOTE)
  916. {
  917. tx_col = MODCOLOR_TEXTSELECTED;
  918. bk_col = MODCOLOR_BACKSELECTED;
  919. }
  920. // Drawing note
  921. m_Dib.SetTextColor(tx_col, bk_col);
  922. if(sndFile.GetType() == MOD_TYPE_MPT && m->instr < MAX_INSTRUMENTS && sndFile.Instruments[m->instr])
  923. DrawNote(xbmp+x, 0, m->note, sndFile.Instruments[m->instr]->pTuning);
  924. else //Original
  925. DrawNote(xbmp+x, 0, m->note);
  926. }
  927. x += pfnt->nEltWidths[0];
  928. // Instrument
  929. if (m_nDetailLevel >= PatternCursor::instrColumn)
  930. {
  931. if (!(dwSpeedUpMask & COLUMN_BITS_INSTRUMENT))
  932. {
  933. tx_col = row_col;
  934. bk_col = row_bkcol;
  935. if ((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_EFFECTHILIGHT) && (m->instr))
  936. {
  937. tx_col = MODCOLOR_INSTRUMENT;
  938. }
  939. if (col_sel & COLUMN_BITS_INSTRUMENT)
  940. {
  941. tx_col = MODCOLOR_TEXTSELECTED;
  942. bk_col = MODCOLOR_BACKSELECTED;
  943. }
  944. // Drawing instrument
  945. m_Dib.SetTextColor(tx_col, bk_col);
  946. DrawInstrument(xbmp+x, 0, m->instr);
  947. }
  948. x += pfnt->nEltWidths[1];
  949. }
  950. // Volume
  951. if (m_nDetailLevel >= PatternCursor::volumeColumn)
  952. {
  953. if (!(dwSpeedUpMask & COLUMN_BITS_VOLUME))
  954. {
  955. tx_col = row_col;
  956. bk_col = row_bkcol;
  957. if (col_sel & COLUMN_BITS_VOLUME)
  958. {
  959. tx_col = MODCOLOR_TEXTSELECTED;
  960. bk_col = MODCOLOR_BACKSELECTED;
  961. } else if (!m->IsPcNote() && (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_EFFECTHILIGHT))
  962. {
  963. if(m->volcmd != VOLCMD_NONE && m->volcmd < MAX_VOLCMDS && effectColors[m->GetVolumeEffectType()] != 0)
  964. {
  965. tx_col = effectColors[m->GetVolumeEffectType()];
  966. } else if(drawDefaultVolume)
  967. {
  968. tx_col = MODCOLOR_DEFAULTVOLUME;
  969. }
  970. }
  971. // Drawing Volume
  972. m_Dib.SetTextColor(tx_col, bk_col);
  973. DrawVolumeCommand(xbmp + x, 0, *m, drawDefaultVolume);
  974. }
  975. x += pfnt->nEltWidths[2];
  976. }
  977. // Command & param
  978. if (m_nDetailLevel >= PatternCursor::effectColumn)
  979. {
  980. const bool isPCnote = m->IsPcNote();
  981. uint16 val = m->GetValueEffectCol();
  982. if(val > ModCommand::maxColumnValue) val = ModCommand::maxColumnValue;
  983. fx_col = row_col;
  984. if (!isPCnote && m->command != CMD_NONE && m->command < MAX_EFFECTS && (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_EFFECTHILIGHT))
  985. {
  986. if(effectColors[m->GetEffectType()] != 0)
  987. fx_col = effectColors[m->GetEffectType()];
  988. else if(m->command == CMD_DUMMY)
  989. fx_col = MODCOLOR_DUMMYCOMMAND;
  990. }
  991. if (!(dwSpeedUpMask & COLUMN_BITS_FXCMD))
  992. {
  993. tx_col = fx_col;
  994. bk_col = row_bkcol;
  995. if (col_sel & COLUMN_BITS_FXCMD)
  996. {
  997. tx_col = MODCOLOR_TEXTSELECTED;
  998. bk_col = MODCOLOR_BACKSELECTED;
  999. }
  1000. // Drawing Command
  1001. m_Dib.SetTextColor(tx_col, bk_col);
  1002. if(isPCnote)
  1003. {
  1004. m_Dib.TextBlt(xbmp + x, 0, 2, pfnt->spacingY, pfnt->nClrX+x, pfnt->nClrY, pfnt->dib);
  1005. m_Dib.TextBlt(xbmp + x + pfnt->pcValMargin, 0, pfnt->nEltWidths[3], m_szCell.cy, pfnt->nNumX, pfnt->nNumY+(val / 100)*pfnt->spacingY, pfnt->dib);
  1006. } else
  1007. {
  1008. if(m->command != CMD_NONE)
  1009. {
  1010. char n = sndFile.GetModSpecifications().GetEffectLetter(m->command);
  1011. MPT_ASSERT(n >= ' ');
  1012. DrawLetter(xbmp+x, 0, n, pfnt->nEltWidths[3], pfnt->nCmdOfs);
  1013. } else
  1014. {
  1015. m_Dib.TextBlt(xbmp+x, 0, pfnt->nEltWidths[3], pfnt->spacingY, pfnt->nClrX+x, pfnt->nClrY, pfnt->dib);
  1016. }
  1017. }
  1018. DrawPadding(m_Dib, pfnt, xbmp + x, 0, 3);
  1019. }
  1020. x += pfnt->nEltWidths[3];
  1021. // Param
  1022. if (!(dwSpeedUpMask & COLUMN_BITS_FXPARAM))
  1023. {
  1024. tx_col = fx_col;
  1025. bk_col = row_bkcol;
  1026. if (col_sel & COLUMN_BITS_FXPARAM)
  1027. {
  1028. tx_col = MODCOLOR_TEXTSELECTED;
  1029. bk_col = MODCOLOR_BACKSELECTED;
  1030. }
  1031. // Drawing param
  1032. m_Dib.SetTextColor(tx_col, bk_col);
  1033. if(isPCnote)
  1034. {
  1035. m_Dib.TextBlt(xbmp + x, 0, pfnt->nParamHiWidth, m_szCell.cy, pfnt->nNumX, pfnt->nNumY+((val / 10) % 10)*pfnt->spacingY, pfnt->dib);
  1036. m_Dib.TextBlt(xbmp + x + pfnt->nParamHiWidth, 0, pfnt->nEltWidths[4] - pfnt->padding[4] - pfnt->nParamHiWidth, m_szCell.cy, pfnt->nNumX+pfnt->paramLoMargin, pfnt->nNumY+(val % 10)*pfnt->spacingY, pfnt->dib);
  1037. }
  1038. else
  1039. {
  1040. if (m->command)
  1041. {
  1042. m_Dib.TextBlt(xbmp + x, 0, pfnt->nParamHiWidth, m_szCell.cy, pfnt->nNumX, pfnt->nNumY+(m->param >> 4)*pfnt->spacingY, pfnt->dib);
  1043. m_Dib.TextBlt(xbmp + x + pfnt->nParamHiWidth, 0, pfnt->nEltWidths[4] - pfnt->padding[4] - pfnt->nParamHiWidth, m_szCell.cy, pfnt->nNumX+pfnt->paramLoMargin, pfnt->nNumY+(m->param & 0x0F)*pfnt->spacingY, pfnt->dib);
  1044. } else
  1045. {
  1046. m_Dib.TextBlt(xbmp+x, 0, pfnt->nEltWidths[4], m_szCell.cy, pfnt->nClrX+x, pfnt->nClrY, pfnt->dib);
  1047. }
  1048. }
  1049. DrawPadding(m_Dib, pfnt, xbmp + x, 0, 4);
  1050. }
  1051. }
  1052. DoBlit:
  1053. nbmp++;
  1054. xbmp += nColumnWidth;
  1055. xpaint += nColumnWidth;
  1056. if ((xbmp + nColumnWidth >= (UINT)m_Dib.GetWidth()) || (xpaint >= rcClient.right)) break;
  1057. } while (++col < maxcol);
  1058. m_Dib.Blit(hdc, xpaint-xbmp, ypaint, xbmp, m_szCell.cy);
  1059. // skip row
  1060. ypaint += m_szCell.cy;
  1061. if (ypaint >= rcClient.bottom) break;
  1062. }
  1063. *pypaint = ypaint;
  1064. }
  1065. void CViewPattern::DrawChannelVUMeter(HDC hdc, int x, int y, UINT nChn)
  1066. {
  1067. if (ChnVUMeters[nChn] != OldVUMeters[nChn])
  1068. {
  1069. UINT vul, vur;
  1070. vul = (ChnVUMeters[nChn] & 0xFF00) >> 8;
  1071. vur = ChnVUMeters[nChn] & 0xFF;
  1072. vul /= 15;
  1073. vur /= 15;
  1074. if (vul > 8) vul = 8;
  1075. if (vur > 8) vur = 8;
  1076. x += (m_szCell.cx / 2);
  1077. const auto &channel = GetSoundFile()->m_PlayState.Chn[nChn];
  1078. const bool isSynth =
  1079. channel.dwFlags[CHN_ADLIB]
  1080. || (channel.pModSample != nullptr && channel.pModSample->uFlags[CHN_ADLIB])
  1081. || ((channel.pModSample == nullptr || !channel.pModSample->HasSampleData()) && channel.HasMIDIOutput());
  1082. const auto bmp = isSynth ? CMainFrame::bmpPluginVUMeters : CMainFrame::bmpVUMeters;
  1083. if (m_nDetailLevel <= PatternCursor::instrColumn)
  1084. {
  1085. DibBlt(hdc, x-VUMETERS_LOWIDTH-1, y, VUMETERS_LOWIDTH, VUMETERS_BMPHEIGHT,
  1086. VUMETERS_BMPWIDTH*2+VUMETERS_MEDWIDTH*2, vul * VUMETERS_BMPHEIGHT, bmp);
  1087. DibBlt(hdc, x-1, y, VUMETERS_LOWIDTH, VUMETERS_BMPHEIGHT,
  1088. VUMETERS_BMPWIDTH*2+VUMETERS_MEDWIDTH*2+VUMETERS_LOWIDTH, vur * VUMETERS_BMPHEIGHT, bmp);
  1089. } else
  1090. if (m_nDetailLevel <= PatternCursor::volumeColumn)
  1091. {
  1092. DibBlt(hdc, x - VUMETERS_MEDWIDTH-1, y, VUMETERS_MEDWIDTH, VUMETERS_BMPHEIGHT,
  1093. VUMETERS_BMPWIDTH*2, vul * VUMETERS_BMPHEIGHT, bmp);
  1094. DibBlt(hdc, x, y, VUMETERS_MEDWIDTH, VUMETERS_BMPHEIGHT,
  1095. VUMETERS_BMPWIDTH*2+VUMETERS_MEDWIDTH, vur * VUMETERS_BMPHEIGHT, bmp);
  1096. } else
  1097. {
  1098. DibBlt(hdc, x - VUMETERS_BMPWIDTH - 1, y, VUMETERS_BMPWIDTH, VUMETERS_BMPHEIGHT,
  1099. 0, vul * VUMETERS_BMPHEIGHT, bmp);
  1100. DibBlt(hdc, x + 1, y, VUMETERS_BMPWIDTH, VUMETERS_BMPHEIGHT,
  1101. VUMETERS_BMPWIDTH, vur * VUMETERS_BMPHEIGHT, bmp);
  1102. }
  1103. OldVUMeters[nChn] = ChnVUMeters[nChn];
  1104. }
  1105. }
  1106. // Draw an inverted border around the dragged selection.
  1107. void CViewPattern::DrawDragSel(HDC hdc)
  1108. {
  1109. const CSoundFile *pSndFile = GetSoundFile();
  1110. CRect rect;
  1111. int x1, y1, x2, y2;
  1112. int nChannels, nRows;
  1113. if(pSndFile == nullptr || !pSndFile->Patterns.IsValidPat(m_nPattern)) return;
  1114. // Compute relative movement
  1115. int dx = (int)m_DragPos.GetChannel() - (int)m_StartSel.GetChannel();
  1116. int dy = (int)m_DragPos.GetRow() - (int)m_StartSel.GetRow();
  1117. // Compute destination rect
  1118. PatternCursor begin(m_Selection.GetUpperLeft()), end(m_Selection.GetLowerRight());
  1119. // Check which selection lines need to be drawn.
  1120. bool drawLeft = ((int)begin.GetChannel() + dx >= GetXScrollPos());
  1121. bool drawRight = ((int)end.GetChannel() + dx < (int)pSndFile->GetNumChannels());
  1122. bool drawTop = ((int)begin.GetRow() + dy >= GetYScrollPos() - (int)m_nMidRow);
  1123. bool drawBottom = ((int)end.GetRow() + dy < (int)pSndFile->Patterns[m_nPattern].GetNumRows());
  1124. begin.Move(dy, dx, 0);
  1125. if(begin.GetChannel() >= pSndFile->GetNumChannels())
  1126. {
  1127. // Moved outside pattern range.
  1128. return;
  1129. }
  1130. end.Move(dy, dx, 0);
  1131. begin.Sanitize(pSndFile->Patterns[m_nPattern].GetNumRows(), pSndFile->GetNumChannels());
  1132. end.Sanitize(pSndFile->Patterns[m_nPattern].GetNumRows(), pSndFile->GetNumChannels());
  1133. // We need to know the first pixel that's not part of our rect anymore, so we extend the selection.
  1134. end.Move(1, 0, 1);
  1135. PatternRect destination(begin, end);
  1136. x1 = m_Selection.GetStartChannel();
  1137. y1 = m_Selection.GetStartRow();
  1138. x2 = m_Selection.GetEndChannel();
  1139. y2 = m_Selection.GetEndRow();
  1140. PatternCursor::Columns c1 = m_Selection.GetStartColumn();
  1141. PatternCursor::Columns c2 = m_Selection.GetEndColumn();
  1142. x1 += dx;
  1143. x2 += dx;
  1144. y1 += dy;
  1145. y2 += dy;
  1146. nChannels = pSndFile->m_nChannels;
  1147. nRows = pSndFile->Patterns[m_nPattern].GetNumRows();
  1148. if (x1 < GetXScrollPos()) drawLeft = false;
  1149. if (x1 >= nChannels) x1 = nChannels - 1;
  1150. if (x1 < 0) { x1 = 0; c1 = PatternCursor::firstColumn; drawLeft = false; }
  1151. if (x2 >= nChannels) { x2 = nChannels - 1; c2 = PatternCursor::lastColumn; drawRight = false; }
  1152. if (x2 < 0) x2 = 0;
  1153. if (y1 < GetYScrollPos() - (int)m_nMidRow) drawTop = false;
  1154. if (y1 >= nRows) y1 = nRows-1;
  1155. if (y1 < 0) { y1 = 0; drawTop = false; }
  1156. if (y2 >= nRows) { y2 = nRows-1; drawBottom = false; }
  1157. if (y2 < 0) y2 = 0;
  1158. POINT ptTopLeft = GetPointFromPosition(begin);
  1159. POINT ptBottomRight = GetPointFromPosition(end);
  1160. if ((ptTopLeft.x >= ptBottomRight.x) || (ptTopLeft.y >= ptBottomRight.y)) return;
  1161. if(end.GetColumnType() == PatternCursor::firstColumn)
  1162. {
  1163. // Special case: If selection ends on the last column of a channel, subtract the channel separator width.
  1164. ptBottomRight.x -= 4;
  1165. }
  1166. // invert the brush pattern (looks just like frame window sizing)
  1167. ::SetTextColor(hdc, RGB(255, 255, 255));
  1168. ::SetBkColor(hdc, RGB(0, 0, 0));
  1169. CBrush* pBrush = CDC::GetHalftoneBrush();
  1170. if (pBrush != NULL)
  1171. {
  1172. HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc, pBrush->m_hObject);
  1173. // Top
  1174. if (drawTop)
  1175. {
  1176. rect.SetRect(ptTopLeft.x + 4, ptTopLeft.y, ptBottomRight.x, ptTopLeft.y + 4);
  1177. if (!drawLeft) rect.left -= 4;
  1178. PatBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
  1179. }
  1180. // Bottom
  1181. if (drawBottom)
  1182. {
  1183. rect.SetRect(ptTopLeft.x, ptBottomRight.y - 4, ptBottomRight.x - 4, ptBottomRight.y);
  1184. if (!drawRight) rect.right += 4;
  1185. PatBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
  1186. }
  1187. // Left
  1188. if (drawLeft)
  1189. {
  1190. rect.SetRect(ptTopLeft.x, ptTopLeft.y, ptTopLeft.x + 4, ptBottomRight.y - 4);
  1191. if (!drawBottom) rect.bottom += 4;
  1192. PatBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
  1193. }
  1194. // Right
  1195. if (drawRight)
  1196. {
  1197. rect.SetRect(ptBottomRight.x - 4, ptTopLeft.y + 4, ptBottomRight.x, ptBottomRight.y);
  1198. if (!drawTop) rect.top -= 4;
  1199. PatBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
  1200. }
  1201. if (hOldBrush != NULL) SelectObject(hdc, hOldBrush);
  1202. }
  1203. }
  1204. void CViewPattern::OnDrawDragSel()
  1205. {
  1206. HDC hdc = ::GetDC(m_hWnd);
  1207. if (hdc != NULL)
  1208. {
  1209. DrawDragSel(hdc);
  1210. ::ReleaseDC(m_hWnd, hdc);
  1211. }
  1212. }
  1213. ///////////////////////////////////////////////////////////////////////////////
  1214. // CViewPattern Scrolling Functions
  1215. void CViewPattern::UpdateScrollSize()
  1216. {
  1217. const CSoundFile *pSndFile = GetSoundFile();
  1218. const CHANNELINDEX numChannels = pSndFile ? pSndFile->GetNumChannels() : 0;
  1219. const ROWINDEX numRows = (pSndFile && pSndFile->Patterns.IsValidPat(m_nPattern)) ? pSndFile->Patterns[m_nPattern].GetNumRows() : 0;
  1220. CRect rect;
  1221. SIZE sizeTotal, sizePage, sizeLine;
  1222. sizeTotal.cx = m_szHeader.cx + numChannels * m_szCell.cx;
  1223. sizeTotal.cy = m_szHeader.cy + numRows * m_szCell.cy;
  1224. sizeLine.cx = m_szCell.cx;
  1225. sizeLine.cy = m_szCell.cy;
  1226. sizePage.cx = sizeLine.cx * 2;
  1227. sizePage.cy = sizeLine.cy * 8;
  1228. GetClientRect(&rect);
  1229. m_nMidRow = 0;
  1230. if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_CENTERROW) m_nMidRow = (rect.Height() - m_szHeader.cy) / (m_szCell.cy * 2);
  1231. if (m_nMidRow) sizeTotal.cy += m_nMidRow * m_szCell.cy * 2;
  1232. SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
  1233. m_bWholePatternFitsOnScreen = (rect.Height() >= sizeTotal.cy);
  1234. if(m_bWholePatternFitsOnScreen)
  1235. m_nYScroll = 0;
  1236. }
  1237. void CViewPattern::UpdateScrollPos()
  1238. {
  1239. CRect rect;
  1240. GetClientRect(&rect);
  1241. int x = GetScrollPos(SB_HORZ);
  1242. if (x < 0) x = 0;
  1243. m_nXScroll = (x + m_szCell.cx - 1) / m_szCell.cx;
  1244. int y = GetScrollPos(SB_VERT);
  1245. if (y < 0) y = 0;
  1246. m_nYScroll = (y + m_szCell.cy - 1) / m_szCell.cy;
  1247. }
  1248. BOOL CViewPattern::OnScrollBy(CSize sizeScroll, BOOL bDoScroll)
  1249. {
  1250. int xOrig, xNew, x;
  1251. int yOrig, yNew, y;
  1252. // don't scroll if there is no valid scroll range (ie. no scroll bar)
  1253. CScrollBar* pBar;
  1254. DWORD dwStyle = GetStyle();
  1255. pBar = GetScrollBarCtrl(SB_VERT);
  1256. if ((pBar != NULL && !pBar->IsWindowEnabled()) ||
  1257. (pBar == NULL && !(dwStyle & WS_VSCROLL)))
  1258. {
  1259. // vertical scroll bar not enabled
  1260. sizeScroll.cy = 0;
  1261. }
  1262. pBar = GetScrollBarCtrl(SB_HORZ);
  1263. if ((pBar != NULL && !pBar->IsWindowEnabled()) ||
  1264. (pBar == NULL && !(dwStyle & WS_HSCROLL)))
  1265. {
  1266. // horizontal scroll bar not enabled
  1267. sizeScroll.cx = 0;
  1268. }
  1269. // adjust current x position
  1270. xOrig = x = GetScrollPos(SB_HORZ);
  1271. int xMax = GetScrollLimit(SB_HORZ);
  1272. x += sizeScroll.cx;
  1273. if (x < 0) x = 0; else if (x > xMax) x = xMax;
  1274. // adjust current y position
  1275. yOrig = y = GetScrollPos(SB_VERT);
  1276. int yMax = GetScrollLimit(SB_VERT);
  1277. y += sizeScroll.cy;
  1278. if (y < 0) y = 0; else if (y > yMax) y = yMax;
  1279. if (!bDoScroll) return TRUE;
  1280. xNew = x;
  1281. yNew = y;
  1282. if (x > 0) x = (x + m_szCell.cx - 1) / m_szCell.cx; else x = 0;
  1283. if (y > 0) y = (y + m_szCell.cy - 1) / m_szCell.cy; else y = 0;
  1284. if ((x != m_nXScroll) || (y != m_nYScroll))
  1285. {
  1286. CRect rect;
  1287. GetClientRect(&rect);
  1288. // HACK:
  1289. // Wine handles ScrollWindow completely synchronously (using RedrawWindow).
  1290. // This causes the window update region to be repainted immediately
  1291. // before and immediately after the actual copying of the scrolled rect.
  1292. // Async and sync window painting generally do not mix well at all
  1293. // (not even on native Windows) and this causes inevitable flickering
  1294. // on Wine.
  1295. // Instead, just invalidate the whole scrolled window area and let
  1296. // WM_PAINT handle the whole mess without ever scrolling any already
  1297. // painted contents. This causes additional CPU usage (on Wine) but
  1298. // avoids totally annoying and distracting flickering of the current-row-
  1299. // highlight.
  1300. if (x != m_nXScroll)
  1301. {
  1302. rect.left = m_szHeader.cx;
  1303. rect.top = 0;
  1304. if(TrackerSettings::Instance().patternAlwaysDrawWholePatternOnScrollSlow || mpt::OS::Windows::IsWine())
  1305. {
  1306. InvalidateRect(&rect, FALSE);
  1307. } else
  1308. {
  1309. ScrollWindow((m_nXScroll - x) * GetChannelWidth(), 0, &rect, &rect);
  1310. }
  1311. m_nXScroll = x;
  1312. }
  1313. if (y != m_nYScroll)
  1314. {
  1315. rect.left = 0;
  1316. rect.top = m_szHeader.cy;
  1317. if(TrackerSettings::Instance().patternAlwaysDrawWholePatternOnScrollSlow || mpt::OS::Windows::IsWine())
  1318. {
  1319. InvalidateRect(&rect, FALSE);
  1320. } else
  1321. {
  1322. ScrollWindow(0, (m_nYScroll - y) * GetRowHeight(), &rect, &rect);
  1323. }
  1324. m_nYScroll = y;
  1325. }
  1326. }
  1327. if (xNew != xOrig) SetScrollPos(SB_HORZ, xNew);
  1328. if (yNew != yOrig) SetScrollPos(SB_VERT, yNew);
  1329. return TRUE;
  1330. }
  1331. void CViewPattern::OnSize(UINT nType, int cx, int cy)
  1332. {
  1333. // Note: Switching between modules (when MDI childs are maximized) first calls this with the windowed size, then with the maximized size.
  1334. // Watch out for this odd behaviour when debugging this function.
  1335. CScrollView::OnSize(nType, cx, cy);
  1336. if (((nType == SIZE_RESTORED) || (nType == SIZE_MAXIMIZED)) && (cx > 0) && (cy > 0))
  1337. {
  1338. UpdateSizes();
  1339. UpdateScrollSize();
  1340. UpdateScrollPos();
  1341. m_Dib.SetSize(cx + m_szCell.cx, m_szCell.cy);
  1342. InvalidatePattern();
  1343. }
  1344. }
  1345. void CViewPattern::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1346. {
  1347. if (nSBCode == SB_THUMBTRACK) m_Status.set(psDragVScroll);
  1348. CModScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
  1349. if (nSBCode == SB_ENDSCROLL) m_Status.reset(psDragVScroll);
  1350. }
  1351. void CViewPattern::SetCurSel(PatternCursor beginSel, PatternCursor endSel)
  1352. {
  1353. RECT rect1, rect2, rect, rcInt, rcUni;
  1354. POINT pt;
  1355. // Get current selection area
  1356. PatternCursor endSel2(m_Selection.GetLowerRight());
  1357. endSel2.Move(1, 0, 1);
  1358. pt = GetPointFromPosition(m_Selection.GetUpperLeft());
  1359. rect1.left = pt.x;
  1360. rect1.top = pt.y;
  1361. pt = GetPointFromPosition(endSel2);
  1362. rect1.right = pt.x;
  1363. rect1.bottom = pt.y;
  1364. if(rect1.left < m_szHeader.cx) rect1.left = m_szHeader.cx;
  1365. if(rect1.top < m_szHeader.cy) rect1.top = m_szHeader.cy;
  1366. // Get new selection area
  1367. m_Selection = PatternRect(beginSel, endSel);
  1368. if(const CSoundFile *sndFile = GetSoundFile(); sndFile != nullptr && sndFile->Patterns.IsValidPat(m_nPattern))
  1369. {
  1370. m_Selection.Sanitize(sndFile->Patterns[m_nPattern].GetNumRows(), sndFile->GetNumChannels());
  1371. }
  1372. UpdateIndicator();
  1373. pt = GetPointFromPosition(m_Selection.GetUpperLeft());
  1374. rect2.left = pt.x;
  1375. rect2.top = pt.y;
  1376. endSel2.Set(m_Selection.GetLowerRight());
  1377. endSel2.Move(1, 0, 1);
  1378. pt = GetPointFromPosition(endSel2);
  1379. rect2.right = pt.x;
  1380. rect2.bottom = pt.y;
  1381. if (rect2.left < m_szHeader.cx) rect2.left = m_szHeader.cx;
  1382. if (rect2.top < m_szHeader.cy) rect2.top = m_szHeader.cy;
  1383. // Compute area for invalidation
  1384. IntersectRect(&rcInt, &rect1, &rect2);
  1385. UnionRect(&rcUni, &rect1, &rect2);
  1386. SubtractRect(&rect, &rcUni, &rcInt);
  1387. if ((rect.left == rcUni.left) && (rect.top == rcUni.top)
  1388. && (rect.right == rcUni.right) && (rect.bottom == rcUni.bottom))
  1389. {
  1390. InvalidateRect(&rect1, FALSE);
  1391. InvalidateRect(&rect2, FALSE);
  1392. } else
  1393. {
  1394. InvalidateRect(&rect, FALSE);
  1395. }
  1396. }
  1397. void CViewPattern::InvalidatePattern(bool invalidateChannelHeaders, bool invalidateRowHeaders)
  1398. {
  1399. CRect rect;
  1400. GetClientRect(&rect);
  1401. if(!invalidateChannelHeaders)
  1402. {
  1403. rect.top += m_szHeader.cy;
  1404. }
  1405. if(!invalidateRowHeaders)
  1406. {
  1407. rect.left += m_szHeader.cx;
  1408. }
  1409. InvalidateRect(&rect, FALSE);
  1410. SanitizeCursor();
  1411. }
  1412. void CViewPattern::InvalidateRow(ROWINDEX n)
  1413. {
  1414. const CSoundFile *pSndFile = GetSoundFile();
  1415. if(pSndFile && pSndFile->Patterns.IsValidPat(m_nPattern))
  1416. {
  1417. int yofs = GetYScrollPos() - m_nMidRow;
  1418. if (n == ROWINDEX_INVALID) n = GetCurrentRow();
  1419. if (((int)n < yofs) || (n >= pSndFile->Patterns[m_nPattern].GetNumRows())) return;
  1420. CRect rect;
  1421. GetClientRect(&rect);
  1422. rect.left = m_szHeader.cx;
  1423. rect.top = m_szHeader.cy - GetSmoothScrollOffset();
  1424. rect.top += (n - yofs) * m_szCell.cy;
  1425. rect.bottom = rect.top + m_szCell.cy;
  1426. InvalidateRect(&rect, FALSE);
  1427. }
  1428. }
  1429. void CViewPattern::InvalidateArea(PatternCursor begin, PatternCursor end)
  1430. {
  1431. RECT rect;
  1432. POINT pt;
  1433. pt = GetPointFromPosition(begin);
  1434. rect.left = pt.x;
  1435. rect.top = pt.y;
  1436. end.Move(1, 0, 1);
  1437. pt = GetPointFromPosition(end);
  1438. rect.right = pt.x;
  1439. rect.bottom = pt.y;
  1440. InvalidateRect(&rect, FALSE);
  1441. }
  1442. void CViewPattern::InvalidateCell(PatternCursor cursor)
  1443. {
  1444. cursor.RemoveColType();
  1445. InvalidateArea(cursor, PatternCursor(cursor.GetRow(), cursor.GetChannel(), PatternCursor::lastColumn));
  1446. }
  1447. void CViewPattern::InvalidateChannelsHeaders(CHANNELINDEX chn)
  1448. {
  1449. CRect rect;
  1450. GetClientRect(&rect);
  1451. rect.bottom = rect.top + m_szHeader.cy;
  1452. if(chn != CHANNELINDEX_INVALID)
  1453. {
  1454. rect.left = GetPointFromPosition(PatternCursor{ 0u, chn }).x;
  1455. rect.right = rect.left + GetChannelWidth();
  1456. }
  1457. InvalidateRect(&rect, FALSE);
  1458. }
  1459. void CViewPattern::UpdateIndicator(bool updateAccessibility)
  1460. {
  1461. const CSoundFile *sndFile = GetSoundFile();
  1462. CMainFrame *mainFrm = CMainFrame::GetMainFrame();
  1463. if(mainFrm == nullptr || sndFile == nullptr || !sndFile->Patterns.IsValidPat(m_nPattern))
  1464. return;
  1465. mainFrm->SetUserText(MPT_CFORMAT("Row {}, Col {}")(GetCurrentRow(), GetCurrentChannel() + 1));
  1466. if(::GetFocus() == m_hWnd)
  1467. {
  1468. const bool hasSelection = m_Selection.GetUpperLeft() != m_Selection.GetLowerRight();
  1469. if(hasSelection)
  1470. mainFrm->SetInfoText(MPT_CFORMAT("Selection: {} row{}, {} channel{}")(m_Selection.GetNumRows(), CString(m_Selection.GetNumRows() != 1 ? _T("s") : _T("")), m_Selection.GetNumChannels(), CString(m_Selection.GetNumChannels() != 1 ? _T("s") : _T(""))));
  1471. if(GetCurrentRow() < sndFile->Patterns[m_nPattern].GetNumRows() && m_Cursor.GetChannel() < sndFile->GetNumChannels())
  1472. {
  1473. if(!hasSelection)
  1474. mainFrm->SetInfoText(GetCursorDescription());
  1475. UpdateXInfoText();
  1476. }
  1477. if(updateAccessibility)
  1478. mainFrm->NotifyAccessibilityUpdate(*this);
  1479. }
  1480. }
  1481. CString CViewPattern::GetCursorDescription() const
  1482. {
  1483. const CSoundFile &sndFile = *GetSoundFile();
  1484. CString s;
  1485. if(!sndFile.Patterns.IsValidPat(m_nPattern))
  1486. {
  1487. return s;
  1488. }
  1489. ROWINDEX row = m_Cursor.GetRow();
  1490. CHANNELINDEX channel = m_Cursor.GetChannel();
  1491. const ModCommand *m = sndFile.Patterns[m_nPattern].GetpModCommand(row, channel);
  1492. switch(m_Cursor.GetColumnType())
  1493. {
  1494. case PatternCursor::noteColumn:
  1495. // display note
  1496. if(m->IsSpecialNote())
  1497. s = szSpecialNoteShortDesc[m->note - NOTE_MIN_SPECIAL];
  1498. else if(m->IsNote())
  1499. s = mpt::ToCString(sndFile.GetNoteName(m->note, m->instr));
  1500. break;
  1501. case PatternCursor::instrColumn:
  1502. // display instrument
  1503. if(m->instr)
  1504. {
  1505. s.Format(_T("%u: "), m->instr);
  1506. if(m->IsPcNote())
  1507. {
  1508. // display plugin name.
  1509. if(m->instr <= MAX_MIXPLUGINS)
  1510. {
  1511. s += mpt::ToCString(sndFile.m_MixPlugins[m->instr - 1].GetName());
  1512. }
  1513. } else
  1514. {
  1515. // "normal" instrument
  1516. if(sndFile.GetNumInstruments())
  1517. {
  1518. if((m->instr <= sndFile.GetNumInstruments()) && (sndFile.Instruments[m->instr]))
  1519. {
  1520. ModInstrument *pIns = sndFile.Instruments[m->instr];
  1521. s += mpt::ToCString(sndFile.GetCharsetInternal(), pIns->name);
  1522. if((m->note) && (m->note <= NOTE_MAX))
  1523. {
  1524. const SAMPLEINDEX nsmp = pIns->Keyboard[m->note - 1];
  1525. if((nsmp) && (nsmp <= sndFile.GetNumSamples()))
  1526. {
  1527. if(sndFile.m_szNames[nsmp][0])
  1528. {
  1529. s.AppendFormat(_T(" (%d: "), nsmp);
  1530. s += mpt::ToCString(sndFile.GetCharsetInternal(), sndFile.m_szNames[nsmp]);
  1531. s.AppendChar(_T(')'));
  1532. }
  1533. }
  1534. }
  1535. }
  1536. } else if(m->instr <= sndFile.GetNumSamples())
  1537. {
  1538. s += mpt::ToCString(sndFile.GetCharsetInternal(), sndFile.m_szNames[m->instr]);
  1539. }
  1540. }
  1541. }
  1542. break;
  1543. case PatternCursor::volumeColumn:
  1544. // display volume command
  1545. if(m->IsPcNote())
  1546. {
  1547. // display plugin param name.
  1548. if(m->instr > 0 && m->instr <= MAX_MIXPLUGINS)
  1549. {
  1550. const SNDMIXPLUGIN &plug = sndFile.m_MixPlugins[m->instr - 1];
  1551. if(plug.pMixPlugin != nullptr)
  1552. {
  1553. s = plug.pMixPlugin->GetFormattedParamName(m->GetValueVolCol());
  1554. }
  1555. }
  1556. } else if(m->volcmd != VOLCMD_NONE)
  1557. {
  1558. // "normal" volume command
  1559. EffectInfo effectInfo(sndFile);
  1560. effectInfo.GetVolCmdInfo(effectInfo.GetIndexFromVolCmd(m->volcmd), &s);
  1561. s += _T(": ");
  1562. CString tmp;
  1563. effectInfo.GetVolCmdParamInfo(*m, &tmp);
  1564. s += tmp;
  1565. }
  1566. break;
  1567. case PatternCursor::effectColumn:
  1568. case PatternCursor::paramColumn:
  1569. // display effect command
  1570. if(m->IsPcNote())
  1571. {
  1572. s.Format(_T("Parameter value: %u"), m->GetValueEffectCol());
  1573. } else if(m->command != CMD_NONE)
  1574. {
  1575. EffectInfo effectInfo(sndFile);
  1576. CString sztmp;
  1577. if(effectInfo.GetIndexFromEffect(m->command, m->param) >= 0)
  1578. {
  1579. UINT xParam = 0, xMultiplier = 1;
  1580. getXParam(m->command, m_nPattern, row, channel, sndFile, xParam, xMultiplier);
  1581. effectInfo.GetEffectNameEx(sztmp, *m, m->param * xMultiplier + xParam, channel);
  1582. }
  1583. //effectInfo.GetEffectName(sztmp, m->command, m->param, false, nChn);
  1584. if(!sztmp.IsEmpty())
  1585. {
  1586. s.Format(_T("%c%02X: "), sndFile.GetModSpecifications().GetEffectLetter(m->command), m->param);
  1587. s += sztmp;
  1588. }
  1589. }
  1590. break;
  1591. }
  1592. return s;
  1593. }
  1594. void CViewPattern::UpdateXInfoText()
  1595. {
  1596. const CSoundFile *sndFile = GetSoundFile();
  1597. CMainFrame *mainFrm = CMainFrame::GetMainFrame();
  1598. if(mainFrm == nullptr || sndFile == nullptr)
  1599. return;
  1600. CHANNELINDEX chn = GetCurrentChannel();
  1601. const auto &channel = sndFile->m_PlayState.Chn[chn];
  1602. CString xtraInfo;
  1603. xtraInfo.Format(_T("Chn:%d; Vol:%X; Mac:%X; Cut:%X%s; Res:%X; Pan:%X%s"),
  1604. chn + 1,
  1605. channel.nGlobalVol,
  1606. channel.nActiveMacro,
  1607. channel.nCutOff,
  1608. (channel.nFilterMode == FilterMode::HighPass) ? _T("-HP") : _T(""),
  1609. channel.nResonance,
  1610. channel.nPan,
  1611. channel.dwFlags[CHN_SURROUND] ? _T("-S") : _T(""));
  1612. mainFrm->SetXInfoText(xtraInfo);
  1613. }
  1614. void CViewPattern::UpdateAllVUMeters(Notification *pnotify)
  1615. {
  1616. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  1617. const CModDoc *pModDoc = GetDocument();
  1618. if ((!pModDoc) || (!pMainFrm)) return;
  1619. CRect rcClient;
  1620. GetClientRect(&rcClient);
  1621. int xofs = GetXScrollPos();
  1622. HDC hdc = ::GetDC(m_hWnd);
  1623. const bool isPlaying = (pMainFrm->GetFollowSong(pModDoc) == m_hWnd);
  1624. int x = m_szHeader.cx;
  1625. CHANNELINDEX nChn = static_cast<CHANNELINDEX>(xofs);
  1626. const int yPos = rcClient.top + MulDiv(COLHDR_HEIGHT, m_nDPIy, 96);
  1627. while ((nChn < pModDoc->GetNumChannels()) && (x < rcClient.right))
  1628. {
  1629. ChnVUMeters[nChn] = static_cast<uint16>(pnotify->pos[nChn]);
  1630. if ((!isPlaying) || pnotify->type[Notification::Stop]) ChnVUMeters[nChn] = 0;
  1631. DrawChannelVUMeter(hdc, x + 1, rcClient.top + yPos, nChn);
  1632. nChn++;
  1633. x += m_szCell.cx;
  1634. }
  1635. ::ReleaseDC(m_hWnd, hdc);
  1636. }
  1637. OPENMPT_NAMESPACE_END