private void frmLogin_Load(object sender, EventArgs e) { this.label3.Text = ""; InfoSys.NetCardIP = WinInfo.GetNetCardIP(); InfoSys.NetCardMAC = WinInfo.GetNetCardMAC(); InfoSys.HostName = WinInfo.Get_HostName(); }
public void Reload() { Program.Config.Load(); Api.Init(Program.Config.Path, Program.Config.ScriptFolder, Program.Config.CardCDB); BanlistManager.Init(Program.Config.BanlistFile); MsgSystem.Init(Program.Config.File_ServerMsgs); WinInfo.Init(Program.Config.WinDbName); banNames.Clear(); if (File.Exists(Program.Config.File_BanAccont)) { string[] lines = File.ReadAllLines(Program.Config.File_BanAccont); foreach (string line in lines) { if (string.IsNullOrEmpty(line) || line.StartsWith("#")) { continue; } string name = line.Trim(); if (!banNames.Contains(name)) { banNames.Add(name); } } } }
public bool Start() { if (IsListening) { return(false); } try { string script = Tool.Combine(Config.Path, "script"); string cdb = Tool.Combine(Config.Path, "cards.cdb"); string windb = Tool.Combine(Config.Path, "win.db"); string lflist = Tool.Combine(Config.Path, "lflist.conf"); string namelist = Tool.Combine(Program.Config.Path, "namelist.txt"); string msgfile = Tool.Combine(Program.Config.Path, "server_msg.txt"); // Logger.Debug("script:"+script); // Logger.Debug("windb:"+windb); // Logger.Debug("lflist:"+lflist); Api.Init(Config.Path, script, cdb); BanlistManager.Init(lflist); WinInfo.Init(windb); RoomManager.init(namelist); Messages.Init(msgfile); if (Config.ApiPort > 0) { Logger.Info("Connecting api server."); if (!ServerApi.Init(Config.ApiPort)) { Logger.Warn("connect api server fail."); } else { Logger.Info("Connect api server ok"); } } m_listener = new AsyncTcpListener <GameSession>(IPAddress.Any, Config.ServerPort, banmode: Config.isBanIP); m_listener.OnConnect += new AsyncTcpListener <GameSession> .ConnectEventHandler(Listener_OnConnect); m_listener.OnReceive += new AsyncTcpListener <GameSession> .ReceiveEventHandler(Listener_OnReceive); m_listener.OnDisconnect += new AsyncTcpListener <GameSession> .DisconnectEventHandler(Listener_OnDisconnect); m_listener.OnCheckClient += new AsyncTcpListener <GameSession> .CheckEventHandler(Listener_OnCheckClient); m_listener.Start(); ServerApi.OnServerInfo(this); IsListening = true; } catch (SocketException) { Logger.Warn("The " + Config.ServerPort + " port is currently in use."); return(false); } catch (Exception e) { Logger.Error(e); return(false); } Logger.Info("Listening on port " + Config.ServerPort); return(true); }
private void initBaseWin(int count) { int width = this._baseWidth / count; int height = this._baseHeight / count; List <WinInfo> playerWinInfos = new List <WinInfo>(); int index = 1; for (int y = 0; y < count; y++) { for (int x = 0; x < count; x++) { //设置位置和宽高 WinInfo info = new WinInfo(); info.index = index++; info.x = width * x; info.width = width; info.y = height * y; info.height = height; playerWinInfos.Add(info); } } basePanelMap[count] = playerWinInfos; }
private static Rectangle GetRectInsideNearestMonitor(WinInfo win) { var real = win.Position; var rect = win.Visible; var monitorRect = Screen.GetWorkingArea(rect); // use workspace coordinates var y = new Rectangle( Math.Max(monitorRect.Left, Math.Min(monitorRect.Right - rect.Width, rect.Left)), Math.Max(monitorRect.Top, Math.Min(monitorRect.Bottom - rect.Height, rect.Top)), Math.Min(monitorRect.Width, rect.Width), Math.Min(monitorRect.Height, rect.Height) ); if (rect != real) // support different real and visible position { y = new Rectangle( y.Left - rect.Left + real.Left, y.Top - rect.Top + real.Top, y.Width - rect.Width + real.Width, y.Height - rect.Height + real.Height ); } #if DEBUG if (y != real) { Debug.WriteLine("Moving " + real + "→" + y + " in monitor " + monitorRect); } #endif return(y); }
private static void WinSaveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { string[] sqls = null; lock (WinInfos) { if (WinInfos.Count == 0) { return; } sqls = new string[WinInfos.Count]; int i = 0; while (WinInfos.Count > 0) { WinInfo info = WinInfos.Dequeue(); sqls[i++] = info.GetSQL(); } } ThreadPool.QueueUserWorkItem(new WaitCallback( delegate(object obj) { //string[] sqls = (string[])obj; SQLiteTool.Command(WinInfo.DB_FILE, sqls); Logger.Debug("save wins record:" + sqls.Length); } )); }
public async Task MakeMoveAsync(SpaceInfoCP space) { if (_graphics == null) { throw new BasicBlankException("Graphics was never created. Rethink"); } SingleInfo = SaveRoot !.PlayerList.GetWhoPlayer(); space.Status = SingleInfo.Piece; WinInfo thisWin = SaveRoot.GameBoard.GetWin(); _graphics !.ThisWin = thisWin; if (BasicData !.MultiPlayer == true && SingleInfo.PlayerCategory == EnumPlayerCategory.Self) { await Network !.SendMoveAsync(space); } if (thisWin.WinList.Count > 0) { RepaintBoard(); await ShowWinAsync(); return; } RepaintBoard(); if (thisWin.IsDraw == true) { await ShowTieAsync(); return; } await EndTurnAsync(); }
private bool EvalWindow(int hwndInt, int lParam) { var hwnd = new IntPtr(hwndInt); if (!IsAltTabWindow(hwnd)) { return(true); } WinInfo win = GetWindowInfo(hwnd); if (IsNormalPosition(win.position.X, win.position.Y)) { m_infos.Add(hwnd, win); // EnumWindows returns windows in Z order from back to front m_windowsBackToTop.Add(hwnd); } #if DEBUG // For debugging purpose, output window title with handle int textLength = 256; System.Text.StringBuilder outText = new System.Text.StringBuilder(textLength + 1); int a = GetWindowText(hwnd, outText, outText.Capacity); int pid = 0; GetWindowThreadProcessId(hwnd, out pid); Debug.WriteLine(hwnd + " " + win.position + " " + outText + " Pid=" + pid); #endif return(true); }
public override async Task MakeMoveAsync(int column) { if (BasicData !.MultiPlayer == true && SingleInfo !.PlayerCategory == EnumPlayerCategory.Self) { await Network !.SendMoveAsync(column); } Vector topSpace = SaveRoot !.GameBoard[1, column].Vector; SpaceInfoCP tempSpace = new SpaceInfoCP(); tempSpace.Color = SingleInfo !.Color.ToString().ToColor(); tempSpace.Player = WhoTurn; tempSpace.Vector = new Vector(1, column); Vector BottomSpace = SaveRoot.GameBoard.GetBottomSpace(column); await Aggregator.AnimateMovePiecesAsync(topSpace, BottomSpace, tempSpace, true); SaveRoot.GameBoard[BottomSpace].Color = tempSpace.Color; SaveRoot.GameBoard[BottomSpace].Player = WhoTurn; RepaintBoard(); WinInfo thisWin = SaveRoot.GameBoard.GetWin(); if (thisWin.IsDraw == true) { await ShowTieAsync(); return; } if (thisWin.WinList.Count > 0) { RepaintBoard(); await ShowWinAsync(); return; } await EndTurnAsync(); }
public bool Start(int port = 0) { try { Api.Init(Program.Config.Path, Program.Config.ScriptFolder, Program.Config.CardCDB); BanlistManager.Init(Program.Config.BanlistFile); //DecksManager.Init(); MsgSystem.Init(Program.Config.File_ServerMsgs); WinInfo.Init(Program.Config.WinDbName); if (File.Exists(Program.Config.File_BanAccont)) { string[] lines = File.ReadAllLines(Program.Config.File_BanAccont); foreach (string line in lines) { if (string.IsNullOrEmpty(line) || line.StartsWith("#")) { continue; } string name = line.Trim(); if (!banNames.Contains(name)) { banNames.Add(name); } } } try{ Directory.CreateDirectory(Program.Config.replayFolder); }catch (IOException) { } IsListening = true; m_listener = new TcpListener(IPAddress.Any, port == 0 ? Program.Config.ServerPort : port); m_listener.Start(); Thread acceptThread = new Thread(new ThreadStart(AcceptClient)); acceptThread.IsBackground = true; acceptThread.Start(); WinSaveTimer.Start(); ApiServer.Start(); } catch (SocketException) { Logger.WriteError("The " + (port == 0 ? Program.Config.ServerPort : port) + " port is currently in use."); return(false); } catch (Exception e) { Logger.WriteError(e); return(false); } Logger.WriteLine("Listening on port " + (port == 0 ? Program.Config.ServerPort : port)); if (BanlistManager.Banlists != null && BanlistManager.Banlists.Count > 0) { Logger.WriteLine("Banlist = " + BanlistManager.Banlists[0].Name); } return(true); }
private void button2_Click(object sender, EventArgs e) { WinInfo wi = listBox1.SelectedItem as WinInfo; if (wi != null) { AddAppTab(wi.win); listBox1.Items.Remove(wi); } }
public static void OnWin(string roomName, int roomMode, int win, int reason, string yrpFileName, string[] names, bool force) { WinInfo info = new WinInfo(roomName, win, reason, yrpFileName, names, force); lock (WinInfos) { WinInfos.Enqueue(info); } }
private WinInfo infoCp(WinInfo temp) { WinInfo info = new WinInfo(); info.x = temp.x; info.y = temp.y; info.width = temp.width; info.height = temp.height; return(info); }
private static WinInfo GetWindowInfo(IntPtr hwnd) { WinInfo win = new WinInfo(); RECT pos; if (!GetWindowRect(hwnd, out pos)) throw new Exception("Error getting window rectangle"); win.position = win.visible = pos.ToRectangle(); if (Environment.OSVersion.Version.Major >= 6) if (DwmGetWindowAttribute(hwnd, 9 /*DwmwaExtendedFrameBounds*/, out pos, Marshal.SizeOf(typeof(Native.RECT))) == 0) win.visible = pos.ToRectangle(); return win; }
private WinInfo GetWindowInfo() { Screen currentScreen = DpiUtil.GetScreenByHandle(Handle); System.Drawing.Rectangle workArea = currentScreen.WorkingArea; WinInfo winInfo = new WinInfo(); winInfo.maxCx = Math.Abs(workArea.Right - workArea.Left); winInfo.maxCy = Math.Abs(workArea.Bottom - workArea.Top); return(winInfo); }
public void AdjustWindowSize() { if (this._maximized) { return; } try { WinInfo winInfo = GetWindowInfo(); uint dpiX = 0; uint dpiY = 0; Screen currentScreen = DpiUtil.GetScreenByHandle(Handle); DpiUtil.GetDpiByScreen(currentScreen, out dpiX, out dpiY); double ratioX = ((double)dpiX / 96d); double ratioY = ((double)dpiY / 96d); double maxCx = (double)winInfo.maxCx / ratioX; double maxCy = (double)winInfo.maxCy / ratioY; log.InfoFormat("Adjust window size, width={0}, height={1}, maxCx={2}, maxCy={3}, left={4}, top={5}, WindowState={6}, hash code={7}", this.Width, this.Height, maxCx, maxCy, this.Left, this.Top, this.WindowState, this.GetHashCode()); // when the screen size is less than the specified size of main window, then set the size of main window // to a proper size. if (_initialWidth >= maxCx || _initialHeight >= maxCy) { double ratio = _initialWidth / (_initialHeight - _titlebarHeight); if ((maxCx / (maxCy - _titlebarHeight)) > ratio) { this.Height = maxCy; this.Width = (maxCy - _titlebarHeight) * ratio; } else { this.Width = maxCx; this.Height = maxCx / ratio + _titlebarHeight; } Utils.MySetWindowPos(Handle, new Rect(currentScreen.Bounds.Left + (currentScreen.Bounds.Width - this.Width * ratioX) / 2, currentScreen.Bounds.Top + (currentScreen.Bounds.Height - this.Height * ratioY) / 2, this.Width * ratioX, this.Height * ratioY)); log.InfoFormat("window size is adjusted, width={0}, height={1}, hash code={2}", this.Width, this.Height, this.GetHashCode()); //_maxWinWhenLoaded = true; //FullScreenStatus = false; //ChangeWindowState(WindowState.Maximized); } } catch (DllNotFoundException e) { log.Debug("Cannot adjust window size for dll not found."); } }
public override async Task SetUpGameAsync(bool isBeginning) { LoadControls(); if (FinishUpAsync == null) { throw new BasicBlankException("The loader never set the finish up code. Rethink"); } PlayerList.First().Piece = EnumSpaceType.X; PlayerList.Last().Piece = EnumSpaceType.O; SaveRoot !.GameBoard.Clear(); //i think here too. WinInfo thisWin = SaveRoot.GameBoard.GetWin(); _graphics !.ThisWin = thisWin; RepaintBoard(); await FinishUpAsync(isBeginning); }
private void initCruiseWin(int count) { int index = 1; for (int i = 0; i < count; i++) { //设置位置和宽高 WinInfo info = new WinInfo(); info.index = index++; info.width = this._baseWidth; info.height = this._baseHeight; info.x = this._baseWidth * i; info.y = 0; cruisePanelList.Add(info); } }
public void Pop(int playerIndex) { if (isCharacterSelectionLocked) { Stack <WinInfo> stack = playerIndex == 0 ? ref P1WinInfo : ref P2WinInfo; List <WinInfo> listToChange = playerIndex == 0 ? P1CharacterSelection : P2CharacterSelection; WinInfo w = stack.Pop(); WinInfo winInfoInList = listToChange.Find(find => find == w); winInfoInList.isKilled = true; } else { Stack <WinInfo> stackToChange = playerIndex == 0 ? P1WinInfo : P2WinInfo; stackToChange.Pop(); } }
internal void Restore(object sender, EventArgs e) // ignore extra params // first, restore the window rectangles and normal/maximized/minimized states { foreach (var placement in m_infos) { // this might error out if the window no longer exists WinInfo win = placement.Value; // make sure window will be inside a monitor Rectangle newpos = GetRectInsideNearestMonitor(win); #if DEBUG Rectangle real = win.position; Rectangle rect = win.visible; Rectangle monitorRect = Screen.GetWorkingArea(rect); if (newpos != real) { // For debugging purpose, output window title with handle int textLength = 256; System.Text.StringBuilder outText = new System.Text.StringBuilder(textLength + 1); GetWindowText(placement.Key, outText, outText.Capacity); Debug.WriteLine("[" + placement.Key + ": " + outText + "] " + "Moving " + real + "→" + newpos + " in monitor " + monitorRect); } #endif if (!SetWindowPos(placement.Key, 0, newpos.Left, newpos.Top, newpos.Width, newpos.Height, 0x0004 /*NOZORDER*/)) { Debug.WriteLine("Can't move window " + placement.Key + ": " + GetLastError()); } } // now update the z-orders m_windowsBackToTop = m_windowsBackToTop.FindAll(IsWindowVisible); IntPtr positionStructure = BeginDeferWindowPos(m_windowsBackToTop.Count); for (int i = 0; i < m_windowsBackToTop.Count; i++) { positionStructure = DeferWindowPos(positionStructure, m_windowsBackToTop[i], i == 0 ? IntPtr.Zero : m_windowsBackToTop[i - 1], 0, 0, 0, 0, DeferWindowPosCommands.SWP_NOMOVE | DeferWindowPosCommands.SWP_NOSIZE | DeferWindowPosCommands.SWP_NOACTIVATE); } EndDeferWindowPos(positionStructure); }
internal void Restore(object sender, EventArgs e) { // ignore extra params // first, restore the window rectangles and normal/maximized/minimized states foreach (var placement in m_infos) { // this might error out if the window no longer exists WinInfo win = placement.Value; // make sure window will be inside a monitor Rectangle newpos = GetRectInsideNearestMonitor(win); if (!SetWindowPos(placement.Key, 0, newpos.Left, newpos.Top, newpos.Width, newpos.Height, 0x0004 /*NOZORDER*/)) Debug.WriteLine("Can't move window " + placement.Key + ": " + GetLastError()); } // now update the z-orders m_windowsBackToTop = m_windowsBackToTop.FindAll(IsWindowVisible); IntPtr positionStructure = BeginDeferWindowPos(m_windowsBackToTop.Count); for (int i = 0; i < m_windowsBackToTop.Count; i++) { positionStructure = DeferWindowPos(positionStructure, m_windowsBackToTop[i], i == 0 ? IntPtr.Zero : m_windowsBackToTop[i - 1], 0, 0, 0, 0, DeferWindowPosCommands.SWP_NOMOVE | DeferWindowPosCommands.SWP_NOSIZE | DeferWindowPosCommands.SWP_NOACTIVATE); } EndDeferWindowPos(positionStructure); }
private bool EvalWindow(int hwndInt, int lParam) { var hwnd = new IntPtr(hwndInt); if (!IsAltTabWindow(hwnd)) return true; // EnumWindows returns windows in Z order from back to front m_windowsBackToTop.Add(hwnd); WinInfo win = GetWindowInfo(hwnd); m_infos.Add(hwnd, win); #if DEBUG // For debugging purpose, output window title with handle int textLength = 256; System.Text.StringBuilder outText = new System.Text.StringBuilder(textLength + 1); int a = GetWindowText(hwnd, outText, outText.Capacity); Debug.WriteLine(hwnd + " " + win.position + " " + outText); #endif return true; }
private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); //kewl - anony methods in c# - almost as good as java now! WinApi.EnumDesktopWindows(IntPtr.Zero, delegate(IntPtr win, int i) { //filter the windows: if (win == Handle) { //not ourselves } else if ((WinApi.GetWindowLongPtr(win, -20).ToInt32() & 0x00000080) > 0) { //tool window } else if (!WinApi.IsWindowVisible(win)) { //window not visible } else { //maybe.... StringBuilder sb = new StringBuilder(); WinApi.GetWindowText(win, sb, 100); if (sb.Length > 0) { //THIS is a good window! WinInfo wi = new WinInfo(); wi.title = sb.ToString(); wi.win = win; listBox1.Items.Add(wi); } } return(true); }, IntPtr.Zero); }
private static Rectangle GetRectInsideNearestMonitor(WinInfo win) { Rectangle real = win.position; Rectangle rect = win.visible; Rectangle monitorRect = Screen.GetWorkingArea(rect); // use workspace coordinates Rectangle y = new Rectangle( Math.Max(monitorRect.Left, Math.Min(monitorRect.Right - rect.Width, rect.Left)), Math.Max(monitorRect.Top, Math.Min(monitorRect.Bottom - rect.Height, rect.Top)), Math.Min(monitorRect.Width, rect.Width), Math.Min(monitorRect.Height, rect.Height) ); if (rect != real) // support different real and visible position { y = new Rectangle( y.Left - rect.Left + real.Left, y.Top - rect.Top + real.Top, y.Width - rect.Width + real.Width, y.Height - rect.Height + real.Height ); } return(y); }
public void OnSelectionLocked() { isCharacterSelectionLocked = true; //I tried encapsulating but was getting a bunch of null references // Because we are only 2 players it should be fine for now if (P1CharacterSelection == null) { P1CharacterSelection = new List <WinInfo>(); } P1CharacterSelection.Clear(); WinInfo[] arr = new WinInfo[P1WinInfo.Count]; P1WinInfo.CopyTo(arr, 0); for (int i = 0; i < arr.Length; i++) { Debug.Log(arr[i].ToString()); P1CharacterSelection.Add(arr[i]); } if (P2CharacterSelection == null) { P2CharacterSelection = new List <WinInfo>(); } P2CharacterSelection.Clear(); WinInfo[] arr1 = new WinInfo[P2WinInfo.Count]; P2WinInfo.CopyTo(arr1, 0); for (int i = 0; i < arr1.Length; i++) { P2CharacterSelection.Add(arr1[i]); } }
private void StepTimer_Tick(object sender, EventArgs e) { // winHandles.Clear(); // winHandles.Add( Win32.FindWindow("Notepad", "todo.txt - Notepad")); MoveWindows.Clear(); Win32.RECT rect = new Win32.RECT(); // first pass select what windows we should maniplate foreach (IntPtr handle in WinHandles) { if(!Win32.GetWindowRect(handle, ref rect)) continue; // if off screen or minimized if (rect.Top == -32000 || (rect.Left == 0 && rect.Top == TaskbarTop)) continue; // if the height is bigger the the vertical space, dont move if (rect.Height > Desktop.Height - Abd.rc.Height || rect.Width > Desktop.Width) continue; if (!WindowPos.ContainsKey(handle)) WindowPos[handle] = new WinInfo(); WinInfo info = WindowPos[handle]; info.Rect = rect; info.Handle = handle; MoveWindows.Add(info); } // of those windows what are the shelves, windows other windows can rest on Shelves.Clear(); foreach (WinInfo info in MoveWindows) { // shelf may need to be broken into multiple pieces depending on whats covering it Recurse = 0; TestShelf(info.Handle, info.Rect); } IntPtr activeWindow = Win32.GetForegroundWindow(); // move the windows according to gravity and the shelf space foreach (WinInfo info in MoveWindows) { IntPtr handle = info.Handle; rect = info.Rect; double dT = (double)(DateTime.Now.Ticks - info.LastRun.Ticks) / (double)TimeSpan.TicksPerSecond; // prevent window from dropping while user is holding it short keyState = Win32.GetKeyState(Win32.VirtualKeyStates.VK_LBUTTON); bool mouseDown = (keyState & Win32.KEY_PRESSED) > 0; Win32.POINT cursorPos; Win32.GetCursorPos(out cursorPos); // used also at end of func // only give window momentum if dragging the header if (mouseDown && activeWindow == handle && rect.Left < cursorPos.X && cursorPos.X < rect.Right && rect.Top < cursorPos.Y && cursorPos.Y < rect.Top + 26) { info.Vx = (double)(cursorPos.X - info.LastX) / dT; info.Vy = (double)(cursorPos.Y - info.LastY) / dT; /*smush - cant resize window while dragging for some reason // if drag started off screen ignore smush if (rect.Right > Abd.rc.Width) { int width = Abd.rc.Width - rect.Left; uint windowStyles = (uint)Win32.GetWindowLongPtr(handle, (int)Win32.GStyles.GWL_STYLE); Win32.SetWindowPos(handle, IntPtr.Zero, rect.Left, rect.Top, width, rect.Height, 0); //Win32.MoveWindow(handle, rect.Left, rect.Top, width, rect.Height, false); } else if (rect.Left < 0) { }*/ } int moveX = 0; int moveY = 0; // move window in x direction if (!mouseDown) { double Ax = 0; if (info.Vx > 0) // moving left, slow down right Ax = -12000; else if (info.Vx < 0) // moving left, slow down right Ax = 12000; // if past right side , bounce back if (rect.Right + moveX > Abd.rc.Width) Ax = -12000; else if (rect.Left + moveX < 0) Ax = 12000; // calc the amount of next move given current velocity and acceleration during time change moveX = (int)(info.Vx * dT + Ax * Math.Pow(dT, 2)); // x = vt + at^2 // if passing right side if (rect.Right < Abd.rc.Width && rect.Right + moveX > Abd.rc.Width) { moveX = Bounce(dT, Abd.rc.Width - rect.Right, ref info.Vx, Ax); // if still past bounds after second bounce, move into place if (rect.Right + moveX > Abd.rc.Width) { info.Vx = 0; moveX = Abd.rc.Width - rect.Right; } } // if passing left side else if (rect.Left > 0 && rect.Left + moveX < 0) { moveX = Bounce(dT, -rect.Left, ref info.Vx, Ax); // if still past bounds after second bounce, move into place if (rect.Left + moveX < 0) { info.Vx = 0; moveX = 0 - rect.Left; } } // if window coast in x in one direction and starts going in other, then stop it double newVx = info.Vx + Ax * dT; if (info.Vx > 0 && newVx < 0) // moving left info.Vx = 0; else if (info.Vx < 0 && newVx > 0) // moving right info.Vx = 0; else info.Vx = newVx; } // not on taskbar and mouse not down, drop it or pop it if (!(mouseDown && activeWindow == handle) && !OnShelf(info)) { double Ay = 0; // if the top is above the taskbar move down if (rect.Bottom < TaskbarTop) Ay = DownAcceleration; // else the bottom is below the taskbar, move up else Ay = UpAcceleration; moveY = (int)(info.Vy * dT + Ay * Math.Pow(dT, 2)); // x = vt + at^2 // if moving down, set target shelf if (Ay > 0) info.TargetShelf = GetTargetShelf(info); // bounce - if accelerating down, and moving through bottom if (Ay > 0 && rect.Bottom + moveY > info.TargetShelf) { moveY = Bounce(dT, info.TargetShelf - rect.Bottom, ref info.Vy, Ay); // if still below taskbar, thats two bounces below, end it here if (rect.Bottom + moveY > info.TargetShelf) { info.Vy = 0; moveY = info.TargetShelf - rect.Bottom; } } // not hitting anything, move normally else { // v = a * t info.Vy = info.Vy + Ay * dT; } //System.Diagnostics.Debug.WriteLine(DateTime.Now.Millisecond.ToString() + " - h:" + handle.ToString() + " x:" + (rect.Top + moveY).ToString() + " dx:" + moveY.ToString() + " v:" + info.Vy.ToString()); } if (moveY != 0 || moveX != 0) Win32.MoveWindow(handle, rect.Left + moveX, rect.Top + moveY, rect.Width, rect.Height, false); // always set this if either run move or not info.LastRun = DateTime.Now; info.LastX = cursorPos.X; info.LastY = cursorPos.Y; } }
private int GetTargetShelf(WinInfo info) { Win32.RECT rect = info.Rect; int closest = int.MaxValue; int shelfTop = TaskbarTop; // check taskbar top if (TaskbarTop - rect.Bottom > 0 && TaskbarTop - rect.Bottom < closest) { closest = TaskbarTop - rect.Bottom; shelfTop = TaskbarTop; } // no way to check which window is above what yet, see button click for options // check all MoveWindows foreach (Win32.RECT shelf in Shelves) if (shelf != rect && shelf.Top - rect.Bottom > 0 && shelf.Top - rect.Bottom < closest) if ((shelf.Left < rect.Right && rect.Right < shelf.Right) || (shelf.Left < rect.Left && rect.Left < shelf.Right) || (rect.Left < shelf.Left && shelf.Right < rect.Right)) { closest = shelf.Top - rect.Bottom; shelfTop = shelf.Top; } return shelfTop; }
bool OnShelf(WinInfo info) { Win32.RECT rect = info.Rect; // check taskbar top if (TaskbarTop == rect.Bottom) return true; // check all MoveWindows foreach(Win32.RECT shelf in Shelves) if (shelf != rect && shelf.Top == rect.Bottom) if ((shelf.Left < rect.Right && rect.Right < shelf.Right) || (shelf.Left < rect.Left && rect.Left < shelf.Right) || (rect.Left < shelf.Left && shelf.Right < rect.Right)) return true; return false; }
/// <summary> /// 初始化扩展布局的窗口信息 /// 对应的窗口数量是: /// 1->1*1 /// 2,3,4->2*2 /// 5,6,9->3*3 /// 7,8,10~16->4*4 /// </summary> private void initExtWin() { videoPanelMap[1] = basePanelMap[1]; videoPanelMap[2] = basePanelMap[2]; videoPanelMap[3] = basePanelMap[2]; videoPanelMap[4] = basePanelMap[2]; videoPanelMap[9] = basePanelMap[3]; videoPanelMap[10] = basePanelMap[4]; videoPanelMap[11] = basePanelMap[4]; videoPanelMap[12] = basePanelMap[4]; videoPanelMap[13] = basePanelMap[4]; videoPanelMap[14] = basePanelMap[4]; videoPanelMap[15] = basePanelMap[4]; videoPanelMap[16] = basePanelMap[4]; //初始化窗口是5,6个的模板 List <WinInfo> playerWinInfos = new List <WinInfo>(); List <WinInfo> tempPlayerWinInfos = basePanelMap[3]; //1号窗口 WinInfo info = infoCp(tempPlayerWinInfos[0]); info.width = info.width * 2; info.height = info.height * 2; playerWinInfos.Add(info); playerWinInfos.Add(tempPlayerWinInfos[2]); playerWinInfos.Add(tempPlayerWinInfos[5]); playerWinInfos.Add(tempPlayerWinInfos[6]); playerWinInfos.Add(tempPlayerWinInfos[7]); playerWinInfos.Add(tempPlayerWinInfos[8]); resetIndex(playerWinInfos); videoPanelMap[5] = playerWinInfos; videoPanelMap[6] = playerWinInfos; //初始化窗口是7,8个的模板 playerWinInfos = new List <WinInfo>(); tempPlayerWinInfos = basePanelMap[4]; //1号窗口 info = infoCp(tempPlayerWinInfos[0]); info.width = info.width * 3; info.height = info.height * 3; playerWinInfos.Add(info); playerWinInfos.Add(tempPlayerWinInfos[3]); playerWinInfos.Add(tempPlayerWinInfos[7]); playerWinInfos.Add(tempPlayerWinInfos[11]); playerWinInfos.Add(tempPlayerWinInfos[12]); playerWinInfos.Add(tempPlayerWinInfos[13]); playerWinInfos.Add(tempPlayerWinInfos[14]); playerWinInfos.Add(tempPlayerWinInfos[15]); resetIndex(playerWinInfos); videoPanelMap[7] = playerWinInfos; videoPanelMap[8] = playerWinInfos; logger.Info("初始化窗口模板完成。。。"); }