Improved group rendering and made some cleanup

This commit is contained in:
Daniel Collin 2012-11-12 21:35:53 +01:00
parent 65b6b3a3e9
commit db839cd75c
3 changed files with 103 additions and 7 deletions

View File

@ -35,6 +35,7 @@ typedef struct Track
typedef struct Group
{
const char* name;
bool folded;
union
{
Track* track;

View File

@ -15,6 +15,8 @@ const int font_size = 8;
const int font_size_half = font_size / 2;
const int track_size_folded = 20;
const int min_track_size = 100;
const int colorbar_adjust = ((font_size * 3) + 2);
static const int name_adjust = font_size * 2;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -81,6 +83,45 @@ struct TrackInfo
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderName(const char* name, int x, int y, int minSize, bool folded)
{
int size = min_track_size;
int text_size;
int x_adjust = 0;
int spacing = folded ? 0 : 30;
text_size = (Emgui_getTextSize(name) & 0xffff) + spacing;
if (text_size < minSize)
x_adjust = (minSize - text_size) / 2;
else
size = text_size + 1;
if (folded)
{
Emgui_drawTextFlipped(name, x, y + text_size, Emgui_color32(0xff, 0xff, 0xff, 0xff));
size = text_size;
}
else
{
Emgui_drawText(name, x + x_adjust + 16, y, Emgui_color32(0xff, 0xff, 0xff, 0xff));
}
return size;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderGroupHeader(Group* group, int x, int y, int groupSize)
{
drawColorButton(Emgui_color32(127, 127, 127, 255), x + 3, y - colorbar_adjust, groupSize);
renderName(group->name, x, y - name_adjust, groupSize, group->folded);
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderTrackName(const struct TrackInfo* info, struct sync_track* track, int startX, bool folded)
{
int size = min_track_size;
@ -108,7 +149,7 @@ static int renderTrackName(const struct TrackInfo* info, struct sync_track* trac
}
else
{
Emgui_drawText(track->name, (startX + 3) + x_adjust + 16, info->startY - font_size * 2, Emgui_color32(0xff, 0xff, 0xff, 0xff));
Emgui_drawText(track->name, (startX + 3) + x_adjust + 16, info->startY - name_adjust, Emgui_color32(0xff, 0xff, 0xff, 0xff));
}
Emgui_setDefaultFont();
@ -175,6 +216,30 @@ static void renderText(const struct TrackInfo* info, struct sync_track* track, i
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int getTrackSize(TrackData* trackData, Track* track)
{
if (track->folded)
return track_size_folded;
// TODO: Need to verify that this is correct
return (Emgui_getTextSize(trackData->syncData.tracks[track->index]->name) & 0xffff) + 31;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int getGroupSize(TrackData* trackData, Group* group)
{
int i, size = 0, count = group->trackCount;
for (i = 0; i < count; ++i)
size += getTrackSize(trackData, group->t.tracks[i]);
return size;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderChannel(struct TrackInfo* info, int startX, int editRow, Track* trackData)
{
int y, y_offset;
@ -208,7 +273,7 @@ static int renderChannel(struct TrackInfo* info, int startX, int editRow, Track*
Emgui_drawBorder(borderColor, borderColor, startX, info->startY - font_size * 4, size, info->endSizeY);
if (drawColorButton(color, startX + 4, info->startY - ((font_size * 3) + 2), size))
if (drawColorButton(color, startX + 4, info->startY - colorbar_adjust, size))
{
printf("Yah!\n");
}
@ -265,6 +330,37 @@ static int renderChannel(struct TrackInfo* info, int startX, int editRow, Track*
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderGroup(Group* group, int posX, struct TrackInfo* info, TrackData* trackData)
{
int i, size, track_count = group->trackCount;
int oldY = info->startY;
Emgui_setFont(info->viewInfo->smallFontId);
size = getGroupSize(trackData, group);
printf("size %d\n", size);
// TODO: Draw the group name and such here
renderGroupHeader(group, posX, oldY, size);
// ----
info->startY += 40;
for (i = 0; i < track_count; ++i)
posX += renderChannel(info, posX, -1, group->t.tracks[i]);
info->startY = oldY;
Emgui_setDefaultFont();
return size;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void renderGroups(TrackViewInfo* viewInfo, TrackData* trackData)
{
struct TrackInfo info;
@ -326,10 +422,9 @@ void renderGroups(TrackViewInfo* viewInfo, TrackData* trackData)
}
else
{
size = renderGroup(group, x_pos, &info, trackData);
}
x_pos += size;
if (x_pos >= viewInfo->windowSizeX)

View File

@ -68,7 +68,7 @@ static void parseXml(mxml_node_t* rootNode, TrackData* trackData)
const char* folded_text = mxmlElementGetAttr(node, "folded");
track_index = TrackData_createGetTrack(trackData, track_name);
printf("track_index %d\n", track_index);
//printf("track_index %d\n", track_index);
t = &trackData->tracks[track_index];
track = trackData->syncData.tracks[track_index];
@ -102,7 +102,7 @@ static void parseXml(mxml_node_t* rootNode, TrackData* trackData)
track->keys = 0;
track->num_keys = 0;
printf("Creating track/channel with name %s\n", track_name);
//printf("Creating track/channel with name %s\n", track_name);
}
else if (!strcmp("key", element_name))
{
@ -121,7 +121,7 @@ static void parseXml(mxml_node_t* rootNode, TrackData* trackData)
assert(!is_key);
sync_set_key(track, &k);
printf("Adding key: row %s | value %s | interpolation %s\n", row, value, interpolation);
//printf("Adding key: row %s | value %s | interpolation %s\n", row, value, interpolation);
}
}