[gnome-subtitles] Character count margins corrected



commit afdfaa7712710daefbb28846f52d3e3858e6db76
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Sun Jul 17 15:54:57 2011 +0100

    Character count margins corrected
    
    The margin now uses the specific Right window of the text view, which prevents
    flickering and other artifacts from appearing. No background needs to be drawn
    because this window doesn't paint a white background.

 src/Glade/MainWindow.glade                         |   20 ++++------
 .../Ui/Edit/SubtitleEditTextViewMargin.cs          |   40 +++++++++----------
 2 files changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/src/Glade/MainWindow.glade b/src/Glade/MainWindow.glade
index a8cfc86..3d20921 100644
--- a/src/Glade/MainWindow.glade
+++ b/src/Glade/MainWindow.glade
@@ -247,8 +247,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                         <signal name="activate" handler="OnEditRedo"/>
-                        <accelerator key="Y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="Y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -586,8 +586,8 @@
                         <property name="label" translatable="yes">Find Ne_xt</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindNext"/>
-                        <accelerator key="F3" signal="activate"/>
                         <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -597,8 +597,8 @@
                         <property name="label" translatable="yes">Find Pre_vious</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindPrevious"/>
-                        <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
                         <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -842,8 +842,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoPlayPause"/>
-                        <accelerator key="F5" signal="activate"/>
                         <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F5" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoPlayPauseImage">
                             <property name="visible">True</property>
@@ -870,8 +870,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoRewind"/>
-                        <accelerator key="F6" signal="activate"/>
                         <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F6" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoRewindImage">
                             <property name="visible">True</property>
@@ -889,8 +889,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoForward"/>
-                        <accelerator key="F7" signal="activate"/>
                         <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F7" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoForwardImage">
                             <property name="visible">True</property>
@@ -930,8 +930,8 @@
                         <property name="label" translatable="yes">Seek _to Selection</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSeekToSelection"/>
-                        <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -941,8 +941,8 @@
                         <property name="label" translatable="yes">Select Nearest Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSelectNearestSubtitle"/>
-                        <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -1921,8 +1921,6 @@ Shift+Plus/Minus (on the numpad) shifts timings.</property>
                             <property name="can_focus">True</property>
                             <property name="pixels_above_lines">5</property>
                             <property name="justification">center</property>
-                            <property name="left_margin">15</property>
-                            <property name="right_margin">15</property>
                             <property name="accepts_tab">False</property>
                           </widget>
                         </child>
@@ -1943,8 +1941,6 @@ Shift+Plus/Minus (on the numpad) shifts timings.</property>
                             <property name="can_focus">True</property>
                             <property name="pixels_above_lines">5</property>
                             <property name="justification">center</property>
