コード例 #1
0
ファイル: Screenshot.cs プロジェクト: jenifly/THelper
 private void Screenshot_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left && e.Clicks == 1)
     {
         if (cancelRect.Contains(e.Location))
         {
             Cache.existOCR = false;
             Dispose();
         }
         if (completRect.Contains(e.Location))
         {
             ExecCutImage();
         }
         if (startPoint == Point.Empty)
         {
             startPoint       = e.Location;
             screenshotStatus = ScreenshotStatus.SCREENSHOTSTART;
         }
         else if (trimType != TrimType.NONE)
         {
             screenshotStatus = ScreenshotStatus.SCREENSHOTTRIM;
         }
     }
     if (e.Button == MouseButtons.Right)
     {
         Cache.existOCR = false;
         Dispose();
     }
     if (e.Button == MouseButtons.Left && e.Clicks == 2)
     {
         ExecCutImage();
     }
 }
コード例 #2
0
        private void StopScreeshot()
        {
            this.Visible = false;

            this.ScreenshotStatus = ScreenshotStatus.None;
            this.OperatorStatus   = OperatorStatus.None;
            this.Cursor           = Cursors.Default;
        }
コード例 #3
0
ファイル: Screenshot.cs プロジェクト: jenifly/THelper
 private void Screenshot_MouseUp(object sender, MouseEventArgs e)
 {
     screenshotStatus = ScreenshotStatus.SCREENSHOTEND;
     trim_X           = 0;
     trim_Y           = 0;
     foreach (KeyValuePair <int, Rectangle> pair in blockDic)
     {
         if (pair.Key > 0)
         {
             pair.Value.Inflate(2, 2);
         }
     }
 }
コード例 #4
0
        private void StartScreenshot()
        {
            Debug.WriteLine($"DESKTOP:{PrimaryScreen.DESKTOP.Width},{PrimaryScreen.DESKTOP.Height}");
            Debug.WriteLine($"WorkingArea:{Screen.PrimaryScreen.WorkingArea.Width},{Screen.PrimaryScreen.WorkingArea.Height}");
            Debug.WriteLine($"DPI:{PrimaryScreen.DpiX},{PrimaryScreen.DpiY}");
            Debug.WriteLine($"Scale:{PrimaryScreen.ScaleX},{PrimaryScreen.ScaleY}");


            Scale_X = PrimaryScreen.ScaleX;
            Scale_Y = PrimaryScreen.ScaleY;

            var size   = PrimaryScreen.DESKTOP;
            var width  = size.Width;
            var height = size.Height;

            RealScreenImage = new Bitmap(width, height);
            using (Graphics graphics = Graphics.FromImage(RealScreenImage))
            {
                graphics.CopyFromScreen(0, 0, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);

                if (Scale_X > 1 || Scale_Y > 1)
                {
                    Bitmap imageSRC = new Bitmap(this.Width, this.Height);
                    using (Graphics g = Graphics.FromImage(imageSRC))
                    {
                        Rectangle rectSrc = new Rectangle(0, 0, width, height);
                        Rectangle rectDes = new Rectangle(0, 0, this.Width, this.Height);
                        g.DrawImage(RealScreenImage, rectDes, rectSrc, GraphicsUnit.Pixel);

                        ScreenSrcImage?.Dispose();
                        ScreenSrcImage = imageSRC;
                    }
                }
                else
                {
                    ScreenSrcImage?.Dispose();
                    ScreenSrcImage = RealScreenImage;
                }
            }

            this.ScreenshotStatus = ScreenshotStatus.Screenshoting;
            this.Visible          = true;
        }
