From f7984f0d1d7ca9d919facbe3a40fb08afbd38b6a Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sun, 25 Nov 2012 11:01:07 +0100 Subject: [PATCH] Added color selection for tracks Closes #26 --- ogl_editor/src/TrackView.c | 19 ++++++-- ogl_editor/src/macosx/FileDialog.m | 88 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/ogl_editor/src/TrackView.c b/ogl_editor/src/TrackView.c index 25f730e..6b4b6f7 100644 --- a/ogl_editor/src/TrackView.c +++ b/ogl_editor/src/TrackView.c @@ -31,6 +31,7 @@ struct TrackInfo { TrackViewInfo* viewInfo; TrackData* trackData; + char* editText; int selectLeft; int selectRight; int selectTop; @@ -42,6 +43,8 @@ struct TrackInfo int midPos; }; +extern void Dialog_showColorPicker(uint32_t* color); + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void TrackView_init() @@ -194,8 +197,7 @@ static void renderText(const struct TrackInfo* info, struct sync_track* track, i float value = track->keys[idx].value; snprintf(temp, 256, "% .2f", value); - if (!editRow) - Emgui_drawText(temp, x, y - font_size_half, Emgui_color32(255, 255, 255, 255)); + Emgui_drawText(temp, x, y - font_size_half, Emgui_color32(255, 255, 255, 255)); } else { @@ -288,7 +290,10 @@ static int renderChannel(struct TrackInfo* info, int startX, int editRow, Track* if (drawColorButton(color, startX + 4, info->startY - colorbar_adjust, size)) { - printf("Yah!\n"); + Dialog_showColorPicker(&trackData->color); + + if (trackData->color != color) + s_needsUpdate = true; } } @@ -332,7 +337,9 @@ static int renderChannel(struct TrackInfo* info, int startX, int editRow, Track* idx = sync_find_key(track, y); renderInterpolation(info, track, size, idx, offset, y_offset, folded); - renderText(info, track, y, idx, offset, y_offset, y == editRow, folded); + + if (!(trackData->selected && info->viewInfo->rowPos == y && info->editText)) + renderText(info, track, y, idx, offset, y_offset, y == editRow, folded); selected = (trackIndex >= info->selectLeft && trackIndex <= info->selectRight) && (y >= info->selectTop && y < info->selectBottom); @@ -351,6 +358,9 @@ static int renderChannel(struct TrackInfo* info, int startX, int editRow, Track* if (trackData->selected) { Emgui_fill(trackData->group->folded ? dark_active_track_color : active_track_color, startX, info->midPos, size, font_size + 1); + + if (info->editText) + Emgui_drawText(info->editText, startX + 2, info->midPos, Emgui_color32(255, 255, 255, 255)); } } @@ -442,6 +452,7 @@ void renderGroups(TrackViewInfo* viewInfo, TrackData* trackData) // Shared info for all tracks + info.editText = trackData->editText; info.selectLeft = emini(viewInfo->selectStartTrack, viewInfo->selectStopTrack); info.selectRight = emaxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack); info.selectTop = emini(viewInfo->selectStartRow, viewInfo->selectStopRow); diff --git a/ogl_editor/src/macosx/FileDialog.m b/ogl_editor/src/macosx/FileDialog.m index 8973e1f..608658c 100644 --- a/ogl_editor/src/macosx/FileDialog.m +++ b/ogl_editor/src/macosx/FileDialog.m @@ -1,4 +1,5 @@ #include "../Dialog.h" +#include #import /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -51,3 +52,90 @@ int Dialog_save(char* dest) return true; } + +@interface ColorDelegate : NSObject +{ + bool m_bIsClosed; +} + +// Delegate methods +- (id)init; +- (BOOL)windowShouldClose:(id)sender; +- (BOOL)isClosed; +@end + +@implementation ColorDelegate : NSObject + +- (id)init +{ + [super init]; + m_bIsClosed = false; + + return self; +} + +- (BOOL)windowShouldClose:(id)sender +{ + (void)sender; + + m_bIsClosed = true; + + [NSApp abortModal]; + [NSApp stopModal]; + return YES; +} + +- (BOOL)isClosed +{ + return m_bIsClosed; +} + +@end + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void Dialog_showColorPicker(uint32_t* color) +{ + uint32_t c = *color; + + NSAutoreleasePool *thePool; + thePool = [[NSAutoreleasePool alloc] init]; + + //Get the shared color and font panel + [[NSColorPanel sharedColorPanel] setColor: + [NSColor colorWithCalibratedRed:(CGFloat) (Emgui_color32_getR(c) / 255.0) + green:(CGFloat) (Emgui_color32_getG(c) / 255.0) + blue:(CGFloat) (Emgui_color32_getB(c) / 255.0) + alpha:(CGFloat) 1.0]]; + + NSColorPanel* theColorPanel = [NSColorPanel sharedColorPanel]; + + //Create and assign the delegates (cocoa event handlers) so + //we can tell if a window has closed/open or not + ColorDelegate* colorDelegate = [[ColorDelegate alloc] init]; + [theColorPanel setDelegate:colorDelegate]; + NSModalSession session = [NSApp beginModalSessionForWindow:theColorPanel]; + for (;;) + { + [NSApp runModalSession:session]; + + //If the color panel is closed, return the font panel modal loop + if ([colorDelegate isClosed]) + break; + } + [NSApp endModalSession:session]; + + [theColorPanel setDelegate:nil]; + [colorDelegate release]; + + //Get the shared color panel along with the chosen color and set the chosen color + NSColor* theColor = [[theColorPanel color] colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; + + *color = Emgui_color32((unsigned char) ([theColor redComponent] * 255.0), + (unsigned char) ([theColor greenComponent] * 255.0), + (unsigned char) ([theColor blueComponent] * 255.0), + 255); + + [thePool release]; +} +