Cleanup, split rendering into separate functions and preparation for folded rendering of tracks

This commit is contained in:
Daniel Collin 2012-11-10 18:28:31 +01:00
parent 177190d690
commit 2566d0eff5

View File

@ -11,6 +11,8 @@
#include "../../sync/track.h"
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;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -78,36 +80,13 @@ struct TrackInfo
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
static void renderTrackFolded(struct TrackInfo* info, int trackIndex)
static int renderTrackName(const struct TrackInfo* info, struct sync_track* track, int startX, bool folded)
{
}
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
static int renderChannel(const TrackViewInfo* viewInfo, struct sync_track* track, uint32_t color, int editRow,
int startX, int startY, int startPos, int endPos, int endSizeY,
int trackId, int selectLeft, int selectRight, int selectTop, int selectBottom)
*/
static int renderChannel(const struct TrackInfo* info, int startX, int editRow, int trackIndex)
{
int y, y_offset;
int size = min_track_size;
int startPos = info->startPos;
const int endPos = info->endPos;
uint32_t borderColor = Emgui_color32(40, 40, 40, 255);
struct sync_track* track = 0;
const uint32_t color = info->trackData->colors[trackIndex];
if (info->trackData->syncData.tracks)
track = info->trackData->syncData.tracks[trackIndex];
if (!track)
return folded ? track_size_folded : size;
if (track)
{
int text_size;
int x_adjust = 0;
@ -123,37 +102,17 @@ static int renderChannel(const struct TrackInfo* info, int startX, int editRow,
Emgui_drawText(track->name, (startX + 3) + x_adjust, info->startY - font_size * 2, Emgui_color32(0xff, 0xff, 0xff, 0xff));
Emgui_setDefaultFont();
}
Emgui_drawBorder(borderColor, borderColor, startX, info->startY - font_size * 4, size, info->endSizeY);
return size;
}
if (drawColorButton(color, startX + 4, info->startY - font_size * 3, size))
{
printf("Yah!\n");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
y_offset = info->startY;// + font_size / 2;
if (startPos < 0)
{
y_offset = info->startY + (font_size * -startPos);
startPos = 0;
}
y_offset += font_size / 2;
for (y = startPos; y < endPos; ++y)
{
int offset = startX + 6;
int idx = -1;
static void renderInterpolation(const struct TrackInfo* info, struct sync_track* track, int size, int idx, int x, int y, bool folded)
{
int fidx;
enum key_type interpolationType;
uint32_t color;
bool selected;
float value = 0.0f;
if (track)
idx = sync_find_key(track, y);
uint32_t color = 0;
// This is kinda crappy implementation as we will overdraw this quite a bit but might be fine
@ -170,34 +129,85 @@ static int renderChannel(const struct TrackInfo* info, int startX, int editRow,
}
if (info->viewInfo)
Emgui_fill(color, startX + (size - 4), y_offset - font_size / 2, 2, (info->endSizeY - y_offset) + font_size - 1);
Emgui_fill(color, x + (size - 4), y - font_size_half, 2, (info->endSizeY - y) + font_size - 1);
}
// Draw text if we have any
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void renderText(const struct TrackInfo* info, struct sync_track* track, int idx, int x, int y, bool editRow, bool folded)
{
if (idx >= 0)
{
char temp[256];
value = track->keys[idx].value;
float value = track->keys[idx].value;
snprintf(temp, 256, "% .2f", value);
if (y != editRow)
Emgui_drawText(temp, offset, y_offset - font_size / 2, Emgui_color32(255, 255, 255, 255));
if (!editRow)
Emgui_drawText(temp, x, y - font_size_half, Emgui_color32(255, 255, 255, 255));
}
else
{
uint32_t color = (y & 7) ? Emgui_color32(0x4f, 0x4f, 0x4f, 0xff) : Emgui_color32(0x7f, 0x7f, 0x7f, 0xff);
Emgui_drawText("---", offset, y_offset - font_size / 2, color);
Emgui_drawText("---", x, y - font_size_half, color);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderChannel(const struct TrackInfo* info, int startX, int editRow, int trackIndex)
{
int y, y_offset;
int size = min_track_size;
int startPos = info->startPos;
const int endPos = info->endPos;
uint32_t borderColor = Emgui_color32(40, 40, 40, 255);
struct sync_track* track = 0;
const uint32_t color = info->trackData->colors[trackIndex];
const bool folded = info->trackData->folded[trackIndex];
if (info->trackData->syncData.tracks)
track = info->trackData->syncData.tracks[trackIndex];
size = renderTrackName(info, track, startX, folded);
Emgui_drawBorder(borderColor, borderColor, startX, info->startY - font_size * 4, size, info->endSizeY);
if (drawColorButton(color, startX + 4, info->startY - font_size * 3, size))
{
printf("Yah!\n");
}
y_offset = info->startY;
if (startPos < 0)
{
y_offset = info->startY + (font_size * -startPos);
startPos = 0;
}
y_offset += font_size_half;
for (y = startPos; y < endPos; ++y)
{
int idx = -1;
int offset = startX + 6;
bool selected;
if (track)
idx = sync_find_key(track, y);
renderInterpolation(info, track, size, idx, offset, y_offset, folded);
renderText(info, track, idx, offset, y_offset, y == editRow, folded);
selected = (trackIndex >= info->selectLeft && trackIndex <= info->selectRight) &&
(y >= info->selectTop && y < info->selectBottom);
if (selected)
Emgui_fill(Emgui_color32(0x4f, 0x4f, 0x4f, 0x3f), startX, y_offset - font_size/2, size, font_size);
Emgui_fill(Emgui_color32(0x4f, 0x4f, 0x4f, 0x3f), startX, y_offset - font_size_half, size, font_size);
y_offset += font_size;
if (y_offset > (info->endSizeY + font_size/2))
if (y_offset > (info->endSizeY + font_size_half))
break;
}