Skip to content

Commit

Permalink
Add OSX SetMenuItemSwatch Fixes reaper-oss#533
Browse files Browse the repository at this point in the history
  • Loading branch information
swstim committed Mar 28, 2017
1 parent 5885d86 commit d62ba16
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
22 changes: 20 additions & 2 deletions Color/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,10 +1108,10 @@ static void menuhook(const char* menustr, HMENU hMenu, int flag)
else
AddSubMenu(hMenu, hSubMenu, __LOCALIZE("SWS item color","sws_menu"), 40707);
}
#ifdef _WIN32
else if (flag == 1)
{ // Update the color swatches
// Color commands can be anywhere on the menu, so find 'em no matter where
#ifdef _WIN32
static WDL_PtrList<void> pBitmaps;
HDC hdcScreen = NULL;
HDC hDC = NULL;
Expand Down Expand Up @@ -1166,8 +1166,26 @@ static void menuhook(const char* menustr, HMENU hMenu, int flag)
DeleteDC(hDC);
if (hdcScreen)
DeleteDC(hdcScreen);
}
#else
UpdateCustomColors();

int iCommand1 = SWSGetCommandID(TrackCustCol, 0);
int iCommand2 = SWSGetCommandID(ItemCustCol, 0);

for (int i = 0; i < 32; i++)
{
int iPos;
HMENU h;
if (i < 16)
h = FindMenuItem(hMenu, iCommand1 + i, &iPos);
else
h = FindMenuItem(hMenu, iCommand2 + i - 16, &iPos);

if (h)
SetMenuItemSwatch(h, iPos, 12, g_custColors[i % 16]);
}
#endif
}
}

int ColorInit()
Expand Down
1 change: 1 addition & 0 deletions sws_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ HCURSOR SWS_LoadCursor(int id);
void mouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo);
BOOL IsWindowEnabled(HWND hwnd);
int GetMenuString(HMENU hMenu, UINT uIDItem, char* lpString, int nMaxCount, UINT uFlag);
void SetMenuItemSwatch(HMENU hMenu, UINT pos, int size, COLORREF color);
#endif

// Command/action handling, sws_extension.cpp
Expand Down
19 changes: 18 additions & 1 deletion sws_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,21 @@ void SWS_ShowTextScrollbar(HWND hwnd, bool show)
[sc setHasHorizontalScroller:show?YES:NO];
}


void SetMenuItemSwatch(HMENU hMenu, UINT pos, int iSize, COLORREF color)
{
if (!hMenu) return;
NSMenu *m=(NSMenu *)hMenu;
NSMenuItem *item = [m itemAtIndex:pos];
NSSize size = NSMakeSize(iSize, iSize);

if (!item)
return;
if (!item.image)
item.image = [[NSImage alloc] initWithSize:(NSSize)size];

NSColor *nscolor = [NSColor colorWithCalibratedRed:GetRValue(color)/255.0f green:GetGValue(color)/255.0f blue:GetBValue(color)/255.0f alpha:1.0f];
[item.image lockFocus];
[nscolor set];
NSRectFill(NSMakeRect(0, 0, size.width, size.height));
[item.image unlockFocus];
}
1 change: 1 addition & 0 deletions whatsnew.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Fixes
+Issue 533: Add custom color swatches to OSX "Set custom color" menu items
+Issue 811: Fix "Xenakios/SWS: Reposition selected items" on OSX
+Issue 839: "Remove all automation envelopes for selected tracks" now removes Trim Volume.
+Issue 843: Fix snapshots with complicated sets of sends not being saved/replicated properly
Expand Down

0 comments on commit d62ba16

Please sign in to comment.