]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
show 使用grid0/1 替代win showall
authorqydysky <qydysky@foxmail.com>
Wed, 20 Jan 2021 03:20:18 +0000 (11:20 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 20 Jan 2021 03:20:18 +0000 (11:20 +0800)
Reply/gtk.go

index c55d9e0643008831a89792cd90f819a11654c35a..b2c9121a930c1afb983ddd688a90dc757cd9bdad 100644 (file)
@@ -51,12 +51,15 @@ var (
        Gtk_danmu_pool_index uint
        Gtk_danmu_pool = make(map[uint]Danmu_mq_t)
        win *gtk.Window
-       grid0 *gtk.Grid
-       in_smooth_roll bool
        imgbuf = make(map[string](*gdk.Pixbuf))
+       danmu_win_running bool//弹幕窗体是否正在运行
+       contrl_win_running bool//控制窗体是否正在运行
+       in_smooth_roll bool
+       grid0 *gtk.Grid
+       grid1 *gtk.Grid
        keep_list = list.New()
-       grid1 *gtk.Grid;
 )
+
 func init(){
        if!IsOn("Gtk") {return}
        go Gtk_danmu()
@@ -75,11 +78,6 @@ func Gtk_danmu() {
        if Gtk_on {return}
        gtk.Init(nil)
 
-       var (
-               danmu_win_running bool//弹幕窗体是否正在运行
-               contrl_win_running bool//控制窗体是否正在运行
-       )
-
        var (
                win2 *gtk.Window
                scrolledwindow0 *gtk.ScrolledWindow
@@ -96,7 +94,6 @@ func Gtk_danmu() {
        )
 
 
-
        application, err := gtk.ApplicationNew(
        "com.github.qydysky.bili_danmu.reply"+p.Sys().GetTime(),//时间戳允许多开
        glib.APPLICATION_FLAGS_NONE)
@@ -513,6 +510,8 @@ func load_face(uid string) (loc string) {
 }
 
 func show(s,img_src string,to_grid ...int){
+       sec := 0
+
        var item danmu_item
 
        item.text,_ = gtk.TextViewNew();
@@ -521,8 +520,12 @@ func show(s,img_src string,to_grid ...int){
                item.text.SetEditable(false)
                item.text.SetHExpand(true)
                item.text.SetWrapMode(gtk.WRAP_WORD_CHAR)
-       }
-       {
+               if tsec,ok := keep_key[img_src];ok && tsec != 0 {
+                       sec = tsec
+                       if sty,e := item.text.GetStyleContext();e == nil{
+                               sty.AddClass("highlight")
+                       }
+               }
                item.handle,_ = item.text.Connect("size-allocate", func(){
                        b,e := item.text.GetBuffer()
                        if e != nil {log.Println(e);return}
@@ -531,7 +534,7 @@ func show(s,img_src string,to_grid ...int){
                })
        }
 
-       item.img,_ =gtk.ImageNew();
+       item.img,_ = gtk.ImageNew();
        {
                var (
                        pixbuf *gdk.Pixbuf
@@ -551,19 +554,12 @@ func show(s,img_src string,to_grid ...int){
                if e == nil {item.img.SetFromPixbuf(pixbuf)}
        }
        {
-               sec := 0
-               if tsec,ok := keep_key[img_src];ok && tsec != 0 {
-                       sec = tsec
-                       if sty,e := item.text.GetStyleContext();e == nil{
-                               sty.AddClass("highlight")
-                       }
-               }
                if len(to_grid) != 0 && to_grid[0] == 0 {//突出显示结束后,显示在普通弹幕区
                        loc := int(grid0.Container.GetChildren().Length())/2;
                        grid0.InsertRow(loc);
                        grid0.Attach(item.img, 0, loc, 1, 1)
                        grid0.Attach(item.text, 1, loc, 1, 1)
-                       if Gtk_on {win.ShowAll()}
+                       grid0.ShowAll()
                        return
                }
                /*
@@ -596,13 +592,14 @@ func show(s,img_src string,to_grid ...int){
                        grid1.InsertRow(loc - InsertIndex);
                        grid1.Attach(item.img, 0, loc - InsertIndex, 1, 1)
                        grid1.Attach(item.text, 1, loc - InsertIndex, 1, 1)
+                       grid1.ShowAll()
                } else {
                        loc := int(grid0.Container.GetChildren().Length())/2;
                        grid0.InsertRow(loc);
                        grid0.Attach(item.img, 0, loc, 1, 1)
                        grid0.Attach(item.text, 1, loc, 1, 1)
+                       grid0.ShowAll()
                }
        }
 
-       if Gtk_on {win.ShowAll()}
 }