From 96d2b4c4e6e5e2bffc615207ea7cab4b3c91c122 Mon Sep 17 00:00:00 2001 From: koldo Date: Fri, 18 Dec 2015 23:08:05 +0000 Subject: [PATCH] GrabYourScreen: If you can watch it you can grab it git-svn-id: svn://ultimatepp.org/upp/trunk@9307 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/GrabYourScreen/GrabBook.cpp | 146 +++++++++++++++++++++++ bazaar/GrabYourScreen/GrabScreen.cpp | 142 ++++++++++++++++++++++ bazaar/GrabYourScreen/GrabYourScreen.h | 60 ++++++++++ bazaar/GrabYourScreen/GrabYourScreen.lay | 50 ++++++++ bazaar/GrabYourScreen/GrabYourScreen.upp | 20 ++++ bazaar/GrabYourScreen/icon.ico | Bin 0 -> 2862 bytes bazaar/GrabYourScreen/icon16x16.png | Bin 0 -> 662 bytes bazaar/GrabYourScreen/iml.iml | 28 +++++ bazaar/GrabYourScreen/init | 7 ++ bazaar/GrabYourScreen/main.cpp | 32 +++++ bazaar/GrabYourScreen/rc.rc | 1 + 11 files changed, 486 insertions(+) create mode 100644 bazaar/GrabYourScreen/GrabBook.cpp create mode 100644 bazaar/GrabYourScreen/GrabScreen.cpp create mode 100644 bazaar/GrabYourScreen/GrabYourScreen.h create mode 100644 bazaar/GrabYourScreen/GrabYourScreen.lay create mode 100644 bazaar/GrabYourScreen/GrabYourScreen.upp create mode 100644 bazaar/GrabYourScreen/icon.ico create mode 100644 bazaar/GrabYourScreen/icon16x16.png create mode 100644 bazaar/GrabYourScreen/iml.iml create mode 100644 bazaar/GrabYourScreen/init create mode 100644 bazaar/GrabYourScreen/main.cpp create mode 100644 bazaar/GrabYourScreen/rc.rc diff --git a/bazaar/GrabYourScreen/GrabBook.cpp b/bazaar/GrabYourScreen/GrabBook.cpp new file mode 100644 index 000000000..ecfe3aa11 --- /dev/null +++ b/bazaar/GrabYourScreen/GrabBook.cpp @@ -0,0 +1,146 @@ +#include "GrabYourScreen.h" + +GrabBook::GrabBook() { + CtrlLayout(*this); +} + +void GrabBook::Init() { + initialPage = 0; + actualPage = 0; + left <<= 100; + right <<= 1200; + up <<= 100; + down <<= 900; + split = true; + + folder = AppendFileName(GetDesktopFolder(), "Libro"); + + canvas.SetShowWindow(false); + + canvas.WhenPaint = THISBACK(OnPaint); + reset.WhenAction = THISBACK(OnReset); + capture.WhenAction = THISBACK(OnCapture); + savePDF.WhenAction = THISBACK(OnSavePDF); + SetTimeCallback(-1000, THISBACK(Timer)); + + keyId = Ctrl::RegisterSystemHotKey(K_CTRL | K_F10, THISBACK(OnCapture)); +} + +GrabBook::~GrabBook() { + Ctrl::UnregisterSystemHotKey(keyId); +} + +void GrabBook::OnPaint(Painter &painter) { + painter.Move(left, up).Line(right, up).Line(right, down). + Line(left, down).Line(left, up).Stroke(2, Black()); + painter.Move(left, up).Line(right, down).Stroke(2, Black()); + painter.Move(right, up).Line(left, down).Stroke(2, Black()); +} + +void GrabBook::OnReset() { + actualPage = 0; + initialPage = 0; +} + +void GrabBook::OnCapture() { + Rect rPdf(left, up, right, down); + Rect screenRect; + ::GetWindowRect(GetHWND(), screenRect); + if (rPdf.Intersects(screenRect)) { + Exclamation("Ventana del programa interfiere con imagen a tomar"); + return; + } + + Timer(); + + if (!DirectoryExists(folder)) + RealizeDirectory(folder); + Image img = ::GetRect(canvas.GetBackground(), Rect(left, up, right, down)); + if (!SaveImage(img, 100, AppendFileName(folder, Format("Pag%04d.jpg", int(actualPage))), ".jpg")) + Exclamation("Error saving image"); + actualPage = actualPage + 1; +} + +void GrabBook::OnSavePDF() { + Report r; + + int width, height; + if (split) { + width = 210; + height = 297; + } else { + width = 297; + height = 210; + } + r.SetPageSize((width-5-5)*6000/254, (height-5-5)*6000/254); + r.Margins(5*6000/254, 5*6000/254); + + String fileName; + + FileSel fs; + + fs.ActiveDir(GetDesktopFolder()); + fs.Type("Ficheros PDF", ".pdf"); + + if (fs.ExecuteSaveAs(t_("Saving file"))) + fileName = ~fs; + else + return; + + WaitCursor wait; + + ForceExt(fileName, ".pdf"); + + Size psz = r.GetPageSize(); + for(int i = initialPage; i < actualPage; ++i) { + if (i > 0) + r.NewPage(); + + String fileName = AppendFileName(folder, Format("Pag%04d.jpg", i)); + Image img = StreamRaster::LoadFileAny(fileName); + Image imgIzq, imgDer; + if (split) { + imgIzq = ::GetRect(img, Rect(0, 0, img.GetWidth()/2, img.GetHeight())); + imgDer = ::GetRect(img, Rect(img.GetWidth()/2 + 1, 0, img.GetWidth(), img.GetHeight())); + } else + imgIzq = img; + + DrawingDraw dw(psz.cx, psz.cy); + Rect rect = FitInFrame(psz, imgIzq.GetSize()); + dw.DrawImage(rect, imgIzq); + QtfRichObject qrob(CreateDrawingObject(dw, psz.cx, psz.cy)); + String qtf; + qtf << qrob; + r << qtf; + + if (split) { + r.NewPage(); + DrawingDraw dw(psz.cx, psz.cy); + Rect rect = FitInFrame(psz, imgDer.GetSize()); + dw.DrawImage(rect, imgDer); + QtfRichObject qrob(CreateDrawingObject(dw, psz.cx, psz.cy)); + String qtf; + qtf << qrob; + r << qtf; + } + } + + if (!SaveFile(fileName, UPP::Pdf(r))) { + Exclamation(t_("It is not possible to save file.&Posibly .pdf file is already opened.")); + return; + } + LaunchFile(fileName); +} + +void GrabBook::Timer() { + NON_REENTRANT_V; + + canvas.SetBackground(Snap_Desktop()); +} + +/* +A añadir: +- Seleccion manual de ventana (usando lo de Screen) +- Paso automático de páginas +- Barrido con zoom? +*/ \ No newline at end of file diff --git a/bazaar/GrabYourScreen/GrabScreen.cpp b/bazaar/GrabYourScreen/GrabScreen.cpp new file mode 100644 index 000000000..f9c896d39 --- /dev/null +++ b/bazaar/GrabYourScreen/GrabScreen.cpp @@ -0,0 +1,142 @@ +#include "GrabYourScreen.h" + +GrabScreen::GrabScreen() { + CtrlLayout(*this); +} + +void GrabScreen::Init(GrabYourScreen &_program) { + program = &_program; + editFileNameGrab <<= AppendFileName(GetDesktopFolder(), "ScreenGrab.avi"); + editTime <<= 5; + editFrameRate <<= 1; + opGrabMouse <<= true; + swGrabMode.Add("Desktop"); + swGrabMode.Add("Window"); +#if defined(PLATFORM_WIN32) + swGrabMode.Add("Rectangle"); +#endif + swGrabMode.MinCaseHeight(20); + swGrabMode.SetData(0); + swGrabMode.WhenAction = THISBACK(SwGrabMode_Action); + SwGrabMode_Action(); +#if defined(PLATFORM_WIN32) + butGrab.WhenPush = THISBACK(ButGrab_Push); +#else + butGrab.Enable(false); + editFileNameGrab.Enable(false); + editTime.Enable(false); + editFrameRate.Enable(false); + opGrabMouse.Enable(false); + editLeft.Hide(); + editTop.Hide(); + editWidth.Hide(); + editHeight.Hide(); + left.Hide(); + top.Hide(); + width.Hide(); + height.Hide(); +#endif + + String extension; +#if defined(PLATFORM_WIN32) + extension = "bmp"; +#else + extension = "xwd"; +#endif + editFileNameSnap <<= AppendFileName(GetDesktopFolder(), "ScreenSnap." + extension); + butSnap.WhenPush = THISBACK(ButSnap_Push); + + Array hWnd, processId; + Array name, fileName, caption; + GetWindowsList(hWnd, processId, name, fileName, caption); + Sort(caption); + for (int i = 0; i < caption.GetCount(); ++i) { + if (!Trim(caption[i]).IsEmpty()) + editWindowTitle.Add(caption[i]); + } + editWindowTitle.SetData(editWindowTitle.GetValue(0)); +} + +void GrabScreen::SwGrabMode_Action() { + switch((int)swGrabMode.GetData()) { + case 0: + editLeft.Enable(false); + editTop.Enable(false); + editWidth.Enable(false); + editHeight.Enable(false); + editWindowTitle.Enable(false); + break; + case 1: + editLeft.Enable(false); + editTop.Enable(false); + editWidth.Enable(false); + editHeight.Enable(false); + editWindowTitle.Enable(true); + break; + case 2: + editLeft.Enable(true); + editTop.Enable(true); + editWidth.Enable(true); + editHeight.Enable(true); + editWindowTitle.Enable(false); + break; + } +} + +void GrabScreen::ButGrab_Push() { +#if defined(PLATFORM_WIN32) + FileDelete(editFileNameGrab.GetData().ToString()); + + bool ret; + if (swGrabMode.GetData() == 0) + ret = Record_Desktop(editFileNameGrab, editTime, editFrameRate, opGrabMouse); + else if (swGrabMode.GetData() == 1) + ret = Record_Window(editFileNameGrab, editTime, GetWindowIdFromCaption(~editWindowTitle, false), editFrameRate, opGrabMouse); + else if (swGrabMode.GetData() == 2) + ret = Record_DesktopRectangle(editFileNameGrab, editTime, editLeft, editTop, editWidth, editHeight, editFrameRate, opGrabMouse); + else + throw Exc("Unexpected value"); + if (!ret) + Exclamation("Error on grabbing"); +#endif +} + +void GrabScreen::ButSnap_Push() { + program->Minimize(); + + TopWindow win; + Button b; + b.SetLabel("CLOSE"); + b <<= win.Breaker(); + StaticImage image; + image.Set(Snap_Desktop()); + win.Add(image.SizePos()); + win.Add(b.LeftPos(10, 100).TopPos(10, 30)); + + win.FullScreen().Run(); + + program->Overlap(); + return; + + + + FileDelete(editFileNameSnap.GetData().ToString()); + + if (swGrabMode.GetData() == 0) + Snap_Desktop(editFileNameSnap); + else if (swGrabMode.GetData() == 1) + Snap_Window(editFileNameSnap, GetWindowIdFromCaption(~editWindowTitle, false)); + else if (swGrabMode.GetData() == 2) + Snap_DesktopRectangle(editFileNameSnap, editLeft, editTop, editWidth, editHeight); + else + throw Exc("Unexpected value"); +} + +/* +A añadir: +- Listado de ventanas en Window Title +- Pantalla completa para seleccionar. Meterlo en Controls4U +- Jsonize para todos +- Que deje salir si un campo está vacio +- Ficheros con EditFile +*/ diff --git a/bazaar/GrabYourScreen/GrabYourScreen.h b/bazaar/GrabYourScreen/GrabYourScreen.h new file mode 100644 index 000000000..03c0e1953 --- /dev/null +++ b/bazaar/GrabYourScreen/GrabYourScreen.h @@ -0,0 +1,60 @@ +#ifndef _GrabYourScreen_GrabYourScreen_h +#define _GrabYourScreen_GrabYourScreen_h + +#include +#include +#include +#include +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +class GrabYourScreen; + +class GrabScreen : public WithScreen { +public: + typedef GrabScreen CLASSNAME; + GrabScreen(); + + void Init(GrabYourScreen &program); + void ButGrab_Push(); + void ButSnap_Push(); + void SwGrabMode_Action(); + +private: + GrabYourScreen *program; +}; + +class GrabBook : public WithBook { +public: + typedef GrabBook CLASSNAME; + GrabBook(); + ~GrabBook(); + + void Init(); + void OnPaint(Painter &painter); + void OnReset(); + void OnCapture(); + void OnSavePDF(); + void Timer(); + + int keyId; + String folder; +}; + +class GrabYourScreen : public TopWindow { +public: + typedef GrabYourScreen CLASSNAME; + GrabYourScreen(); + void Init(); + void Exit(); + + TabCtrl mainTab; + GrabScreen grabScreen; + GrabBook grabBook; +}; + +#endif diff --git a/bazaar/GrabYourScreen/GrabYourScreen.lay b/bazaar/GrabYourScreen/GrabYourScreen.lay new file mode 100644 index 000000000..4cfee8d04 --- /dev/null +++ b/bazaar/GrabYourScreen/GrabYourScreen.lay @@ -0,0 +1,50 @@ +LAYOUT(Book, 368, 292) + ITEM(Button, savePDF, SetLabel(t_("Save PDF")).HSizePosZ(8, 112).TopPosZ(132, 24)) + ITEM(Button, capture, SetLabel(t_("Capture - Ctrl-F10")).HSizePosZ(8, 4).TopPosZ(4, 24)) + ITEM(Label, dv___2, SetLabel(t_("Down:")).LeftPosZ(112, 36).TopPosZ(104, 21)) + ITEM(Label, dv___3, SetLabel(t_("Initial Page")).LeftPosZ(4, 76).TopPosZ(36, 21)) + ITEM(Label, dv___4, SetLabel(t_("Actual Page")).LeftPosZ(84, 76).TopPosZ(36, 21)) + ITEM(EditIntSpin, down, LeftPosZ(148, 56).TopPosZ(104, 19)) + ITEM(Label, dv___6, SetLabel(t_("Right:")).LeftPosZ(112, 36).TopPosZ(84, 21)) + ITEM(EditIntSpin, right, LeftPosZ(148, 56).TopPosZ(84, 19)) + ITEM(Label, dv___8, SetLabel(t_("Up:")).LeftPosZ(8, 36).TopPosZ(104, 21)) + ITEM(EditIntSpin, up, LeftPosZ(44, 64).TopPosZ(104, 19)) + ITEM(Label, dv___10, SetLabel(t_("Left:")).LeftPosZ(8, 36).TopPosZ(84, 21)) + ITEM(EditIntSpin, left, LeftPosZ(44, 64).TopPosZ(84, 19)) + ITEM(EditIntNotNull, initialPage, LeftPosZ(4, 64).TopPosZ(56, 19)) + ITEM(EditIntNotNull, actualPage, LeftPosZ(84, 64).TopPosZ(56, 19)) + ITEM(PainterCanvas, canvas, SetShowWindow(false).SetFrame(ThinInsetFrame()).HSizePosZ(4, 4).VSizePosZ(164, 4)) + ITEM(Button, reset, SetLabel(t_("Reset")).LeftPosZ(156, 48).TopPosZ(52, 24)) + ITEM(Option, split, SetLabel(t_("Split in two")).RightPosZ(4, 84).TopPosZ(136, 16)) +END_LAYOUT + +LAYOUT(Screen, 464, 204) + ITEM(LabelBox, dv___0, SetLabel(t_("Image Snapshot")).LeftPosZ(8, 452).TopPosZ(68, 40)) + ITEM(LabelBox, dv___1, SetLabel(t_("Video Grab")).LeftPosZ(8, 452).TopPosZ(4, 60)) + ITEM(LabelBox, dv___2, SetLabel(t_("Mode")).LeftPosZ(8, 452).TopPosZ(112, 84)) + ITEM(Label, dv___3, SetLabel(t_("secs/frame")).LeftPosZ(220, 56).TopPosZ(40, 19)) + ITEM(Label, top, SetLabel(t_("Top:")).LeftPosZ(176, 24).TopPosZ(168, 19)) + ITEM(Label, width, SetLabel(t_("Width:")).LeftPosZ(256, 36).TopPosZ(168, 19)) + ITEM(Label, height, SetLabel(t_("Height:")).LeftPosZ(348, 40).TopPosZ(168, 19)) + ITEM(EditString, editFileNameSnap, NotNull(true).LeftPosZ(72, 316).TopPosZ(84, 19)) + ITEM(EditString, editFileNameGrab, NotNull(true).LeftPosZ(72, 316).TopPosZ(20, 19)) + ITEM(EditIntNotNull, editTime, Min(1).LeftPosZ(72, 32).TopPosZ(40, 19)) + ITEM(EditDoubleNotNull, editFrameRate, LeftPosZ(196, 24).TopPosZ(40, 19)) + ITEM(Option, opGrabMouse, SetLabel(t_("Grab mouse")).LeftPosZ(288, 76).TopPosZ(44, 16)) + ITEM(Switch, swGrabMode, LeftPosZ(16, 80).TopPosZ(128, 64)) + ITEM(EditInt, editLeft, Min(0).LeftPosZ(120, 44).TopPosZ(168, 19)) + ITEM(EditInt, editTop, Min(0).LeftPosZ(200, 44).TopPosZ(168, 19)) + ITEM(EditInt, editWidth, Min(0).LeftPosZ(292, 44).TopPosZ(168, 19)) + ITEM(EditInt, editHeight, Min(0).LeftPosZ(388, 44).TopPosZ(168, 19)) + ITEM(Label, left, SetLabel(t_("Left:")).LeftPosZ(96, 24).TopPosZ(168, 19)) + ITEM(Label, dv___18, SetLabel(t_("Window Title:")).LeftPosZ(96, 64).TopPosZ(148, 19)) + ITEM(Label, dv___19, SetLabel(t_("File Name:")).LeftPosZ(16, 52).TopPosZ(84, 19)) + ITEM(Label, dv___20, SetLabel(t_("File Name:")).LeftPosZ(16, 52).TopPosZ(20, 19)) + ITEM(Button, butSnap, SetLabel(t_("Snap it!")).LeftPosZ(392, 56).TopPosZ(84, 20)) + ITEM(Button, butGrab, SetLabel(t_("Record it!")).LeftPosZ(392, 56).TopPosZ(20, 40)) + ITEM(Label, dv___23, SetLabel(t_("Frame rate:")).LeftPosZ(140, 56).TopPosZ(40, 19)) + ITEM(Label, dv___24, SetLabel(t_("sec")).LeftPosZ(104, 24).TopPosZ(40, 19)) + ITEM(Label, dv___25, SetLabel(t_("Time:")).LeftPosZ(16, 52).TopPosZ(40, 19)) + ITEM(DropList, editWindowTitle, LeftPosZ(164, 268).TopPosZ(148, 19)) +END_LAYOUT + diff --git a/bazaar/GrabYourScreen/GrabYourScreen.upp b/bazaar/GrabYourScreen/GrabYourScreen.upp new file mode 100644 index 000000000..a559cfed0 --- /dev/null +++ b/bazaar/GrabYourScreen/GrabYourScreen.upp @@ -0,0 +1,20 @@ +description "If you can watch it, you can get it!\377"; + +uses + CtrlLib, + Controls4U, + SysInfo, + Report; + +file + main.cpp, + GrabBook.cpp, + GrabScreen.cpp, + GrabYourScreen.h, + GrabYourScreen.lay, + iml.iml, + rc.rc; + +mainconfig + "" = "GUI SSE2"; + diff --git a/bazaar/GrabYourScreen/icon.ico b/bazaar/GrabYourScreen/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..00a334da6f93e2eb94f508acf31fea90c4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JqoUE(Iec$IuX-GlVme(;*lcV#pX2-8_x#37s@OG{6F_s-p? zY_{~|&-A%HHRjIU@bK`c)Y#Xe+u2gLqSQqlq=R&IsOeNuLF%Ffg_ljS}k&GYiq3-V{Zrn5kW*~Hk*hDwOZ|O z$!u=^BF4z2%U5yEk&7|*j*J|oR@(wVQB*-y(R3jKrJ+Gyzk12>v6F-tQPrftdrz&l z#r?S|U@!(u+A!^C)ayLDa|Y)etJQae5IA`4Mp7UmD2g$Lq0%tcT8y>Wb{K1E)az(W zjAP@c(Wq#<2G)B|R4~SpW!bK$!aDP{86qSFzTF;U4OuSNWjEGhjlo!( zYNLs9{?ikh4MC$O0OuU4DFvHljPC0P)3Jx)`ww-6AUgyi_ ze;X^a8P2)37gDFX3VM2SJiL8^5F_3T+uJQvBfY&nSfeOlO?nHe$&so_!OqUk^z!oC z^Btpj?@NV3VN^ue*w|=gS=MK>3{@DbjC1VBApj2SFC!xCnuY1<>AN9>>l0_sT__Za zyjWcL9YRS9xMe>CLB7t0HnVo&yoSB))?=^JY wVOm{X-K +#define IMAGECLASS Images +#include + +GrabYourScreen::GrabYourScreen() { + Icon(Images::Computer()); + LargeIcon(Images::Computer()); + Sizeable().Zoomable();//.TopMost(true, true); +} + +void GrabYourScreen::Init() { + Title("GrabYourScreen"); + + Add(mainTab.SizePos()); + grabBook.Init(); + mainTab.Add(grabBook.SizePos(), "Book"); + grabScreen.Init(*this); + mainTab.Add(grabScreen.SizePos(), "Screen"); +} + +void GrabYourScreen::Exit() { + Break(); +} + +GUI_APP_MAIN { + GrabYourScreen program; + program.Open(); + program.Init(); + program.Run(); +} diff --git a/bazaar/GrabYourScreen/rc.rc b/bazaar/GrabYourScreen/rc.rc new file mode 100644 index 000000000..9d51e78cf --- /dev/null +++ b/bazaar/GrabYourScreen/rc.rc @@ -0,0 +1 @@ +5555 ICON DISCARDABLE "icon.ico"