func (self *Image) showIBeam(w driver.Window) { if (self.state & imageHasIBeam) == 0 { if cursor, err := w.Display().NewCursor(driver.CursorIBeam); err == nil { PushCursor(self, cursor) self.state |= imageHasIBeam } } }
func (self *View) changeMouseSelection(w driver.Window, p geom.Point, b mouse.ButtonSet) { if (self.state & viewMouseSelection) == 0 { self.state |= viewMouseSelection self.mouseSelectionOrigin = p self.mouseSelectionButtons = b if cur, err := w.Display().NewCursor(driver.CursorIBeam); err != nil { fmt.Fprintf(os.Stderr, "WARN: seting default cursor to I-Beam failed: %s\n", err) } else { self.changeDefaultCursor(cur) } } p0 := self.mouseSelectionOrigin p1 := p r := geom.Rect{X: p0.X, Y: p0.Y, W: p1.X - p0.X, H: p1.Y - p0.Y} if r.W >= 0.0 && r.W < 1.0 { r.W = 1.0 } else if r.W < 0.0 && r.W > -1.0 { r.W = -1.0 } if r.H >= 0.0 && r.H < 1.0 { r.H = 1.0 } else if r.H < 0.0 && r.H > -1.0 { r.H = -1.0 } if self.content != nil { mouseSelection(w, self.content, event.MouseSelection{ Pressed: b, Bounds: r, }) } }
func (self *View) Process(src driver.Window, ev interface{}) (err error) { if src == nil { err = ErrNilWindow return } if ev == nil { err = ErrNilEvent return } self.state |= viewProcess switch e := ev.(type) { case event.Redraw: self.processRedraw(src, e) case event.Resize: self.processResize(src, e) case event.ChangeScreen: self.processChangeScreen(src, e) case event.Move: self.processMove(src, e) case event.Minimize: self.processMinimize(src, e) case event.Maximize: self.processMaximize(src, e) case event.Restore: self.processRestore(src, e) case event.Focus: self.processFocus(src, e) case event.Close: self.processClose(src, e) case event.KeyDown: self.processKeyDown(src, e) case event.KeyUp: self.processKeyUp(src, e) case event.MouseDown: self.processMouseDown(src, e) case event.MouseUp: self.processMouseUp(src, e) case event.MouseEnter: self.processMouseEnter(src, e) case event.MouseExit: self.processMouseExit(src, e) case event.MouseMove: self.processMouseMove(src, e) case event.MouseDrag: self.processMouseDrag(src, e) case event.Copy: self.processCopy(src, e) case event.Cut: self.processCut(src, e) case event.Paste: self.processPaste(src, e) case func(driver.Window): e(src) } // If the resize flag is set to true some widgets in the tree have changed // properties that impact how they should be laid out, we reset bounds of // the root widget which should propagate this to its child elements if it's // a container. if self.content != nil && (self.state&viewResize) != 0 { self.content.SetBounds(self.Bounds()) } // If a source window was given for the event it will be sent the redrawing // operations that the modified widgets of the view have scheduled while // processing the event. for _, r := range self.dirty { if err = src.Send(event.Redraw{Clip: r}); err != nil { break } } // Processing the event caused may have changed the cursor stack, we pick // the cursor that's on top of the stack and set it to the window. if (self.state & viewCursorChanged) != 0 { var cur driver.Cursor var err error if n := len(self.cursors); n == 0 { if cur = self.defaultCursor; cur == nil { cur, err = src.Display().NewCursor(driver.CursorArrow) } } else { cur = self.cursors[n-1] } if err != nil { fmt.Fprintf(os.Stderr, "WARN: failed to switch cursor back to the default: %s\n", err) } else { src.Send(event.ChangeCursor{cur}) } } self.state &= ^(viewProcess | viewResize | viewCursorChanged) self.dirty = self.dirty[:0] return }