}; //Color.BlueViolet /// <summary> /// Briefly shows standard blinking on-screen rectangle. /// </summary> public static void ShowOsdRect(RECT r, bool limitToScreen = false) { var osr = CreateOsdRect(); r.Inflate(2, 2); //2 pixels inside, 2 outside if (limitToScreen) { var k = AScreen.Of(r).Bounds; r.Intersect(k); } osr.Rect = r; osr.Show(); int i = 0; ATimer.Every(250, t => { if (i++ < 5) { osr.Color = (i & 1) != 0 ? 0xFFFFFF00 : 0xFF8A2BE2; } else { t.Stop(); osr.Dispose(); } }); }
/// <summary> /// Returns normal coordinates relative to the primary screen. Converts fractional/reverse coordinates etc. /// </summary> /// <param name="x">X coordinate relative to the specified screen (default - primary).</param> /// <param name="y">Y coordinate relative to the specified screen (default - primary).</param> /// <param name="workArea">x y are relative to the work area.</param> /// <param name="screen">If used, x y are relative to this screen. Default - primary screen.</param> /// <param name="widthHeight">Use only width and height of the screen rectangle. If false, the function adds its offset (left and top, which can be nonzero if using the work area or a non-primary screen).</param> /// <param name="centerIfEmpty">If x or y is default(Coord), use Coord.Center.</param> public static POINT Normalize(Coord x, Coord y, bool workArea = false, AScreen screen = default, bool widthHeight = false, bool centerIfEmpty = false) { if (centerIfEmpty) { if (x.IsEmpty) { x = Center; } if (y.IsEmpty) { y = Center; } } POINT p = default; if (!x.IsEmpty || !y.IsEmpty) { RECT r; if (workArea || !screen.IsNull || _NeedRect(x, y)) { r = screen.GetScreenHandle().GetRect(workArea); if (widthHeight) { r.Offset(-r.left, -r.top); } } else { r = default; } p.x = x._Normalize(r.left, r.right); p.y = y._Normalize(r.top, r.bottom); } return(p); }
void _SetRect(RECT anchor) { var ra = _doc.RectangleToScreen(anchor); var rs = AScreen.Of(ra).WorkArea; rs.Inflate(-1, -5); int heiAbove = ra.Top - rs.top, heiBelow = rs.bottom - ra.Bottom; int maxHeight = Math.Max(heiAbove, heiBelow); if (maxHeight < 200) { maxHeight = 200; } var r = _w.Bounds; int width = r.Width, height = r.Height; if (height > maxHeight) { _height = height; height = maxHeight; } else if (_height > 0 && _height <= maxHeight) { height = _height; _height = 0; } r.Height = height; r.X = ra.Left + width <= rs.right ? ra.Left : rs.right - width; r.X = Math.Max(r.X, rs.left); bool down = height <= heiBelow || heiAbove <= heiBelow; r.Y = down ? ra.Bottom : ra.Top - height; _w.Bounds = r; }
// ============================================================================ // ***** SCREENS MANAGEMENT ***** // ============================================================================ public void AddScreen(AScreen screen, bool closeCurrentScreen = true) { if (lastScreensOpen.Contains(screen) || screen == currentScreen) { Debug.LogError("Screen is already open : " + screen.name); return; } if (currentScreen == null) { screen.ActivateScreen(); currentScreen = screen; return; } if (closeCurrentScreen) { currentScreen.DeactivateScreen(screen.ActivateScreen); currentScreen = screen; } else { screen.ActivateScreen(); lastScreensOpen.Push(currentScreen); currentScreen = screen; } }
public void AddScreenWithoutCloseAScreen(AScreen screen, AScreen screenDoesntClose) { if (screen == screenDoesntClose) { Debug.LogError("Screen and screenDoesntClose is the same thing"); return; } if (screen == currentScreen) { Debug.LogWarning("Screen is already open"); return; } if (currentScreen == screenDoesntClose) { lastScreensOpen.Push(currentScreen); currentScreen = screen; currentScreen.ActivateScreen(); } else { AScreen lLastScreen = currentScreen; currentScreen = screen; lLastScreen.DeactivateScreen(delegate { if (screen != currentScreen) { return; } screen.ActivateScreen(); }); } }
public void CloseCurrentScreenWithoutCloseAnimation() { if (currentScreen == null) { Debug.LogError("Use addscreen to add the first screen"); return; } currentScreen.DeactivateScreenWithoutAnimation(); currentScreen = null; }
public void ReturnToLastScreenOpen() { if (lastScreensOpen.Count == 0) { Debug.LogError("No last screen!"); return; } if (currentScreen != null) { currentScreen.DeactivateScreen(); } currentScreen = lastScreensOpen.Pop(); }
private void OpenScreen(ScreenMeta screenMeta, bool closeCurrent) { //DebugToScreen.Log( "ScreenManager: OpenScreen() Title: " + screenMeta.title // + " Model: " + screenMeta.modelName + " Screen: " + screenMeta.screen // + " Opening..." ); // If already open, return if (m_Open != null && m_Open == screenMeta && m_Open.screen.isOpen) { return; } AScreen screen = screenMeta.screen; screen.screenTitle = screenMeta.title; screen.modelName = screenMeta.modelName; if (closeCurrent && m_Open != null) { if (m_Open.remember) { // Push onto History m_ScreenHistory.Push(m_Open); } m_Open.screen.Close(true); // Fire 'Closed' Event onEvent(new Event(Event.Type.Closed, m_Open.title)); } // Open the new Screen #if DEBUG //Debug.Log( "ScreenManager: About to Open Screen: " + screen.screenTitle + " isOpen: " + screen.isOpen + " isHidden: " + screen.isHidden ); #endif screen.Open(); m_Open = screenMeta; #if DEBUG //Debug.Log( "ScreenManager: About to Set Controls: " + screen.screenTitle + " isOpen: " + screen.isOpen + " isHidden: " + screen.isHidden ); #endif SetControls(screenMeta.controls); // Fire 'Opened' Event onEvent(new Event(Event.Type.Opened, screenMeta.title)); Announce(); }
public void AddScreenWithoutCloseAnimation(AScreen screen) { if (lastScreensOpen.Contains(screen) || screen == currentScreen) { Debug.LogWarning("Screen is already open :" + screen.name); return; } if (currentScreen == null) { Debug.LogError("Use addscreen to add the first screen"); return; } currentScreen.DeactivateScreenWithoutAnimation(screen.ActivateScreen); currentScreen = screen; }
public bool Detect(POINT pt) { //get normal x y. In pt can be outside screen when cursor moved fast and was stopped by a screen edge. Tested: never for click/wheel events. //AOutput.Write(pt, AMouse.XY); //var r = AScreen.Of(pt).Bounds; //problem with empty corners between 2 unaligned screens: when mouse tries to quickly diagonally cut such a corner, may activate a wrong trigger var r = AScreen.Of(AMouse.XY).Bounds; //smaller problem: AMouse.XY gets previous coordinates _xmin = r.left; _ymin = r.top; _xmax = r.right - 1; _ymax = r.bottom - 1; _x = AMath.MinMax(pt.x, _xmin, _xmax); _y = AMath.MinMax(pt.y, _ymin, _ymax); //AOutput.Write(pt, _x, _y, r); result = default; result.pt = (_x, _y); _Detect(); _prev.xx = _x; _prev.yy = _y; #if DEBUG //AOutput.Write(++_prev.debug, edgeEvent, moveEvent, (_x, _y)); #endif return(result.edgeEvent != 0 || result.moveEvent != 0); }
public void CloseAllScreens(bool withoutCloseAnimation = false) { if (withoutCloseAnimation) { currentScreen.DeactivateScreenWithoutAnimation(); currentScreen = null; for (int i = lastScreensOpen.Count - 1; i >= 0; i--) { lastScreensOpen.Pop().DeactivateScreenWithoutAnimation(); } return; } currentScreen.DeactivateScreen(); currentScreen = null; for (int i = lastScreensOpen.Count - 1; i >= 0; i--) { lastScreensOpen.Pop().DeactivateScreen(); } }
void _Show(Control anchor, Rectangle ra) { ResultItem = null; ResultWasKey = false; int n = Items?.Length ?? 0; if (n == 0) { ClosedAction?.Invoke(this); return; } _ = PopupWindow; //auto-creates _w and _c objects if null or disposed if (MultiShow && _c.IsHandleCreated) { if (_c.Root.TryGetFirstChild(out var n0)) { _c.SelectedNode = n0; //make CurrentNode=the first node and reset vertical scrollbar. Never mind: does not reset horizontal scrollbar. } _c.ClearSelection(); } //never mind: could skip most of this code if items not changed. Then need to clone Items etc. Too difficult if IPopupListItem. bool hasCheckboxes = false, hasIcons = false; foreach (var v in Items) { if (v is IPopupListItem e) { if (!hasCheckboxes && e.CheckType != default) { hasCheckboxes = true; } if (!hasIcons && e.Icon != null) { hasIcons = true; } if (hasCheckboxes && hasIcons) { break; } } } var si = AScreen.Of(ra).GetInfo(); var rs = si.workArea; if (ra.Width > 0 && (ra.Right <= rs.left || ra.Left >= rs.right)) { rs = si.bounds; } rs.Inflate(-1, -5); int heiSB = SystemInformation.HorizontalScrollBarHeight; int heiAbove = ra.Top - rs.top - heiSB, heiBelow = rs.bottom - ra.Bottom - heiSB; int maxHeight = Math.Max(heiAbove, heiBelow), maxWidth = FixedWidth ? ra.Width : rs.Width - 100; if (maxHeight < 200) { maxHeight = 200; } bool hasVertSB = false; int width = 0, height = 2; Font fontNormal = _w.Font; foreach (var v in Items) { var e = v as IPopupListItem; var font = (e?.BoldFont ?? false) ? _w.FontBold : fontNormal; var z = TextRenderer.MeasureText(v.ToString(), font); z.Width += _c._ccText.LeftMargin; z.Height += 2; if (z.Height < 17) { z.Height = 17; } if (e != null) { if (e.CheckType != default) { z.Width += NodeCheckBox.ImageSize + _c._ccCheck.LeftMargin; } var im = e.Icon; if (im != null) { var iz = Util.ADpi.ImageSize(im); z.Width += iz.width + _c._ccIcon.LeftMargin; if (z.Height < iz.height) { z.Height = iz.height; } } } //AOutput.Write(z); if (height + z.Height <= maxHeight) { height += z.Height; } else { hasVertSB = true; } if (z.Width > width) { width = z.Width; } } width += 5; if (hasVertSB) { width += SystemInformation.VerticalScrollBarWidth; } if (width < ra.Width) { width = ra.Width; } else if (width > maxWidth) { width = maxWidth; height += heiSB; } var r = new Rectangle(0, 0, width, height); _c.Bounds = r; r.X = ra.Left + width <= rs.right ? ra.Left : rs.right - width; r.X = Math.Max(r.X, rs.left); bool down = height <= heiBelow || heiAbove <= heiBelow; r.Y = down ? ra.Bottom : ra.Top - height; _w.Bounds = r; _c.Model = null; _c.Model = _c; _w.ShowAt(anchor, !down); //tested: API CalculatePopupWindowPosition does not work well here. }
void TestAScreen() { var w = AWnd.Active; var s = new AScreen(w); var d = s.GetScreenHandle(); AOutput.Write(d); //var w = AWnd.Find("*Notepad", also: o => o.Screen.Index == 1); //Bug1("", f: o=>o.) //Bug1(f: o=>o.) //ThreadPool.QueueUserWorkItem(_ => AOutput.Write(1)); //500.ms(); //APerf.First(); //var a = AScreen.AllScreens; //APerf.NW(); //AOutput.Write(a); //500.ms(); ////while(!AKeys.IsCtrl) 100.ms(); ////AScreen.Of(w). //var w = AWnd.Active; //AWnd.Active.Move(0, 0, 0, 0, false, screen: 1); ////AWnd.Active.Move(0, 0, 0, 0, false, screen: w); ////AWnd.Active.Move(0, 0, 0, 0, false, (AScreen)w); //AWnd.Active.Move(0, 0, 0, 0, false, new AScreen(w)); //AWnd.Active.Move(0, 0, 0, 0, false, AScreen.Of(w)); //new AScreen(() => AScreen.Of(AMouse.XY)); //new AScreen(() => AScreen.Of(AWnd.Active)); //Screen sco = null; new AScreen(sco); //AWnd.Active.Move(0, 0, 0, 0, false, screen: sco); //RECT r = AScreen.Of(AWnd.Active).Bounds; //AOutput.Write(HScreen.AllScreens); ////AOutput.Write(Screen.AllScreens); //AOutput.Write(HScreen.FromIndex(0), HScreen.FromIndex(1), HScreen.FromIndex(2), HScreen.FromIndex(3)); //foreach(var v in Screen.AllScreens) AOutput.Write(v.GetIndex(), (HScreen)v); //foreach(var v in HScreen.AllScreens) AOutput.Write(v.Index, (Screen)v); //bool two = AKeys.IsScrollLock; //var screenFromMouse = new HScreen(() => HScreen.FromPoint(AMouse.XY)); //var screenFromActiveWindow = new HScreen(() => HScreen.FromWindow(AWnd.Active)); //AOutput.Write(screenFromMouse, screenFromActiveWindow); //while(ADialog.ShowOkCancel("test")) { // two = AKeys.IsScrollLock; // 200.ms(); // //APerf.SpeedUpCpu(); // APerf.First(); // if(two) { _ = HScreen.AllScreens; APerf.Next(); _ = HScreen.AllScreens; } // else { _ = Screen.AllScreens; APerf.Next(); _ = Screen.AllScreens; } // APerf.NW(); //} //APerf.SpeedUpCpu(); //for(int i1 = 0; i1 < 7; i1++) { // int n2 = 1; // APerf.First(); // for(int i2 = 0; i2 < n2; i2++) { _ = HScreen.AllScreens; } // APerf.Next(); // for(int i2 = 0; i2 < n2; i2++) { _ = two ? HScreen.Primary.Info.bounds : AScreen2.PrimaryRect; } // APerf.NW(); // Thread.Sleep(100); //} //var h = HScreen.Primary; ////h = default; ////h = new HScreen((IntPtr)12345678); //h = HScreen.FromWindow(AWnd.Active, SDefault.Nearest); //var v = h.GetInfo(); //AOutput.Write(v, h.IsAlive); //AOutput.Write(h == HScreen.Primary); }
#pragma warning restore 1591 //XML doc /// <summary> /// Sets position and/or screen. /// </summary> /// <param name="x">X relative to the screen or work area. Default - center.</param> /// <param name="y">X relative to the screen or work area. Default - center.</param> /// <param name="workArea">x y are relative to the work area of the screen.</param> /// <param name="screen">Can be used to specify a screen. Default - primary.</param> /// <remarks> /// Also there is are implicit conversions from tuple (x, y) and POINT. Instead of <c>new PopupXY(x, y)</c> you can use <c>(x, y)</c>. Instead of <c>new PopupXY(p.x, p.y, false)</c> you can use <c>p</c> or <c>(POINT)p</c> . /// </remarks> public PopupXY(Coord x = default, Coord y = default, bool workArea = true, AScreen screen = default) { this.x = x; this.y = y; this.workArea = workArea; this.screen = screen; }
bool _HookProc2(TriggerHookContext thc, bool isEdgeMove, ESubtype subtype, HookData.MouseEvent mEvent, POINT pt, byte data, byte dataAnyPart) { var mod = TrigUtil.GetModLR(out var modL, out var modR) | _eatMod; MouseTriggerArgs args = null; g1: if (_d.TryGetValue(_DictKey(subtype, data), out var v)) { if (!isEdgeMove) { thc.UseWndFromPoint(pt); } for (; v != null; v = v.next) { var x = v as MouseTrigger; if ((mod & x.modMask) != x.modMasked) { continue; } switch (x.flags & (TMFlags.LeftMod | TMFlags.RightMod)) { case TMFlags.LeftMod: if (modL != mod) { continue; } break; case TMFlags.RightMod: if (modR != mod) { continue; } break; } if (isEdgeMove && x.screenIndex != TMScreen.Any) { var screen = x.screenIndex == TMScreen.OfActiveWindow ? AScreen.Of(AWnd.Active) : AScreen.Index((int)x.screenIndex); if (!screen.Bounds.Contains(pt)) { continue; } } if (v.DisabledThisOrAll) { continue; } if (args == null) { thc.args = args = new MouseTriggerArgs(x, thc.Window, mod); //may need for scope callbacks too } else { args.Trigger = x; } if (!x.MatchScopeWindowAndFunc(thc)) { continue; } if (x.action == null) { _ResetUp(); } else if (0 != (x.flags & TMFlags.ButtonModUp) && (mod != 0 || subtype == ESubtype.Click)) { _upTrigger = x; _upArgs = args; _upEvent = subtype == ESubtype.Click ? mEvent : 0; _upMod = mod; } else { thc.trigger = x; _ResetUp(); } _eatMod = mod; if (mod != 0) { _SetTempKeybHook(); if (thc.trigger != null) { thc.muteMod = TriggerActionThreads.c_modRelease; } else { ThreadPool.QueueUserWorkItem(_ => AKeys.Internal_.ReleaseModAndDisableModMenu()); } } //AOutput.Write(mEvent, pt, mod); if (isEdgeMove || 0 != (x.flags & TMFlags.ShareEvent)) { return(false); } if (subtype == ESubtype.Click) { _eatUp = mEvent; } return(true); } } if (dataAnyPart != 0) { data = dataAnyPart; dataAnyPart = 0; goto g1; } return(false); }