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 000000000..00a334da6 Binary files /dev/null and b/bazaar/GrabYourScreen/icon.ico differ diff --git a/bazaar/GrabYourScreen/icon16x16.png b/bazaar/GrabYourScreen/icon16x16.png new file mode 100644 index 000000000..c97b64c02 Binary files /dev/null and b/bazaar/GrabYourScreen/icon16x16.png differ diff --git a/bazaar/GrabYourScreen/iml.iml b/bazaar/GrabYourScreen/iml.iml new file mode 100644 index 000000000..05eb03348 --- /dev/null +++ b/bazaar/GrabYourScreen/iml.iml @@ -0,0 +1,28 @@ +PREMULTIPLIED +IMAGE_ID(Computer) IMAGE_META("exp", "") + + +IMAGE_BEGIN_DATA +IMAGE_DATA(120,156,141,147,223,75,83,97,24,199,149,46,21,242,166,191,69,48,240,162,171,188,8,18,196,44,188,83,112,52,150,203) +IMAGE_DATA(45,83,154,107,130,41,42,139,54,181,150,201,180,72,36,131,185,185,205,114,7,219,230,54,61,30,143,251,225,118,246,195) +IMAGE_DATA(29,119,116,106,132,89,18,68,20,93,124,123,223,55,23,4,37,30,248,114,224,240,124,222,239,247,125,158,231,148,85,149) +IMAGE_DATA(85,149,157,245,49,153,76,147,145,72,228,103,56,28,70,32,16,0,199,113,88,88,88,128,211,233,132,86,171,157,249,31) +IMAGE_DATA(87,89,89,121,126,112,112,240,181,44,203,216,219,123,15,185,176,11,89,86,144,167,202,23,112,116,244,25,211,211,211,248) +IMAGE_DATA(23,91,83,83,115,217,235,245,238,43,138,130,195,195,67,172,9,49,68,86,214,17,10,11,8,134,120,4,131,171,200,230) +IMAGE_DATA(100,216,237,118,196,227,241,31,201,100,146,190,33,138,34,120,158,71,40,20,130,223,239,135,207,231,3,57,135,101,157,157) +IMAGE_DATA(157,101,126,35,35,163,176,88,172,72,103,242,176,217,108,160,236,241,241,23,40,74,145,169,160,236,98,155,102,221,222,249) +IMAGE_DATA(147,53,71,244,241,232,19,243,123,231,143,128,91,10,65,74,111,145,115,44,136,70,163,140,107,188,231,36,114,225,154,193) +IMAGE_DATA(133,166,158,121,52,25,221,184,126,223,131,27,38,47,174,116,204,32,147,149,153,159,217,108,198,208,208,16,82,82,14,195) +IMAGE_DATA(195,195,16,4,129,121,82,78,245,48,140,155,143,86,160,182,242,208,140,10,104,127,44,66,107,139,50,62,157,206,51,191) +IMAGE_DATA(69,46,136,183,139,1,146,59,131,190,190,62,144,217,176,222,54,245,184,161,182,172,66,51,178,134,91,99,235,208,62,217) +IMAGE_DATA(192,237,167,49,232,158,37,24,95,242,123,201,79,161,241,213,85,36,8,111,52,26,217,76,233,92,104,86,202,181,159,112) +IMAGE_DATA(29,132,211,79,108,226,142,61,197,248,100,234,183,223,165,231,23,81,61,90,141,120,34,141,174,174,46,214,99,218,35,122) +IMAGE_DATA(79,154,213,226,200,194,50,151,59,209,22,238,78,165,25,95,242,115,123,56,184,220,28,98,241,20,116,58,29,60,30,15) +IMAGE_DATA(182,73,175,105,205,105,74,73,91,204,207,53,239,195,156,107,17,209,88,10,26,141,6,14,135,3,197,226,62,36,41,131) +IMAGE_DATA(205,164,132,141,104,130,237,201,50,217,19,126,109,131,244,87,36,251,35,146,254,101,137,159,30,14,194,58,230,222,144,186) +IMAGE_DATA(36,84,42,21,154,155,155,205,189,189,189,162,193,96,16,201,249,34,201,88,160,115,30,31,31,167,121,191,211,59,247,15) +IMAGE_DATA(12,224,65,255,0,38,167,94,48,142,234,224,224,3,90,91,91,255,218,223,218,218,218,246,182,182,182,165,224,114,152,229) +IMAGE_DATA(235,236,236,252,86,87,87,55,209,210,210,178,169,215,235,233,255,2,181,90,13,82,3,242,13,245,245,245,153,18,91,81) +IMAGE_DATA(81,113,193,106,181,146,185,74,80,118,138,108,247,20,178,23,164,254,235,89,254,211,242,242,242,115,228,62,52,63,186,187) +IMAGE_DATA(187,81,242,107,104,104,16,78,227,126,1,218,229,112,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) +IMAGE_END_DATA(704, 1) diff --git a/bazaar/GrabYourScreen/init b/bazaar/GrabYourScreen/init new file mode 100644 index 000000000..6e16120b9 --- /dev/null +++ b/bazaar/GrabYourScreen/init @@ -0,0 +1,7 @@ +#ifndef _GrabYourScreen_icpp_init_stub +#define _GrabYourScreen_icpp_init_stub +#include "CtrlLib/init" +#include "Controls4U/init" +#include "SysInfo/init" +#include "Report/init" +#endif diff --git a/bazaar/GrabYourScreen/main.cpp b/bazaar/GrabYourScreen/main.cpp new file mode 100644 index 000000000..60ee33270 --- /dev/null +++ b/bazaar/GrabYourScreen/main.cpp @@ -0,0 +1,32 @@ +#include "GrabYourScreen.h" + +#define IMAGEFILE +#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"