Date: prev next · Thread: first prev next last
2010 Archives by date, by thread · List index


Hello Jonas, 
I think the patch looks great, I've pushed it... But when we need to
draw a thin solid line under the visual line that the caret is in, we
will probably need to pass a boolean value to SmCursor::Draw in
SmGraphicWindow::Paint and from SmCursor::Draw to
SmCaretDrawingVisitor... So that only the vertical line blinks, but
the solid underline of the visual line doesn't blink...
This is as opposed to not calling SmCursor::Draw in
SmGraphicWindow::Paint which is what currently happens...

Thanks very much for your help in pointing me in the right direction for
this.

I've attempted the other easy hack, this information meant I didn't have
to spend any time working out what to do.
I made a couple of methods for SmGraphicWindow, IsLineVisible and
ShowLine. I made them public, as I would imagine they would be used for
number 7 of the complex and non-essential tasks on the todo list.

By the way, I think that it's really cool that you found the setting
for the caret blink timer... Nice work!
That was all thanks to opengrok.go-oo.org (thanks for pointing that out
to me).


Regards,
Luke 
From 1bbb3fab0d224a6cae86dfdd0caf37056ddcf76c Mon Sep 17 00:00:00 2001
From: Luke Dixon <6b8b4567@gmail.com>
Date: Tue, 16 Nov 2010 23:37:09 +0000
Subject: [PATCH] Draw a visible line under the current line in the visual formula editor.

---
 starmath/inc/cursor.hxx      |    2 +-
 starmath/inc/view.hxx        |    6 ++++--
 starmath/inc/visitors.hxx    |    3 ++-
 starmath/source/cursor.cxx   |    4 ++--
 starmath/source/view.cxx     |   14 ++++++++++++--
 starmath/source/visitors.cxx |   38 +++++++++++++++++++++++++++++---------
 6 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/starmath/inc/cursor.hxx b/starmath/inc/cursor.hxx
index 7c4fa85..139d5c4 100644
--- a/starmath/inc/cursor.hxx
+++ b/starmath/inc/cursor.hxx
@@ -226,7 +226,7 @@ public:
     static SmNode* FindTopMostNodeInLine(SmNode* pSNode, bool MoveUpIfSelected = false);
 
     /** Draw the caret */
-    void Draw(OutputDevice& pDev, Point Offset);
+    void Draw(OutputDevice& pDev, Point Offset, bool isCaretVisible);
 
 private:
     friend class SmDocShell;
diff --git a/starmath/inc/view.hxx b/starmath/inc/view.hxx
index cbaf501..e5899ce 100644
--- a/starmath/inc/view.hxx
+++ b/starmath/inc/view.hxx
@@ -57,11 +57,13 @@ class SmGraphicWindow : public ScrollableWindow
     // old style editing pieces
     Rectangle aCursorRect;
     bool      bIsCursorVisible;
-
-    AutoTimer     aCaretBlinkTimer;
+    bool      bIsLineVisible;
+    AutoTimer aCaretBlinkTimer;
 public:
     bool IsCursorVisible() const { return bIsCursorVisible; }
     void ShowCursor(bool bShow);
+    bool IsLineVisible() const { return bIsLineVisible; }
+    void ShowLine(bool bShow);
     const SmNode * SetCursorPos(USHORT nRow, USHORT nCol);
 protected:
     void               SetIsCursorVisible(bool bVis) { bIsCursorVisible = bVis; }
diff --git a/starmath/inc/visitors.hxx b/starmath/inc/visitors.hxx
index 2b89b6f..cff09dc 100644
--- a/starmath/inc/visitors.hxx
+++ b/starmath/inc/visitors.hxx
@@ -152,13 +152,14 @@ class SmCaretDrawingVisitor : public SmDefaultingVisitor
 {
 public:
     /** Given position and device this constructor will draw the caret */
-    SmCaretDrawingVisitor( OutputDevice& rDevice, SmCaretPos position, Point offset );
+    SmCaretDrawingVisitor( OutputDevice& rDevice, SmCaretPos position, Point offset, bool 
caretVisible );
     void Visit( SmTextNode* pNode );
 private:
     OutputDevice &rDev;
     SmCaretPos pos;
     /** Offset to draw from */
     Point Offset;
+    bool isCaretVisible;
 protected:
     /** Default method for drawing pNodes */
     void DefaultVisit( SmNode* pNode );
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index 948a02b..1219595 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -180,8 +180,8 @@ void SmCursor::AnnotateSelection(){
     SmSetSelectionVisitor(anchor->CaretPos, position->CaretPos, pTree);
 }
 
-void SmCursor::Draw(OutputDevice& pDev, Point Offset){
-    SmCaretDrawingVisitor(pDev, GetPosition(), Offset);
+void SmCursor::Draw(OutputDevice& pDev, Point Offset, bool isCaretVisible){
+    SmCaretDrawingVisitor(pDev, GetPosition(), Offset, isCaretVisible);
 }
 
 void SmCursor::Delete(){
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 6d2752d..75871e6 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -116,6 +116,7 @@ SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
     SetHelpId(HID_SMA_WIN_DOCUMENT);
     SetUniqueId(HID_SMA_WIN_DOCUMENT);
 
+    ShowLine(false);
     CaretBlinkInit();
 }
 
@@ -224,6 +225,7 @@ void SmGraphicWindow::GetFocus()
     //Let view shell know what insertions should be done in visual editor
     pViewShell->SetInsertIntoEditWindow(false);
     SetIsCursorVisible(true);
+    ShowLine(true);
     CaretBlinkStart();
     RepaintViewShellDoc();
 }
@@ -242,6 +244,7 @@ void SmGraphicWindow::LoseFocus()
     if (!IsInlineEditEnabled())
         return;
     SetIsCursorVisible(false);
+    ShowLine(false);
     CaretBlinkStop();
     RepaintViewShellDoc();
 }