-                            <property name="left_margin">15</property>
-                            <property name="right_margin">15</property>
                             <property name="accepts_tab">False</property>
                           </widget>
                         </child>
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextViewMargin.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextViewMargin.cs
index 4182805..3326893 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextViewMargin.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextViewMargin.cs
@@ -31,7 +31,6 @@ public class SubtitleEditTextViewMargin {
 	private int marginDigitCount = 2;
 	
 	/* Cached GCs and Pango Layout */
-	private Gdk.GC bgGC = null;
 	private Gdk.GC lineGC = null;
 	private Gdk.GC textGC = null;
 	private Pango.Layout textLayout = null;
@@ -47,22 +46,20 @@ public class SubtitleEditTextViewMargin {
 	
 	/* Private methods */
 	
-	public void DrawMargin (TextView textView, Gdk.Window window) {
+	public void DrawMargin (TextView textView) {
+	
     	/* Get char count info  */
     	int[,] info;
     	GetCharCountDrawInfo(textView, out info);
 
-    	/* Do some calculations */    	
-    	int marginNumbersWidth = marginDigitCount * this.marginCharWidth;
-    	int marginNumbersX = textView.Allocation.Width - this.marginSpace - marginNumbersWidth;
+    	/* Set margin and window */
+    	int marginWidth = (this.marginSpace * 2) + (this.marginDigitCount * this.marginCharWidth);
+    	textView.SetBorderWindowSize(TextWindowType.Right, marginWidth);
+    	Gdk.Window window = textView.GetWindow(TextWindowType.Right);
+    	window.Clear();
     	
     	/* Draw line */
-    	int marginWidth = (this.marginSpace * 2) + marginNumbersWidth;
-    	int marginLineX = textView.Allocation.Width - marginWidth;
-    	window.DrawLine(this.lineGC, marginLineX, 0, marginLineX, textView.Allocation.Height);
-    	
-    	/* Draw background area */
-    	window.DrawRectangle(this.bgGC, true, marginLineX+1, 0, marginWidth-1, textView.Allocation.Height);
+    	window.DrawLine(this.lineGC, 0, 0, 0, textView.Allocation.Height);
     	
     	/* Draw text */
     	int infoCount = info.GetLength(0);
@@ -73,7 +70,7 @@ public class SubtitleEditTextViewMargin {
     		this.textLayout.SetText(charCount.ToString());
     		int textLayoutWidth, textLayoutHeight;
     		this.textLayout.GetPixelSize(out textLayoutWidth, out textLayoutHeight);
-    		window.DrawLayout(this.textGC, marginNumbersX, y - textLayoutHeight/2, this.textLayout);
+    		window.DrawLayout(this.textGC, this.marginSpace, y - textLayoutHeight/2, this.textLayout);
 		}
     }
 
@@ -146,7 +143,6 @@ public class SubtitleEditTextViewMargin {
     }
     
     private void SetGCs () {
-    	this.bgGC = Base.Ui.Window.Style.BackgroundGC(StateType.Normal);
 		this.lineGC = Base.Ui.Window.Style.BackgroundGC(StateType.Active);
 		this.textGC = Base.Ui.Window.Style.TextGC(StateType.Active);
     }
@@ -159,7 +155,6 @@ public class SubtitleEditTextViewMargin {
 	/* Event members */
 	
 	private void OnBaseInitFinished () {
-	
 		/* GCs */
 		SetGCs();
 		
@@ -168,7 +163,7 @@ public class SubtitleEditTextViewMargin {
 		this.textLayout.FontDescription = Pango.FontDescription.FromString("sans 10");
 		
 		/* Margin char width */
-		this.textLayout.SetText("0");
+		this.textLayout.SetText("8"); //To calculate a character's width
 		int marginCharHeight;
 		this.textLayout.GetPixelSize(out this.marginCharWidth, out marginCharHeight);
 
@@ -176,20 +171,16 @@ public class SubtitleEditTextViewMargin {
 		textView.ExposeEvent += OnExposeEvent;
 		textView.Buffer.Changed += OnBufferChanged; //To calculate margin digit count (based on the largest line char count)
 		textView.StyleSet += OnStyleSet; //To update colors if the style is changed
-		textView.Parent.ExposeEvent += OnScrolledWindowExposeEvent;
+		textView.StateChanged += OnStateChanged;
 	}
 	
 	private void OnExposeEvent (object o, ExposeEventArgs args) {
 		TextView textView = o as TextView;
 		if (textView.State != StateType.Insensitive) {
-			DrawMargin(textView, args.Event.Window);
+			DrawMargin(textView);
 		}
 	}
 	
-	private void OnScrolledWindowExposeEvent (object o, ExposeEventArgs args) {
-		Refresh(); //Necessary for artifacts not to appear when scrolling
-	}
-	
 	private void OnBufferChanged (object o, EventArgs args) {
 		this.marginDigitCount = CalcDigitCount(o as TextBuffer, this.marginMinDigits);
 	}
@@ -197,6 +188,13 @@ public class SubtitleEditTextViewMargin {
 	private void OnStyleSet (object o, StyleSetArgs args) {
 		SetGCs();
 	}
+	
+	private void OnStateChanged (object o, StateChangedArgs args) {
+		TextView textView = o as TextView;
+		if (textView.State == StateType.Insensitive) {
+			textView.SetBorderWindowSize(TextWindowType.Right, 0); //Don't show the margin if the text view is insensitive
+		}
+	}
 
 	
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]