コード例 #5
0
ファイル: pb_UV_Editor.cs プロジェクト: itubeasts/I-eaT-U
	void OnGUI()
	{
		if(screenshotStatus != ScreenshotStatus.Done)
		{
			this.minSize = new Vector2(ScreenRect.width, ScreenRect.height);
			this.maxSize = new Vector2(ScreenRect.width, ScreenRect.height);

			pb_GUI_Utility.DrawSolidColor(new Rect(-1, -1, ScreenRect.width + 10, ScreenRect.height + 10), screenshot_backgroundColor);

			DrawUVGraph(graphRect);

			if(screenshotStatus == ScreenshotStatus.PrepareCanvas)
			{
				if(Event.current.type == EventType.Repaint)
				{
					screenshotStatus = ScreenshotStatus.CanvasReady;
					Screenshot();
				}

				return;
			}
			else
			{
				Screenshot();
			}
		}		

		if(tool == Tool.View || m_draggingCanvas)	
			EditorGUIUtility.AddCursorRect(new Rect(0,toolbarRect.y + toolbarRect.height,screenWidth,screenHeight), MouseCursor.Pan);

		ScreenRect.width = Screen.width;
		ScreenRect.height = Screen.height;

		/**
		 * if basic skin, manually tint the background
		 */
		if(!EditorGUIUtility.isProSkin)
		{
			GUI.backgroundColor = BasicBackgroundColor; //new Color(.13f, .13f, .13f, .7f);
			GUI.Box(ScreenRect, "");
			GUI.backgroundColor = Color.white;
		}
		
		#if PB_DEBUG
		profiler.BeginSample("pb_UV_Editor::OnGUI");
		profiler.BeginSample("GUI Calculations");
		#endif

		if(Screen.width != screenWidth || Screen.height != screenHeight)
			OnScreenResize();

		toolbarRect = new Rect(PAD, PAD, Screen.width-PAD*2, 29);
		graphRect = new Rect(PAD, PAD, Screen.width-PAD*2, Screen.height-PAD*2);

		actionWindowRect.x = (int)Mathf.Clamp(actionWindowRect.x, PAD, Screen.width-PAD-PAD-actionWindowRect.width);
		actionWindowRect.y = (int)Mathf.Clamp(actionWindowRect.y, PAD, Screen.height-MIN_ACTION_WINDOW_SIZE);
		actionWindowRect.height = (int)Mathf.Min(Screen.height - actionWindowRect.y - 24, 350);
		switch(mode)
		{
			case UVMode.Manual:
			case UVMode.Mixed:
				actionWindowRect.width = ACTION_WINDOW_WIDTH_MANUAL;
				break;

			case UVMode.Auto:
				actionWindowRect.width = ACTION_WINDOW_WIDTH_AUTO;
				break;
		}

		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("HandleInput");
		#endif

		// Mouse drags, canvas movement, etc
		HandleInput();
		
		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("DrawUVGraph");
		#endif

		try{
			DrawUVGraph( graphRect );		
		} catch(System.Exception e) {

		}

		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("Tools");
		#endif

		// Draw AND update translation handles
		if(selection != null && selectedUVCount > 0)
		{
			switch(tool)
			{
				case Tool.Move:
					MoveTool();
					break;

				case Tool.Rotate:
					RotateTool();
					break;
			
				case Tool.Scale:
					ScaleTool();
					break;
			}
		}

		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("UpdateNearestElement");
		#endif

		if(UpdateNearestElement(Event.current.mousePosition))
			Repaint();
		
		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("MouseDrag");
		#endif

		if(m_mouseDragging && !modifyingUVs && !m_draggingCanvas && !m_rightMouseDrag)
		{
			Color oldColor = GUI.backgroundColor;
			GUI.backgroundColor = DRAG_BOX_COLOR;
			GUI.Box(dragRect, "");
			GUI.backgroundColor = oldColor;
		}

		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("DrawUVTools");
		#endif

		DrawUVTools(toolbarRect);

		#if PB_DEBUG
		profiler.EndSample();
		profiler.BeginSample("DrawActionWindow");
		#endif

		BeginWindows();
			actionWindowRect = GUILayout.Window( 1, actionWindowRect, DrawActionWindow, "Actions" );
		EndWindows();

		#if PB_DEBUG
		profiler.EndSample();
		#endif

		if(needsRepaint)
		{
			Repaint();
			needsRepaint = false;
		}

		#if PB_DEBUG
		profiler.EndSample();
		#endif

		#if PB_DEBUG
		buggerRect = new Rect(Screen.width - 226, PAD, 220, 300);
		DrawDebugInfo(buggerRect);
		#endif
	}
