This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_wallpaper_base.cpp
169 lines (144 loc) · 4.92 KB
/
common_wallpaper_base.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/////////////////////////////////////////////////////////////////////////////
// Name: common_wallpaper_base.cpp
// Purpose:
// Author: Rex Zhang
// Modified by:
// Created: 2006-03-04
// RCS-ID:
// Copyright: (c) 2006 Rex Zhang
// Licence: GNU General Public License (GPL) version 2
/////////////////////////////////////////////////////////////////////////////
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include "common_globals.h"
#include "common_wallpaper_base.h"
//WallpaperBase::WallpaperBase(ngpodwcConfig programConfig)
WallpaperBase::WallpaperBase(void)
{
//ctor
//config = programConfig;
Init();
}
WallpaperBase::~WallpaperBase()
{
//dtor
}
bool WallpaperBase::Init()
{
return true;
}
wxImage WallpaperBase::GetImage()
{
return Image;
}
bool WallpaperBase::SetImage(wxImage inImage)
{
Image = inImage;
return true;
}
bool WallpaperBase::ImageOk()
{
return Image.Ok();
}
wxString WallpaperBase::GetText()
{
return wxEmptyString;
}
bool WallpaperBase::DrawText()
{
wxString TextString(GetText());//获取需要加注的格式化后的文本
if(TextString == wxEmptyString)
{
//没有加注信息,直接跳出
return false;
}
wxBitmap ScreenBitmap(Image);
// Create a memory DC
wxMemoryDC ScreenImageDC;
ScreenImageDC.SelectObject(ScreenBitmap);
wxColourDatabase ColourDB;
//ScreenImageDC.SetTextForeground(ColourDB.Find(wxT("DARK GREY")));
//ScreenImageDC.SetTextBackground(ColourDB.Find(wxT("LIGHT GREY")));
//
int InfoBoxW = 600, InfoBoxH = 200;
int InfoBoxXY = 20, infoBoxYSeek = 30;//当为右下时,为右下与屏幕右下角的相对坐标
wxRect podInfoRect(Image.GetWidth() - InfoBoxXY - InfoBoxW,
Image.GetHeight() - InfoBoxXY - InfoBoxH - infoBoxYSeek,
InfoBoxW, InfoBoxH);
/*
//--------------------------------
wxBitmap InfoBoxBitmap(600,150, 16);
InfoBoxBitmap.LoadFile(wxT("share/art/logo.xpm"), wxBITMAP_TYPE_XPM);
wxMemoryDC InfoBoxDC;
InfoBoxDC.SelectObject(InfoBoxBitmap);
InfoBoxDC.SetTextForeground(ColourDB.Find(wxT("DARK GREY")));
InfoBoxDC.SetTextBackground(ColourDB.Find(wxT("LIGHT GREY")));
//InfoBoxDC.Clear();
//InfoBoxDC.DrawRoundedRectangle(0,0,600,150,20);
InfoBoxDC.DrawRectangle(1,1,550,140);
ScreenImageDC.DrawBitmap(InfoBoxBitmap, 400, 600, true);
//--------------------------------
*/
//ScreenImageDC.DrawRectangle(400,600,600,150);
wxFont ScreenImageFont = ScreenImageDC.GetFont();
ScreenImageFont.SetFamily(wxFONTFAMILY_ROMAN);
ScreenImageDC.SetFont(ScreenImageFont);
//ScreenImageDC.SetBackgroundMode(wxSOLID);//强制指定显示字体背景色,默认为透明
ScreenImageDC.SetTextForeground(ColourDB.Find(wxT("DARK GREY")));
ScreenImageDC.DrawLabel(TextString, podInfoRect, wxALIGN_RIGHT | wxALIGN_BOTTOM, -1);
//
ScreenImageDC.SetTextForeground(ColourDB.Find(wxT("LIGHT GREY")));
int InfoBoxW2 = 600, InfoBoxH2 = 200;
int InfoBoxXY2 = 20, infoBoxYSeek2 = 30;//当为右下时,为右下与屏幕右下角的相对坐标
wxRect podInfoRect2(Image.GetWidth() - InfoBoxXY2 - InfoBoxW2 - 1,
Image.GetHeight() - InfoBoxXY2 - InfoBoxH2 - infoBoxYSeek2 - 1,
InfoBoxW2, InfoBoxH2);
ScreenImageDC.DrawLabel(TextString, podInfoRect2, wxALIGN_RIGHT | wxALIGN_BOTTOM, -1);
//
ScreenImageDC.SelectObject( wxNullBitmap );
Image = ScreenBitmap.ConvertToImage();
return true;
}
bool WallpaperBase::ImageReSize()
{
//调整图片尺寸
if( (Image.GetWidth() != configRunning.ScreenWidth)
|| (Image.GetHeight() != configRunning.ScreenHeight) )
{
//如果原图片尺寸与屏幕尺寸不符〉〉调整大小
/*
//Debug Info
wxString msg;
msg.Printf(wxT("From : %i x %i\nTo : %i x %i"),
PodImage.GetWidth(), PodImage.GetHeight(), pConfig->ScreenWidth, pConfig->ScreenHeight);
wxSafeShowMessage(wxT("change size"), msg);
*/
Image = Image.Rescale(configRunning.ScreenWidth, configRunning.ScreenHeight);
}
else
{
//Image = Image;
}
return true;
}
bool WallpaperBase::SaveWallpaper()
{
//将处理完毕的图片输出至指定目录
wxString wallpaper = configRunning.ScreenPicturePath + wxT("\\") + configRunning.ScreenPictureName;
if(!Image.SaveFile(wallpaper, wxBITMAP_TYPE_BMP))
{
//wxSafeShowMessage(wxT("Can't save BMP image"),wxT("Can't save BMP image"));
wxLogError(_("ERROR! Can't create(save) wallpaper file(%s)!"), wallpaper.c_str());
return false;
}
return true;
}