From d13f3daaa2534a941ca08d9605daf032f4b5ea82 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 30 May 2010 17:21:58 +0000 Subject: [PATCH] .upptst git-svn-id: svn://ultimatepp.org/upp/trunk@2442 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- upptst/Fonts/main.cpp | 81 +++++++++++++------------ upptst/ScreenShotter/ScreenShotter.upp | 12 ++++ upptst/ScreenShotter/init | 8 +++ upptst/ScreenShotter/main.cpp | 83 ++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 41 deletions(-) create mode 100644 upptst/ScreenShotter/ScreenShotter.upp create mode 100644 upptst/ScreenShotter/init create mode 100644 upptst/ScreenShotter/main.cpp diff --git a/upptst/Fonts/main.cpp b/upptst/Fonts/main.cpp index bfd98c500..d2bf94943 100644 --- a/upptst/Fonts/main.cpp +++ b/upptst/Fonts/main.cpp @@ -1,41 +1,40 @@ -#include "Fonts.h" - -struct DisplayWithFont : public Display { - void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const - { - ValueArray va = q; - String txt = va[0]; - int face = va[1]; - Font fnt(face, r.Height() - 4); - w.DrawRect(r, paper); - w.DrawText(r.left, r.top + (r.Height() - fnt.Info().GetHeight()) / 2, txt, fnt, ink); - } -}; - -void Fonts::Reload() -{ - list.Clear(); - for(int i = 0; i < Font::GetFaceCount(); i++) - list.Add(Font::GetFaceName(i), ~text, i); -} - -void Fonts::Copy() -{ - if(list.IsCursor()) - WriteClipboardText(list.GetKey()); -} - -Fonts::Fonts() -{ - CtrlLayout(*this, "Font test"); - text <<= THISBACK(Reload); - list.AddColumn("Font"); - list.AddColumn("Text").AddIndex().SetDisplay(Single()); - list.WhenCursor = THISBACK(Copy); -} - -GUI_APP_MAIN -{ - Fonts().Run(); -} - +#include "Fonts.h" + +struct DisplayWithFont : public Display { + void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const + { + ValueArray va = q; + String txt = va[0]; + int face = va[1]; + Font fnt(face, r.Height() - 4); + w.DrawRect(r, paper); + w.DrawText(r.left, r.top + (r.Height() - fnt.Info().GetHeight()) / 2, txt, fnt, ink); + } +}; + +void Fonts::Reload() +{ + list.Clear(); + for(int i = 0; i < Font::GetFaceCount(); i++) + list.Add(Font::GetFaceName(i), ~text, i); +} + +void Fonts::Copy() +{ + if(list.IsCursor()) + WriteClipboardText(list.GetKey()); +} + +Fonts::Fonts() +{ + CtrlLayout(*this, "Font test"); + text <<= THISBACK(Reload); + list.AddColumn("Font"); + list.AddColumn("Text").AddIndex().SetDisplay(Single()); + list.WhenCursor = THISBACK(Copy); +} + +GUI_APP_MAIN +{ + Fonts().Run(); +} diff --git a/upptst/ScreenShotter/ScreenShotter.upp b/upptst/ScreenShotter/ScreenShotter.upp new file mode 100644 index 000000000..a22f22e44 --- /dev/null +++ b/upptst/ScreenShotter/ScreenShotter.upp @@ -0,0 +1,12 @@ +uses + CtrlLib, + plugin\jpg, + plugin\gif, + plugin\tif; + +file + main.cpp; + +mainconfig + "" = "GUI DLL"; + diff --git a/upptst/ScreenShotter/init b/upptst/ScreenShotter/init new file mode 100644 index 000000000..336830065 --- /dev/null +++ b/upptst/ScreenShotter/init @@ -0,0 +1,8 @@ +#ifndef _ScreenShotter_icpp_init_stub +#define _ScreenShotter_icpp_init_stub +#include "CtrlLib/init" +#include "plugin\jpg/init" +#include "plugin\gif/init" +#include "plugin\tif/init" +#include "plugin\pcx/init" +#endif diff --git a/upptst/ScreenShotter/main.cpp b/upptst/ScreenShotter/main.cpp new file mode 100644 index 000000000..9edea5765 --- /dev/null +++ b/upptst/ScreenShotter/main.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + +using namespace Upp; + +Image ScreenShot(int x, int y, int cx, int cy) +{ + HDC dcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); + + RGBA *pixels; + + Buffer data; + data.Alloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256); + BITMAPINFOHEADER *hi = (BITMAPINFOHEADER *) ~data;; + memset(hi, 0, sizeof(BITMAPINFOHEADER)); + hi->biSize = sizeof(BITMAPINFOHEADER); + hi->biPlanes = 1; + hi->biBitCount = 32; + hi->biCompression = BI_RGB; + hi->biSizeImage = 0; + hi->biClrUsed = 0; + hi->biClrImportant = 0; + hi->biWidth = cx; + hi->biHeight = -cy; + + HBITMAP hbmp = CreateDIBSection(dcScreen, (BITMAPINFO *)hi, DIB_RGB_COLORS, (void **)&pixels, NULL, 0); + HDC dcMem = ::CreateCompatibleDC(dcScreen); + HBITMAP hbmpOld = (HBITMAP) ::SelectObject(dcMem, hbmp); + HDC hdcCompatible = CreateCompatibleDC(dcScreen); + ::BitBlt(dcMem, 0, 0, cx, cy, dcScreen, x, y, SRCCOPY); + + ImageBuffer ib(cx, cy); + memcpy(~ib, pixels, cx * cy * sizeof(RGBA)); + + ::DeleteObject(::SelectObject(dcMem, hbmpOld)); + ::DeleteDC(dcMem); + ::DeleteDC(dcScreen); + + return ib; +}; + + +extern "C" __declspec(dllexport) int capture_screen(int x, int y, int cx, int cy, char *filename) { + Image m = ScreenShot(x, y, cx, cy); + String ext = ToLower(GetFileExt(filename)); + if(ext == ".png") + PNGEncoder().SaveFile(filename, m); + if(ext == ".bmp") + BMPEncoder().Bpp(32).SaveFile(filename, m); + if(ext == ".jpg") + JPGEncoder().SaveFile(filename, m); + if(ext == ".gif") + GIFEncoder().SaveFile(filename, m); + if(ext == ".tif" || ext == ".tiff") + TIFEncoder().SaveFile(filename, m); + return 0; +} + + +#define DLL_APP_MAIN \ +void _DllMainAppInit(); \ +\ +BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved) \ +{ \ + if(fdwReason == DLL_PROCESS_ATTACH) { \ + Ctrl::InitWin32(AppGetHandle()); \ + AppInitEnvironment__(); \ + _DllMainAppInit(); \ + } \ + else \ + if(fdwReason == DLL_PROCESS_DETACH) { \ + Ctrl::ExitWin32(); \ + } \ + return true; \ +} \ +\ +void _DllMainAppInit() + +DLL_APP_MAIN { +}