コード例 #6
0
ファイル: pb_UV_Editor.cs プロジェクト: itubeasts/I-eaT-U
	void Screenshot()
	{
		switch(screenshotStatus)
		{
				// A new screenshot has been initiated
			case ScreenshotStatus.Done:
				curUvScale = uvGraphScale;
				curUvPosition = uvCanvasOffset;

				uvGraphScale = screenshot_size / 256;
				// always begin texture grabs at bottom left
				uvCanvasOffset = new Vector2(-ScreenRect.width/2f, ScreenRect.height/2f);

				screenshot = new Texture2D(screenshot_size, screenshot_size);
				screenshot.hideFlags = (HideFlags)( 1 | 2 | 4 );
				screenshotStatus = ScreenshotStatus.PrepareCanvas;

				// set the current rect pixel boudns to the largest possible size.  if some parts are out of focus, they'll be grabbed in subsequent
				// passes
				screenshotCanvasRect = new Rect(0, 0, (int)Mathf.Min(screenshot_size, ScreenRect.width), (int)Mathf.Min(screenshot_size, ScreenRect.height) );
				screenshotTexturePosition = new Vector2(0,0);

				this.ShowNotification(new GUIContent("Rendering UV Graph\n..."));
				
				Repaint();

				return;

			case ScreenshotStatus.CanvasReady:
					
				// take screenshots vertically, then move right, repeat if necessary
				if(screenshotTexturePosition.y < screenshot_size)
				{
					screenshot.ReadPixels(screenshotCanvasRect, (int)screenshotTexturePosition.x, (int)screenshotTexturePosition.y);

					screenshotTexturePosition.y += screenshotCanvasRect.height;

					if(screenshotTexturePosition.y < screenshot_size)
					{
						// reposition canvas
						uvCanvasOffset.y += screenshotCanvasRect.height;
						screenshotCanvasRect.height = (int)Mathf.Min(screenshot_size - screenshotTexturePosition.y, ScreenRect.height);
						screenshotStatus = ScreenshotStatus.PrepareCanvas;
						Repaint();
						return;
					}
					else
					{
						screenshotTexturePosition.x += screenshotCanvasRect.width;

						if(screenshotTexturePosition.x < screenshot_size)
						{
							uvCanvasOffset.x -= screenshotCanvasRect.width;	// move canvas offset to right
							uvCanvasOffset.y = ScreenRect.height/2f;	// reset canvas offset y value
							screenshotCanvasRect.width = (int)Mathf.Min(screenshot_size - screenshotTexturePosition.x, ScreenRect.width);
							screenshotTexturePosition.y = 0;
							screenshotStatus = ScreenshotStatus.PrepareCanvas;
							Repaint();
							return;
						}
					}
				}

				// reset the canvas to it's original position and scale
				uvGraphScale = curUvScale;
				uvCanvasOffset = curUvPosition;

				this.RemoveNotification();
				screenshotStatus = ScreenshotStatus.RenderComplete;
				Repaint();
				break;

			case ScreenshotStatus.RenderComplete:

				if(screenshot_transparentBackground)
				{
					Color[] px = screenshot.GetPixels(0);

					for(int i = 0; i < px.Length; i++)

						if( Mathf.Abs(px[i].r - UV_FILL_COLOR.r) < .01f && 
						 	Mathf.Abs(px[i].g - UV_FILL_COLOR.g) < .01f && 
						  	Mathf.Abs(px[i].b - UV_FILL_COLOR.b) < .01f )
							px[i] = Color.clear;

					screenshot.SetPixels(px);
					screenshot.Apply();
				}

				EditorApplication.delayCall += SaveUVRender;	// don't run the save image stuff in the UI loop
				screenshotStatus = ScreenshotStatus.Done;
				break;
		}
	}
コード例 #7
0
ファイル: pb_UV_Editor.cs プロジェクト: itubeasts/I-eaT-U
	readonly Color UV_FILL_COLOR = new Color(.192f,.192f,.192f,1f);	///< This is the default background of the UV editor - used to compare bacground pixels when rendering UV template

	void Screenshot(int ImageSize, bool HideGrid, Color LineColor, bool TransparentBackground, Color BackgroundColor)
	{
		screenshot_size = ImageSize;
		screenshot_hideGrid = HideGrid;
		screenshot_lineColor = LineColor;
		screenshot_transparentBackground = TransparentBackground;
		screenshot_backgroundColor = TransparentBackground ? UV_FILL_COLOR : BackgroundColor;

		// if line color and background color are the same but we want transparent backgruond,
		// make sure that the background fill will be distinguishable from the lines during the
		// opacity wipe
		if(TransparentBackground && (screenshot_lineColor.Approx(screenshot_backgroundColor, .01f)))
		{
			screenshot_backgroundColor.r += screenshot_backgroundColor.r < .9f ? .1f : -.1f;
			screenshot_backgroundColor.g += screenshot_backgroundColor.g < .9f ? .1f : -.1f;
			screenshot_backgroundColor.b += screenshot_backgroundColor.b < .9f ? .1f : -.1f;
		}

		screenshot_path = EditorUtility.SaveFilePanel("Save UV Template", Application.dataPath, "", "png");
		if(screenshot_path == "")
			return;

		screenshotStatus = ScreenshotStatus.Done;
		Screenshot();
	}