Added grid key handling

Originally committed to SVN as r105.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-22 02:25:45 +00:00
parent 0c3b724c31
commit 5d490b988f
5 changed files with 117 additions and 6 deletions

View File

@ -49,6 +49,7 @@
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "frame_main.h" #include "frame_main.h"
#include "video_display.h" #include "video_display.h"
#include "video_slider.h"
/////////////// ///////////////
@ -59,6 +60,7 @@ BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wx
// Misc variables // Misc variables
lastRow = -1; lastRow = -1;
yPos = 0; yPos = 0;
extendRow = -1;
bmp = NULL; bmp = NULL;
holding = false; holding = false;
@ -135,12 +137,12 @@ void BaseGrid::EndBatch() {
////////////////////// //////////////////////
// Makes cell visible // Makes cell visible
void BaseGrid::MakeCellVisible(int row, int col) { void BaseGrid::MakeCellVisible(int row, int col,bool center) {
// Get size // Get size
int w = 0; int w = 0;
int h = 0; int h = 0;
GetClientSize(&w,&h); GetClientSize(&w,&h);
bool forceCenter = true; bool forceCenter = !center;
// Get min and max visible // Get min and max visible
int minVis = yPos+1; int minVis = yPos+1;
@ -148,7 +150,14 @@ void BaseGrid::MakeCellVisible(int row, int col) {
// Make visible // Make visible
if (forceCenter || row < minVis || row > maxVis) { if (forceCenter || row < minVis || row > maxVis) {
ScrollTo(row - h/lineHeight/2 + 1); if (center) {
ScrollTo(row - h/lineHeight/2 + 1);
}
else {
if (row < minVis) ScrollTo(row - 1);
if (row > maxVis) ScrollTo(row - h/lineHeight + 3);
}
} }
} }
@ -212,6 +221,7 @@ BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
EVT_SIZE(BaseGrid::OnSize) EVT_SIZE(BaseGrid::OnSize)
EVT_COMMAND_SCROLL(GRID_SCROLLBAR,BaseGrid::OnScroll) EVT_COMMAND_SCROLL(GRID_SCROLLBAR,BaseGrid::OnScroll)
EVT_MOUSE_EVENTS(BaseGrid::OnMouseEvent) EVT_MOUSE_EVENTS(BaseGrid::OnMouseEvent)
EVT_KEY_DOWN(BaseGrid::OnKeyPress)
END_EVENT_TABLE() END_EVENT_TABLE()
@ -512,6 +522,13 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
bool validRow = row >= 0 && row < GetRows(); bool validRow = row >= 0 && row < GetRows();
if (!validRow) row = -1; if (!validRow) row = -1;
// Get focus
if (event.ButtonDown()) {
if (Options.AsBool(_T("Grid Allow Focus"))) {
SetFocus();
}
}
// Click type // Click type
if (click && !holding && validRow) { if (click && !holding && validRow) {
holding = true; holding = true;
@ -537,6 +554,9 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
// Click // Click
if ((click || holding) && validRow) { if ((click || holding) && validRow) {
// Disable extending
extendRow = -1;
// Toggle selected // Toggle selected
if (click && ctrl && !shift && !alt) { if (click && ctrl && !shift && !alt) {
SelectRow(row,true,!IsInSelection(row,0)); SelectRow(row,true,!IsInSelection(row,0));
@ -803,3 +823,84 @@ void BaseGrid::UpdateMaps() {
// Refresh // Refresh
Refresh(false); Refresh(false);
} }
/////////////
// Key press
void BaseGrid::OnKeyPress(wxKeyEvent &event) {
int key = event.KeyCode();
// Left/right, forward to seek bar if video is loaded
if (key == WXK_LEFT || key == WXK_RIGHT) {
if (video->loaded) {
video->ControlSlider->SetFocus();
video->ControlSlider->AddPendingEvent(event);
return;
}
event.Skip();
return;
}
// Up/down
int dir = 0;
if (key == WXK_UP) dir = -1;
if (key == WXK_DOWN) dir = 1;
// Moving
if (dir) {
// Modifiers
bool ctrl = event.m_controlDown;
bool alt = event.m_altDown;
bool shift = event.m_shiftDown;
// Move selection
if (!ctrl && !shift && !alt) {
int next = editBox->linen+dir;
editBox->SetToLine(next);
SelectRow(next);
MakeCellVisible(next,0,false);
extendRow = -1;
return;
}
// Move active only
if (alt && !shift && !ctrl) {
int next = editBox->linen+dir;
editBox->SetToLine(next);
Refresh(false);
MakeCellVisible(next,0,false);
extendRow = -1;
return;
}
// Add to selection
if (shift && !ctrl && !alt) {
if (extendRow == -1) {
extendRow = editBox->linen+dir;
extendRow = MID(0,extendRow,GetRows());
SelectRow(extendRow,true);
}
else {
// Add
if ((extendRow > editBox->linen && dir == 1) || (extendRow < editBox->linen && dir == -1) || extendRow == editBox->linen) {
extendRow += dir;
extendRow = MID(0,extendRow,GetRows());
SelectRow(extendRow,true);
}
// Remove (moving back)
else {
SelectRow(extendRow,true,false);
extendRow += dir;
extendRow = MID(0,extendRow,GetRows());
}
}
MakeCellVisible(extendRow,0,false);
return;
}
}
event.Skip();
}

View File

@ -62,6 +62,7 @@ private:
int lineHeight; int lineHeight;
int colWidth[16]; int colWidth[16];
int lastRow; int lastRow;
int extendRow;
bool holding; bool holding;
wxFont font; wxFont font;
wxScrollBar *scrollBar; wxScrollBar *scrollBar;
@ -71,6 +72,7 @@ private:
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
void OnScroll(wxScrollEvent &event); void OnScroll(wxScrollEvent &event);
void OnMouseEvent(wxMouseEvent &event); void OnMouseEvent(wxMouseEvent &event);
void OnKeyPress(wxKeyEvent &event);
void DrawImage(wxDC &dc); void DrawImage(wxDC &dc);
@ -93,7 +95,7 @@ public:
void SetColumnWidths(); void SetColumnWidths();
void BeginBatch(); void BeginBatch();
void EndBatch(); void EndBatch();
void MakeCellVisible(int row, int col); void MakeCellVisible(int row, int col,bool center=true);
void SelectRow(int row, bool addToSelected = false, bool select=true); void SelectRow(int row, bool addToSelected = false, bool select=true);
void ClearSelection(); void ClearSelection();

View File

@ -21,7 +21,7 @@ Please visit http://aegisub.net to download latest version
- 1,1+2 recombining lines where 1 is a substring of 2 no longer causes incorrect behavior. 1+2,2 similarly fixed. This fix also gives more sanity-checking in the recombining (jfs) - 1,1+2 recombining lines where 1 is a substring of 2 no longer causes incorrect behavior. 1+2,2 similarly fixed. This fix also gives more sanity-checking in the recombining (jfs)
- Replaced the subtitles grid with a custom control, which should hopefully behave and look better. (AMZ) Changes are: - Replaced the subtitles grid with a custom control, which should hopefully behave and look better. (AMZ) Changes are:
o Currently active line is now highlighted with a border. o Currently active line is now highlighted with a border.
o The grid can no longer receive focus. o The grid can optionally no longer receive focus (this behavior is disabled by default, change "Grid Allow Focus" to 0 in config.dat to prevent it from getting focus).
o Fixed bug related to tag cycling, which would reset grid, move video and force a refresh of everything (slow, and could undo uncommited changes). o Fixed bug related to tag cycling, which would reset grid, move video and force a refresh of everything (slow, and could undo uncommited changes).
o Rows colliding with the currently active one will now be highlighted in grid. o Rows colliding with the currently active one will now be highlighted in grid.
o Selected comments are now highlighted in a different color. o Selected comments are now highlighted in a different color.
@ -38,7 +38,7 @@ Please visit http://aegisub.net to download latest version
- Implemented Redo. (AMZ) - Implemented Redo. (AMZ)
- Fonts collector will now default collection to same folder as script (Set to "?script" on config.dat). (AMZ) - Fonts collector will now default collection to same folder as script (Set to "?script" on config.dat). (AMZ)
- Alt+Left/Right on the video seek bar will now seek by increments of 10 frames (increment is customizeable in config.dat). (AMZ) - Alt+Left/Right on the video seek bar will now seek by increments of 10 frames (increment is customizeable in config.dat). (AMZ)
- Added a simple audio resync method afor video playback. (AMZ) - Added a simple audio resync method for video playback. (AMZ)
- Audio timing will now apply to all selected lines, as well as active line. (AMZ) - Audio timing will now apply to all selected lines, as well as active line. (AMZ)
- Added a volume slider bar to audio mode. (AMZ) - Added a volume slider bar to audio mode. (AMZ)
- Fixed some internal workings, which should make Aegisub use considerably less RAM (especially for large Karaoke files, 3-4x less RAM usage was measured with a 9 MB file). (AMZ) - Fixed some internal workings, which should make Aegisub use considerably less RAM (especially for large Karaoke files, 3-4x less RAM usage was measured with a 9 MB file). (AMZ)

View File

@ -144,6 +144,7 @@ void OptionsManager::LoadDefaults() {
wchar_t temp = 0x2600; wchar_t temp = 0x2600;
SetText(_T("Grid hide overrides char"),temp); SetText(_T("Grid hide overrides char"),temp);
SetInt(_T("Grid font size"),8); SetInt(_T("Grid font size"),8);
SetBool(_T("Grid allow focus"),true);
SetBool(_T("Highlight subs in frame"),true); SetBool(_T("Highlight subs in frame"),true);

View File

@ -373,6 +373,13 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
} }
} }
// Forward up/down to grid
if (key == WXK_UP || key == WXK_DOWN) {
grid->AddPendingEvent(event);
grid->SetFocus();
return;
}
event.Skip(); event.Skip();
} }