示例#1
0
func (win *Window) TitleBarButton(ms *mouse.Mouse, fnClick clickHandler, x, y, w, h int) *TitleBarButton {

	but := &TitleBarButton{
		parent:     win,
		fb:         win.fb,
		wasClicked: false,
		clickHndr:  fnClick,
	}

	win.Children.PushFront(but)

	but.Element = base.Element{
		Id:         base.GenerateId(),
		X:          x,
		Y:          y,
		ScreenX:    win.Element.X + x,
		ScreenY:    win.Element.Y + y,
		Width:      w,
		Height:     h,
		InvMsgPipe: win.InvMsgPipe,
	}

	ms.RegisterMouse(but.Element.Id, but.Mouse, nil, &but.Element.ScreenX, &but.Element.ScreenY, w, h)

	but.Draw()

	return but
}
示例#2
0
文件: button.go 项目: romovs/viscum
// style should be one of BS_TEXT, BS_ICON_TEXT, BS_ICON
// icon should be nil for BS_TEXT
// txt should be empty string for BS_ICON
func (win *Window) Button(style byte, ms *mouse.Mouse, icon image.Image, txt string, fnClick clickHandler, x, y, w, h int) *Button {

	but := &Button{
		parent:     win,
		fb:         win.fb,
		wasClicked: false,
		clickHndr:  fnClick,
		txt:        txt,
		style:      style,
		icon:       icon,
		pushed:     false,
	}

	win.Children.PushFront(but)

	but.Element = base.Element{
		Id:         base.GenerateId(),
		X:          x,
		Y:          y,
		ScreenX:    win.Element.X + x,
		ScreenY:    win.Element.Y + y,
		Width:      w,
		Height:     h,
		InvMsgPipe: win.InvMsgPipe,
		Font:       fonts.Default(),
	}

	ms.RegisterMouse(but.Element.Id, but.Mouse, nil, &but.Element.ScreenX, &but.Element.ScreenY, w, h)

	but.Draw()

	return but
}
示例#3
0
文件: checkbox.go 项目: romovs/viscum
func (win *Window) CheckBox(style byte, ms *mouse.Mouse, txt string, fnClick clickHandler, x, y int) *CheckBox {

	cb := &CheckBox{
		parent:    win,
		fb:        win.fb,
		clickHndr: fnClick,
		txt:       txt,
		style:     style,
		checked:   false,
		mouseIn:   false,
	}

	win.Children.PushFront(cb)

	cb.Element = base.Element{
		Id:         base.GenerateId(),
		X:          x,
		Y:          y,
		ScreenX:    win.Element.X + x,
		ScreenY:    win.Element.Y + y,
		Width:      tk.cbChecked.Bounds().Dx(),
		Height:     tk.cbChecked.Bounds().Dy(),
		InvMsgPipe: win.InvMsgPipe,
		Font:       fonts.Default(),
	}

	var totalWidth, totalHeight int

	if txt != "" {
		w, h, _ := fonts.ExpectedSize(cb.Element.Font, txt)
		totalWidth = cb.Element.Width + ICON_TEXT_SPACE + int(w)

		if int(h) > cb.Element.Height {
			totalHeight = int(h)
		} else {
			totalHeight = cb.Element.Height
		}
	} else {
		totalWidth = cb.Element.Width
		totalHeight = cb.Element.Height
	}

	ms.RegisterMouse(cb.Element.Id, cb.Mouse, nil, &cb.Element.ScreenX, &cb.Element.ScreenY, totalWidth, totalHeight)

	cb.Draw()

	return cb
}
示例#4
0
文件: window.go 项目: romovs/viscum
func CreateWindow(style byte, fnCmpWinActivate cmpWinActivateHandler, fb *fbdev.Framebuffer, ms *mouse.Mouse, imp chan int64,
	x, y, w, h int) (*Window, error) {

	win := &Window{
		fb:             fb,
		titleBarHeight: 20,
		wasClicked:     false,
		cmpWinActHndr:  fnCmpWinActivate,
		tbHidden:       style&WS_TITLEBAR_HIDDEN != 0,
		bg: color.RGBA{
			R: 241,
			G: 240,
			B: 238,
			A: gfx.A_OPAQUE,
		},
	}

	win.Element = base.Element{
		Id:             base.GenerateId(),
		X:              x, // relative position within the parent element
		Y:              y,
		ScreenX:        x, // position within the screen coordinates
		ScreenY:        y,
		Width:          w,
		Height:         h,
		Buffer:         make([]byte, w*h*4),
		InvMsgPipe:     imp,
		DeactivateHndr: win.Deactivate,
		Children:       list.New(),
	}

	ms.RegisterMouse(win.Element.Id, win.Mouse, win.activate, &win.Element.ScreenX, &win.Element.ScreenY, w, h)

	if !win.tbHidden {
		win.closeButton = win.TitleBarButton(ms, func(_ bool) {
			log.Debugf("Window %v exiting...", win.Id)
			// deregister the window
			win.Element.CompRemoveHdnr(win.Id)
			// remove mouse handlers
			ms.DeregisterMouse(win.Id)
			for v := win.Children.Front(); v != nil; v = v.Next() {
				ms.DeregisterMouse(v.Value.(base.IElement).GetId())
			}
		}, w-15, 5, 10, 10)
	}

	win.Draw()

	return win, nil
}