@@ -299,6 +302,13 @@ void SmGraphicWindow::ShowCursor(bool bShow)
     SetIsCursorVisible(bShow);
 }
 
+void SmGraphicWindow::ShowLine(bool bShow)
+{
+    if (!IsInlineEditEnabled())
+        return;
+
+    bIsLineVisible = bShow;
+}
 
 void SmGraphicWindow::SetCursor(const SmNode *pNode)
 {
@@ -371,8 +381,8 @@ void SmGraphicWindow::Paint(const Rectangle&)
     SetFormulaDrawPos(aPoint);
     if(IsInlineEditEnabled()) {
         //Draw cursor if any...
-        if(pViewShell->GetDoc()->HasCursor() && IsCursorVisible())
-            pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint);
+        if(pViewShell->GetDoc()->HasCursor() && IsLineVisible())
+            pViewShell->GetDoc()->GetCursor().Draw(*this, aPoint, IsCursorVisible());
     } else {
     SetIsCursorVisible(false); // (old) cursor must be drawn again
 
diff --git a/starmath/source/visitors.cxx b/starmath/source/visitors.cxx
index 8f69b2e..6ca86fd 100644
--- a/starmath/source/visitors.cxx
+++ b/starmath/source/visitors.cxx
@@ -339,11 +339,13 @@ void SmDefaultingVisitor::Visit( SmVerticalBraceNode* pNode )
 
 SmCaretDrawingVisitor::SmCaretDrawingVisitor( OutputDevice& rDevice,
                                              SmCaretPos position,
-                                             Point offset )
+                                             Point offset,
+                                             bool caretVisible )
  : rDev( rDevice )
 {
     pos = position;
     Offset = offset;
+    isCaretVisible = caretVisible;
     j_assert( position.IsValid( ), "Cannot draw invalid position!" );
     if( !position.IsValid( ) )
         return;
@@ -369,14 +371,23 @@ void SmCaretDrawingVisitor::Visit( SmTextNode* pNode )
     long left = pNode->GetLeft( ) + rDev.GetTextWidth( pNode->GetText( ), 0, i ) + Offset.X( );
     long top = pLine->GetTop( ) + Offset.Y( );
     long height = pLine->GetHeight( );
+    long left_line = pLine->GetLeft( ) + Offset.X( );
+    long right_line = pLine->GetRight( ) + Offset.X( );
 
     //Set color
     rDev.SetLineColor( Color( COL_BLACK ) );
 
-    //Draw vertical line
-    Point p1( left, top );
-    Point p2( left, top + height );
-    rDev.DrawLine( p1, p2 );
+    if ( isCaretVisible ) {
+        //Draw vertical line
+        Point p1( left, top );
+        Point p2( left, top + height );
+        rDev.DrawLine( p1, p2 );
+    }
+
+    //Underline the line
+    Point pLeft( left_line, top + height );
+    Point pRight( right_line, top + height );
+    rDev.DrawLine( pLeft, pRight );
 }
 
 void SmCaretDrawingVisitor::DefaultVisit( SmNode* pNode )
@@ -390,14 +401,23 @@ void SmCaretDrawingVisitor::DefaultVisit( SmNode* pNode )
     long left = pNode->GetLeft( ) + Offset.X( ) + ( pos.Index == 1 ? pNode->GetWidth( ) : 0 );
     long top = pLine->GetTop( ) + Offset.Y( );
     long height = pLine->GetHeight( );
+    long left_line = pLine->GetLeft( ) + Offset.X( );
+    long right_line = pLine->GetRight( ) + Offset.X( );
 
     //Set color
     rDev.SetLineColor( Color( COL_BLACK ) );
 
-    //Draw vertical line
-    Point p1( left, top );
-    Point p2( left, top + height );
-    rDev.DrawLine( p1, p2 );
+    if ( isCaretVisible ) {
+        //Draw vertical line
+        Point p1( left, top );
+        Point p2( left, top + height );
+        rDev.DrawLine( p1, p2 );
+    }
+
+    //Underline the line
+    Point pLeft( left_line, top + height );
+    Point pRight( right_line, top + height );
+    rDev.DrawLine( pLeft, pRight );
 }
 
 /////////////////////////////// SmCaretPos2LineVisitor ////////////////////////////////
-- 
1.7.3.2


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.