Made it possible to do selection of rows and tracks (shift + arrow keys)

This commit is contained in:
Daniel Collin 2012-11-04 10:17:49 +01:00
parent 4015d13f40
commit ca73e5748a
4 changed files with 90 additions and 42 deletions

View File

@ -8,6 +8,7 @@
#include "LoadSave.h"
#include "TrackView.h"
#include "rlog.h"
#include "minmax.h"
#include "TrackData.h"
#include "RemoteConnection.h"
#include "MinecraftiaFont.h"
@ -149,10 +150,11 @@ static bool is_editing = false;
bool Editor_keyDown(int key, int modifiers)
{
bool handled_key = true;
TrackViewInfo* viewInfo = &s_editorData.trackViewInfo;
bool paused = RemoteConnection_isPaused();
struct sync_track** tracks = getTracks();
int active_track = getActiveTrack();
int row_pos = s_editorData.trackViewInfo.rowPos;
int row_pos = viewInfo->rowPos;
if (key == ' ')
{
@ -174,7 +176,16 @@ bool Editor_keyDown(int key, int modifiers)
int row = row_pos;
row += modifiers & EDITOR_KEY_ALT ? 8 : 1;
s_editorData.trackViewInfo.rowPos = row;
viewInfo->rowPos = row;
if (modifiers & EDITOR_KEY_SHIFT)
{
viewInfo->selectStopRow = row;
break;
}
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
viewInfo->selectStartTrack = viewInfo->selectStopTrack = active_track;
RemoteConnection_sendSetRowCommand(row);
@ -190,7 +201,16 @@ bool Editor_keyDown(int key, int modifiers)
if ((modifiers & EDITOR_KEY_COMMAND) || row < 0)
row = 0;
s_editorData.trackViewInfo.rowPos = row;
viewInfo->rowPos = row;
if (modifiers & EDITOR_KEY_SHIFT)
{
viewInfo->selectStopRow = row;
break;
}
viewInfo->selectStartRow = viewInfo->selectStopRow = row;
viewInfo->selectStartTrack = viewInfo->selectStopTrack = active_track;
RemoteConnection_sendSetRowCommand(row);
handled_key = true;
@ -207,6 +227,15 @@ bool Editor_keyDown(int key, int modifiers)
setActiveTrack(track < 0 ? 0 : track);
if (modifiers & EDITOR_KEY_SHIFT)
{
viewInfo->selectStopTrack = track;
break;
}
viewInfo->selectStartRow = viewInfo->selectStopRow = row_pos;
viewInfo->selectStartTrack = viewInfo->selectStopTrack = track;
handled_key = true;
break;
@ -225,6 +254,15 @@ bool Editor_keyDown(int key, int modifiers)
setActiveTrack(track);
if (modifiers & EDITOR_KEY_SHIFT)
{
viewInfo->selectStopTrack = track;
break;
}
viewInfo->selectStartRow = viewInfo->selectStopRow = row_pos;
viewInfo->selectStartTrack = viewInfo->selectStopTrack = track;
handled_key = true;
break;
@ -238,7 +276,7 @@ bool Editor_keyDown(int key, int modifiers)
if ((key >= '1' && key <= '9') && ((modifiers & EDITOR_KEY_CTRL) || (modifiers & EDITOR_KEY_ALT)))
{
struct sync_track* track = tracks[active_track];
int row = s_editorData.trackViewInfo.rowPos;
int row = viewInfo->rowPos;
float bias_value = 0.0f;
@ -310,7 +348,7 @@ bool Editor_keyDown(int key, int modifiers)
if (key == 'i')
{
struct sync_track* track = tracks[active_track];
int row = s_editorData.trackViewInfo.rowPos;
int row = viewInfo->rowPos;
int idx = key_idx_floor(track, row);
if (idx < 0)

View File

@ -5,6 +5,7 @@
#include <string.h>
#include "TrackData.h"
#include "rlog.h"
#include "minmax.h"
#include "../../sync/sync.h"
#include "../../sync/data.h"
#include "../../sync/track.h"
@ -52,7 +53,8 @@ static void printRowNumbers(int x, int y, int rowCount, int rowOffset, int rowSp
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int renderChannel(const TrackViewInfo* viewInfo, struct sync_track* track,
int startX, int startY, int startPos, int endPos, int endSizeY)
int startX, int startY, int startPos, int endPos, int endSizeY,
int trackId, int selectLeft, int selectRight, int selectTop, int selectBottom)
{
uint y;
int size = min_track_size;
@ -63,11 +65,8 @@ static int renderChannel(const TrackViewInfo* viewInfo, struct sync_track* track
int x_adjust = 0;
Emgui_setFont(viewInfo->smallFontId);
text_size = Emgui_getTextSize(track->name) + 4;
rlog(R_INFO, "t %s size %d\n", track->name, text_size);
// if text is smaller than min size we center the text
if (text_size < min_track_size)
@ -75,8 +74,6 @@ static int renderChannel(const TrackViewInfo* viewInfo, struct sync_track* track
else
size = text_size + 1;
rlog(R_INFO, "t %s size %d adjust %d\n", track->name, text_size, x_adjust);
Emgui_drawText(track->name, (startX + 3) + x_adjust, startY - 12, Emgui_color32(0xff, 0xff, 0xff, 0xff));
Emgui_setDefaultFont();
}
@ -135,16 +132,15 @@ static int renderChannel(const TrackViewInfo* viewInfo, struct sync_track* track
}
else
{
uint32_t color = 0;
if (y & 7)
color = Emgui_color32(0x4f, 0x4f, 0x4f, 0xff);
else
color = Emgui_color32(0x7f, 0x7f, 0x7f, 0xff);
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);
}
bool selected = (trackId >= selectLeft && trackId <= selectRight) && (y >= selectTop && y < selectBottom);
if (selected)
Emgui_fill(Emgui_color32(0x4f, 0x4f, 0x4f, 0x3f), startX, y_offset - font_size/2, size, font_size);
y_offset += font_size;
if (y_offset > (endSizeY + font_size/2))
@ -156,27 +152,6 @@ static int renderChannel(const TrackViewInfo* viewInfo, struct sync_track* track
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int doMax(int a, int b)
{
if (b >= a)
return b;
else
return a;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static inline int min(int a, int b)
{
if (a < b)
return a;
else
return b;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// foo
void TrackView_render(const TrackViewInfo* viewInfo, TrackData* trackData)
{
uint i = 0;
@ -198,12 +173,20 @@ void TrackView_render(const TrackViewInfo* viewInfo, TrackData* trackData)
if (syncData->num_tracks == 0)
{
renderChannel(0, 0, 40 + (i * 64), adjust_top_size, y_pos_row, y_pos_row + end_row, y_end_border);
renderChannel(0, 0, 40 + (i * 64), adjust_top_size, y_pos_row, y_pos_row + end_row, y_end_border,
0, 0, 0, 0, 0);
uint32_t color = Emgui_color32(127, 127, 127, 56);
Emgui_fill(color, 0, mid_screen_y + adjust_top_size, viewInfo->windowSizeX, font_size + 2);
return;
}
int selectLeft = mini(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
int selectRight = maxi(viewInfo->selectStartTrack, viewInfo->selectStopTrack);
int selectTop = mini(viewInfo->selectStartRow, viewInfo->selectStopRow);
int selectBottom = maxi(viewInfo->selectStartRow, viewInfo->selectStopRow);
rlog(R_INFO, "%d %d %d %d\n", selectLeft, selectRight, selectTop, selectBottom);
int num_tracks = syncData->num_tracks;
int max_render_tracks = viewInfo->windowSizeX / min_track_size;
@ -218,11 +201,12 @@ void TrackView_render(const TrackViewInfo* viewInfo, TrackData* trackData)
int x_pos = 40;
const int end_track = min(start_track + num_tracks, syncData->num_tracks);
const int end_track = mini(start_track + num_tracks, syncData->num_tracks);
for (i = start_track; i < end_track; ++i)
{
int size = renderChannel(viewInfo, syncData->tracks[i], x_pos, adjust_top_size, y_pos_row, y_pos_row + end_row, y_end_border);
int size = renderChannel(viewInfo, syncData->tracks[i], x_pos, adjust_top_size, y_pos_row, y_pos_row + end_row, y_end_border,
i, selectLeft, selectRight, selectTop, selectBottom);
if (sel_track == i)
{

View File

@ -12,6 +12,10 @@ typedef struct TrackViewInfo
int windowSizeY;
int rowPos;
int smallFontId;
int selectStartTrack;
int selectStopTrack;
int selectStartRow;
int selectStopRow;
} TrackViewInfo;

22
ogl_editor/src/minmax.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static inline int maxi(int a, int b)
{
if (a > b)
return a;
return b;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static inline int mini(int a, int b)
{
if (a < b)
return a;
return b;
}