Commit 0d99494
New tab bar
Changed files (11)
modifiedbirdfont/GtkWindow.valamodifiedgraphics/tools_and_buttons.svgmodifiedicons/tab1_left.pngmodifiedicons/tab1_right.pngmodifiedicons/tab2_left.pngmodifiedicons/tab2_right.pngmodifiedicons/tab3_left.pngmodifiedicons/tab3_right.pngmodifiedlibbirdfont/Renderer/Text.valamodifiedlibbirdfont/Renderer/TextTab.valamodifiedlibbirdfont/TabBar.vala
Diff
@@ -1095,7 +1095,7 @@ class TabbarCanvas : DrawingArea { queue_draw_area (x, y, w, h); }); - set_size_request (20, 33);+ set_size_request (20, 38); } }@@ -1206,9 +1206,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2"- inkscape:zoom="2.8284271"- inkscape:cx="129.29434"- inkscape:cy="720.06113"+ inkscape:zoom="6.250608"+ inkscape:cx="294.83826"+ inkscape:cy="593.47879" inkscape:current-layer="layer1" inkscape:document-units="px" showgrid="false"@@ -3624,5 +3624,48 @@ sodipodi:ry="18.070375" d="m 219.00678,133.99237 a 15.290318,18.070375 0 1 1 -30.58064,0 15.290318,18.070375 0 1 1 30.58064,0 z" transform="matrix(0.39792146,0,0,0.03494084,148.58689,59.804985)" />+ <image+ y="0.6927166"+ x="404.71494"+ id="image3518"+ xlink:href="file:///home/johan/H%C3%A4mtningar/BF_CharacterSet_Dark.jpg"+ height="738"+ width="909" />+ <rect+ style="opacity:0.98000004;color:#000000;fill:#ea4d1a;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.75199997;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"+ id="rect3521"+ width="5.4599066"+ height="38.8801"+ x="270.5"+ y="134.5" />+ <rect+ style="opacity:0.98000004;color:#000000;fill:#464d53;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.75199997;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"+ id="rect3523"+ width="1.8100172"+ height="38.902409"+ x="270.37643"+ y="134.53888" />+ <g+ id="g4318"+ inkscape:export-filename="/home/johan/birdfont/icons/tab3_right.png"+ inkscape:export-xdpi="320"+ inkscape:export-ydpi="320">+ <rect+ transform="scale(-1,1)"+ y="134.50909"+ x="-284.88071"+ height="38.8801"+ width="4.5"+ id="rect3521-8"+ style="opacity:0.98000004;color:#000000;fill:#ea4d1a;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.75199997;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />+ <rect+ transform="scale(-1,1)"+ y="134.54797"+ x="-285.00427"+ height="38.902409"+ width="1.8100172"+ id="rect3523-6"+ style="opacity:0.98000004;color:#000000;fill:#464d53;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.75199997;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />+ </g> </g> </svg>Binary files a/icons/tab1_left.png and b/icons/tab1_left.png differBinary files a/icons/tab1_right.png and b/icons/tab1_right.png differBinary files a/icons/tab2_left.png and b/icons/tab2_left.png differBinary files a/icons/tab2_right.png and b/icons/tab2_right.png differBinary files a/icons/tab3_left.png and b/icons/tab3_left.png differBinary files a/icons/tab3_right.png and b/icons/tab3_right.png differ@@ -18,16 +18,33 @@ namespace BirdFont { /** Test implementation of a birdfont rendering engine. */ public class Text {++ Font font {+ get {+ if (current_font == null) {+ current_font = new Font ();+ if (!load_font ("testfont.bf")) {+ current_font = new Font ();+ }+ }+ + return (!) current_font;+ }+ + set {+ current_font = value;+ }+ } FontCache font_cache;- Font font;+ Font? current_font; string text; GlyphSequence glyph_sequence; double line_gap = 20; public delegate void Iterator (Glyph glyph, double kerning); public Text () {- font = new Font ();+ current_font = null; text = ""; glyph_sequence = new GlyphSequence (); font_cache = FontCache.get_default_cache ();@@ -99,7 +116,7 @@ public class Text { } } - public double get_max_extent_x (double font_size_in_pixels) {+ public double get_extent (double font_size_in_pixels) { double x = 0; double ratio = font_size_in_pixels / get_row_height (); @@ -120,7 +137,7 @@ public class Text { return f != null; } - public void draw (Context cr, int px, int py, int width, int height, double font_size_in_pixels) {+ public void draw (Context cr, double px, double py, double font_size_in_pixels) { double x, y; double row_height, ratio; @@ -129,7 +146,7 @@ public class Text { cr.save (); - y = get_row_height () + font.base_line + py;+ y = ratio * (get_row_height () + font.base_line) + py; x = px; iterate ((glyph, kerning) => {@@ -25,11 +25,9 @@ public class TextTab : FontDisplay { public TextTab () { text_area = new Text ();- text_area.load_font ("testfont.bf"); text_area.set_text ("Test"); text_area2 = new Text ();- text_area2.load_font ("testfont.bf"); text_area2.set_text ("Birdfont ÅÄÖ"); text_area3 = new Text ();@@ -38,9 +36,9 @@ public class TextTab : FontDisplay { } public override void draw (WidgetAllocation allocation, Context cr) { - text_area.draw (cr, 0, 0, 200, 200, 16);- text_area2.draw (cr, 0, 100, 200, 200, 16);- text_area3.draw (cr, 0, 200, 200, 200, 16);+ text_area.draw (cr, 0, 0, 16);+ text_area2.draw (cr, 0, 100, 16);+ text_area3.draw (cr, 0, 200, 16); } } @@ -38,15 +38,6 @@ public class TabBar : GLib.Object { Tab? previous_tab = null; Tab? current_tab = null;-- ImageSurface? tab1_left = null;- ImageSurface? tab1_right = null;-- ImageSurface? tab2_left = null;- ImageSurface? tab2_right = null;-- ImageSurface? tab3_left = null;- ImageSurface? tab3_right = null; ImageSurface? progress = null; @@ -60,22 +51,13 @@ public class TabBar : GLib.Object { bool processing = false; double wheel_rotation = 0; - double background_r = 230 /255.0;- double background_g = 229 /255.0;- double background_b = 228 /255.0;+ double background_r = 51 /255.0;+ double background_g = 54 /255.0;+ double background_b = 59 /255.0; public TabBar () { tabs = new Gee.ArrayList<Tab> ();- - tab1_left = Icons.get_icon ("tab1_left.png");- tab1_right = Icons.get_icon ("tab1_right.png"); - tab2_left = Icons.get_icon ("tab2_left.png");- tab2_right = Icons.get_icon ("tab2_right.png");-- tab3_left = Icons.get_icon ("tab3_left.png");- tab3_right = Icons.get_icon ("tab3_right.png");- next_tab = Icons.get_icon ("next_tab.png"); to_previous_tab = Icons.get_icon ("previous_tab.png"); @@ -95,14 +77,10 @@ public class TabBar : GLib.Object { private void over_close (double x, double y, out int over, out int over_close_tab) { int i = 0;- double offset = 19;- double edge;+ double offset = 0;+ bool close_y, close_x; - return_if_fail (tab3_right != null);- - edge = ((!)tab3_right).get_width () * scale;- - if (x < 19 && has_scroll ()) {+ if (x < 24 && has_scroll ()) { over_close_tab = NO_TAB; over = PREVIOUS_TAB; return;@@ -134,10 +112,12 @@ public class TabBar : GLib.Object { continue; } - if (offset < x < offset + t.get_width () + edge) {+ if (offset < x < offset + t.get_width ()) { over = i; - if (height - 18 < y < height - 5 && x > offset + t.get_width () - 19) {+ close_y = height / 2.0 - 4 < y < height / 2.0 + 4;+ close_x = x > offset + t.get_width () - 16;+ if (close_y && close_x) { over_close_tab = i; } else { over_close_tab = NO_TAB;@@ -146,7 +126,7 @@ public class TabBar : GLib.Object { return; } - offset += t.get_width () + ((!)tab1_right).get_width () * scale;+ offset += t.get_width (); i++; } @@ -446,8 +426,6 @@ public class TabBar : GLib.Object { double offset = 19; double end = (has_progress_wheel ()) ? width - 28 : width - 19; - return_if_fail (tab1_right != null);- if (first_tab > 0) { return true; }@@ -462,7 +440,7 @@ public class TabBar : GLib.Object { return true; } - offset += t.get_width () + ((!)tab1_right).get_width () * scale;+ offset += t.get_width (); i++; } @@ -487,8 +465,6 @@ public class TabBar : GLib.Object { int i = 0; double end = (has_progress_wheel ()) ? width - 28 : width - 19; - return_if_fail (tab1_right != null);- if (index < first_tab) { first_tab = index; @@ -522,7 +498,7 @@ public class TabBar : GLib.Object { return; } - offset += t.get_width () + ((!)tab1_right).get_width () * scale;+ offset += t.get_width (); i++; } @@ -610,10 +586,10 @@ public class TabBar : GLib.Object { return_if_fail (tab_bar_background != null); cr.save ();- cr.rectangle (0, 0, width, height); cr.set_line_width (0); cr.set_source_rgba (background_r, background_g, background_b, 1);- cr.fill_preserve ();+ cr.rectangle (0, 0, width, height);+ cr.fill (); cr.restore (); cr.save ();@@ -622,11 +598,6 @@ public class TabBar : GLib.Object { w = width / scale; h = height / scale; - for (double i = 0; i < w; i += ((!)tab_bar_background).get_width ()) {- cr.set_source_surface ((!) tab_bar_background, i, h - ((!) tab_bar_background).get_height ());- cr.paint ();- }- if (has_scroll ()) { // left arrow cr.set_source_surface ((!) to_previous_tab, 2 / scale, h - ((!) to_previous_tab).get_height () - 5 / scale);@@ -671,69 +642,63 @@ public class TabBar : GLib.Object { } private void draw_tabs (Context cr) {+ double text_height, text_width, center_x, center_y; double close_opacity;- double offset = 19 / scale;+ double offset; double tab_width;- int i = 0; double tabs_end = width / scale; double h = height / scale; double tab_height; double tab_y;- + Tab t;+ Text label;+ if (has_progress_wheel ()) { tabs_end -= 19 / scale; } if (has_scroll ()) { tabs_end -= 19 / scale;- } - - return_if_fail (tab3_right != null);- return_if_fail (tab2_right != null);- return_if_fail (tab1_right != null);- return_if_fail (tab3_left != null);- return_if_fail (tab3_right != null);- return_if_fail (tab2_left != null);- return_if_fail (tab1_left != null);- return_if_fail (tab1_right != null);- return_if_fail (next_tab != null);+ offset = 24 / scale;+ } else {+ offset = 0;+ } - tab_height = ((!)tab3_right).get_height ();+ tab_height = this.height / scale; tab_y = h - tab_height; - foreach (Tab t in tabs) {- - if (i < first_tab) {- i++;- continue;- }-+ for (int tab_index = first_tab; tab_index < tabs.size; tab_index++) {+ t = tabs.get (tab_index);+ cr.save (); cr.translate (offset, 0); tab_width = t.get_width () / scale; - if (offset + tab_width + ((!)next_tab).get_width () + 3 / scale > tabs_end) {+ if (offset + tab_width > tabs_end) { cr.restore (); break; }- + // background- if (i == selected) {- for (int j = ((!)tab3_left).get_width (); j < tab_width; j++) {- cr.set_source_surface ((!) tab3_right, j, tab_y);- cr.paint ();- } - } else if (i == over) {- for (int j = ((!)tab2_left).get_width (); j < tab_width; j++) {- cr.set_source_surface ((!) tab2_right, j, tab_y);- cr.paint ();- } + if (tab_index == selected) {+ cr.save ();+ cr.set_source_rgba (234 / 255.0, 77 / 255.0, 26 / 255.0, 1);+ cr.rectangle (0, 0, tab_width, h);+ cr.fill ();+ cr.restore (); + } else if (tab_index == over) {+ cr.save ();+ cr.set_source_rgba (56 / 255.0, 59 / 255.0, 65 / 255.0, 1);+ cr.rectangle (0, 0, tab_width, h);+ cr.fill ();+ cr.restore (); } else {- for (int j = ((!)tab1_left).get_width (); j < tab_width; j++) {- cr.set_source_surface ((!) tab1_right, j, tab_y);- cr.paint ();- }+ cr.save ();+ cr.set_source_rgba (51 / 255.0, 54 / 255.0, 59 / 255.0, 1);+ cr.rectangle (0, 0, tab_width, h);+ cr.fill ();+ cr.restore (); } // close (x)@@ -742,50 +707,62 @@ public class TabBar : GLib.Object { cr.new_path (); cr.set_line_width (1 / scale); - close_opacity = (over_close_tab == i) ? 1 : 0.2; - cr.set_source_rgba (0, 0, 0, close_opacity);+ close_opacity = (over_close_tab == tab_index) ? 1 : 0.2; ++ if (tab_index == selected) {+ cr.set_source_rgba (40 / 255.0, 57 / 255.0, 65 / 255.0, close_opacity);+ } else {+ cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, close_opacity);+ } - cr.move_to (tab_width - 5 / scale, h - 14 / scale);- cr.line_to (tab_width - 10 / scale, h - 9 / scale);+ cr.move_to (tab_width - 7 / scale, h / 2.0 - 2.5 / scale);+ cr.line_to (tab_width - 12 / scale, h / 2.0 + 2.5 / scale); - cr.move_to (tab_width - 10 / scale, h - 14 / scale);- cr.line_to (tab_width - 5 / scale, h - 9 / scale);+ cr.move_to (tab_width - 12 / scale, h / 2.0 - 2.5 / scale);+ cr.line_to (tab_width - 7 / scale, h / 2.0 + 2.5 / scale); cr.stroke (); cr.restore (); }-- cr.set_source_rgba (0, 0, 0, 1);- cr.set_font_size (14 / scale);- cr.move_to (8 / scale, h - 6 / scale);- cr.show_text (t.get_label ());- cr.stroke (); + // tab label+ label = new Text ();+ label.set_text (t.get_label ());+ text_height = 8 / scale;+ text_width = label.get_extent (text_height);+ center_x = tab_width / 2.0 - text_width / 2.0;+ center_y = h / 2.0 - text_height / 2;+ + if (tab_index == selected) {+ cr.set_source_rgba (40 / 255.0, 57 / 255.0, 65 / 255.0, 1);+ } else {+ cr.set_source_rgba (101 / 255.0, 108 / 255.0, 116 / 255.0, 1);+ }+ + label.draw (cr, center_x, center_y, text_height);+ // edges- if (i == selected) {- cr.set_source_surface ((!) tab3_left, 0, tab_y);- cr.paint ();+ if (tab_index != selected) { // don't draw edges for the selected tab+ if (tab_index + 1 != selected) {+ cr.save ();+ cr.set_source_rgba (70 / 255.0, 77 / 255.0, 83 / 255.0, 1);+ cr.rectangle (tab_width - 1 / scale, 0, 1 / scale, h);+ cr.fill ();+ cr.restore ();+ } - cr.set_source_surface ((!) tab3_right, tab_width, tab_y);- cr.paint ();- } else if (i == over) {- cr.set_source_surface ((!) tab2_left, 0, tab_y);- cr.paint ();-- cr.set_source_surface ((!) tab2_right, tab_width, tab_y);- cr.paint ();- } else {- cr.set_source_surface ((!) tab1_left, 0, tab_y);- cr.paint ();-- cr.set_source_surface ((!) tab1_right, tab_width, tab_y);- cr.paint ();+ if (tab_index == first_tab) {+ cr.save ();+ cr.set_source_rgba (70 / 255.0, 77 / 255.0, 83 / 255.0, 1);+ cr.rectangle (- 1 / scale, 0, 1 / scale, h);+ cr.fill ();+ cr.restore ();+ } } cr.restore (); - offset += tab_width + ((!)tab1_right).get_width ();- i++;+ offset += tab_width; } }