Browse files

Finished adding a horizontal scrollbar to the UndoHistory control.

  • Loading branch information...
1 parent a152435 commit 51680efae5db6e9c5b4871dd83467976d4c18b1d @ajpalkovic ajpalkovic committed Feb 8, 2010
Showing with 22 additions and 57 deletions.
  1. +5 −4 src/UndoHistory.cpp
  2. +16 −52 src/VersionTree.cpp
  3. +1 −1 src/VersionTree.h
View
9 src/UndoHistory.cpp 100644 → 100755
@@ -168,13 +168,15 @@ void UndoHistory::DrawLayout(wxDC& dc) {
m_treeWidth = m_pTree->GetWidth();
wxRect rect;
+ //If an image is moved both horizontally and vertically, then there is no way to capture the area to be redrawn in a single rectangle.
+ //So, this optimization is only used if the vertical scrollbar is used.
if (m_isScrolling) {
// If there is overlap, then move the image
if (m_verticalScrollPos + size.y > m_oldVerticalScrollPos && m_verticalScrollPos < m_oldVerticalScrollPos + size.y) {
const int top = wxMax(m_verticalScrollPos, m_oldVerticalScrollPos);
const int bottom = wxMin(m_verticalScrollPos, m_oldVerticalScrollPos) + size.y;
const int overlap_height = bottom - top;
- m_mdc.Blit(m_horizontalScrollPos, (top - m_oldVerticalScrollPos) + (m_oldVerticalScrollPos - m_verticalScrollPos), size.x, overlap_height, &m_mdc, 0, top - m_oldVerticalScrollPos);
+ m_mdc.Blit(m_horizontalScrollPos, (top - m_oldVerticalScrollPos) + (m_oldVerticalScrollPos - m_verticalScrollPos), size.x, overlap_height, &m_mdc, m_horizontalScrollPos, top - m_oldVerticalScrollPos);
const int new_height = size.y - overlap_height;
const int newtop = (top == m_verticalScrollPos) ? bottom : m_verticalScrollPos;
@@ -223,8 +225,7 @@ void UndoHistory::DrawLayout(wxDC& dc) {
// Resize & scroll the versiontree
const wxSize treesize = m_pTree->GetBestSize();
m_pTree->SetSize(wxSize(treesize.x, size.y));
- m_pTree->ScrollVertical(m_verticalScrollPos);
- m_pTree->ScrollHorizontal(m_horizontalScrollPos);
+ m_pTree->Scroll(m_horizontalScrollPos, m_verticalScrollPos);
// Calculate visible node-range
const int topnode = rect.y ? (rect.y-1) / (m_lineHeight) : 0;
@@ -477,7 +478,7 @@ void UndoHistory::OnScroll(wxScrollWinEvent& event) {
if (pos != m_horizontalScrollPos) {
m_oldHorizontalScrollPos = m_horizontalScrollPos;
m_horizontalScrollPos = pos;
- m_isScrolling = true;
+ m_isScrolling = false;
wxClientDC dc(this);
DrawLayout(dc);
View
68 src/VersionTree.cpp 100644 → 100755
@@ -269,70 +269,34 @@ void VersionTree::UpdateTree() {
}
void VersionTree::ScrollVertical(int pos) {
- if (pos == verticalScrollPos) return;
+ Scroll(horizontalScrollPos, pos);
+}
+
+void VersionTree::Scroll(int xpos, int ypos) {
+ if(xpos == horizontalScrollPos && ypos == verticalScrollPos) return;
const wxSize size = GetClientSize();
wxRect rect;
- if (needRedrawing) {
- verticalScrollPos = pos;
- rect = wxRect(horizontalScrollPos,verticalScrollPos,size.x,size.y);
- }
- else {
+ rect = wxRect(xpos,ypos,size.x,size.y);
+ //If the user scrolls horizontally, then we just do a full redraw. There is no way to shift the image both left and up and then do a redraw on a six sided region.
+ if (!needRedrawing && xpos == horizontalScrollPos) {
// If there is overlap, then move the image
- if (pos + size.y > verticalScrollPos && pos < verticalScrollPos + size.y) {
- const int top = wxMax(pos, verticalScrollPos);
- const int bottom = wxMin(pos, verticalScrollPos) + size.y;
+ if (ypos + size.y > verticalScrollPos && ypos < verticalScrollPos + size.y) {
+ const int top = wxMax(ypos, verticalScrollPos);
+ const int bottom = wxMin(ypos, verticalScrollPos) + size.y;
const int overlap_height = bottom - top;
- mdc.Blit(horizontalScrollPos, (top - verticalScrollPos) + (verticalScrollPos - pos), size.x, overlap_height, &mdc, 0, top - verticalScrollPos);
+ mdc.Blit(0, (top - verticalScrollPos) + (verticalScrollPos - ypos), treeWidth, overlap_height, &mdc, 0, top - verticalScrollPos);
const int new_height = size.y - overlap_height;
- const int newtop = (top == pos) ? bottom : pos;
- verticalScrollPos = pos;
+ const int newtop = (top == ypos) ? bottom : ypos;
rect = wxRect(horizontalScrollPos,newtop,size.x,new_height);
}
- else {
- verticalScrollPos = pos;
- rect = wxRect(horizontalScrollPos,verticalScrollPos,size.x,size.y);
- }
+
}
- DrawTree(rect);
-
- // Copy updated MemoryDC to Display
- wxClientDC dc(this);
- dc.Blit(0, 0, size.x, size.y, &mdc, 0, 0);
-
- needRedrawing = false;
-}
+ verticalScrollPos = ypos;
+ horizontalScrollPos = xpos;
-void VersionTree::ScrollHorizontal(int pos) {
- if (pos == horizontalScrollPos) return;
-
- const wxSize size = GetClientSize();
- wxRect rect;
-
- if (needRedrawing) {
- horizontalScrollPos = pos;
- rect = wxRect(horizontalScrollPos,verticalScrollPos,size.x,size.y);
- }
- else {
- // If there is overlap, then move the image
- if (pos + size.x > horizontalScrollPos && pos < horizontalScrollPos + size.x) {
- const int left = wxMax(pos, horizontalScrollPos);
- const int right = wxMin(pos, horizontalScrollPos) + size.x;
- const int overlap_width = right - left;
- mdc.Blit((left - horizontalScrollPos) + (horizontalScrollPos - pos), verticalScrollPos, overlap_width, size.y, &mdc, left-horizontalScrollPos, verticalScrollPos);
-
- const int new_width = size.y - overlap_width;
- const int newleft = (left == pos) ? right : pos;
- horizontalScrollPos = pos;
- rect = wxRect(newleft, verticalScrollPos, new_width, size.y);
- }
- else {
- horizontalScrollPos = pos;
- rect = wxRect(horizontalScrollPos,verticalScrollPos,size.x,size.y);
- }
- }
DrawTree(rect);
// Copy updated MemoryDC to Display
View
2 src/VersionTree.h 100644 → 100755
@@ -36,7 +36,7 @@ class VersionTree : public wxControl {
void MakeNodeVisible(size_t node_id, bool doCenter=false);
void ScrollVertical(int pos);
- void ScrollHorizontal(int pos);
+ void Scroll(int xpos, int ypos);
int GetVerticalScrollPos() const {return verticalScrollPos;};
int GetHorizontalScrollPos() const {return horizontalScrollPos;};
void UpdateTree();

0 comments on commit 51680ef

Please sign in to comment.