linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05002
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2736: add an icon to the splash screen, draw it with a layered window (for transparency)
------------------------------------------------------------
revno: 2736
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2011-12-22 20:24:21 +0100
message:
add an icon to the splash screen, draw it with a layered window (for transparency)
modified:
win32/SplashWindow.cpp
win32/SplashWindow.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'win32/SplashWindow.cpp'
--- win32/SplashWindow.cpp 2011-06-28 20:07:49 +0000
+++ win32/SplashWindow.cpp 2011-12-22 19:24:21 +0000
@@ -17,62 +17,72 @@
*/
#include "stdafx.h"
-#include <dcpp/DCPlusPlus.h>
-
#include "SplashWindow.h"
#include <dcpp/format.h>
+#include <dcpp/Text.h>
#include <dcpp/version.h>
-#include <dcpp/Text.h>
+#include "resource.h"
#include "WinUtil.h"
-SplashWindow::SplashWindow() : dwt::Window(0) {
- {
- Seed cs;
- cs.style = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
- cs.exStyle = WS_EX_STATICEDGE;
- cs.caption = _T(APPNAME);
- tmp = new dwt::Window(0);
- tmp->create(cs);
- }
- {
- Seed cs;
- cs.style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
- cs.exStyle = WS_EX_STATICEDGE;
- cs.caption = _T(APPNAME);
- create(cs);
- }
- tstring caption = _T(APPNAME) _T(" ") _T(VERSIONSTRING);
- {
- dwt::TextBox::Seed cs;
- cs.style = WS_CHILD | ES_CENTER | ES_READONLY;
- cs.exStyle = WS_EX_STATICEDGE;
- text = addChild(cs);
- }
-
- dwt::Point textSize(text->getTextSize(caption));
- dwt::Point desktopSize(getDesktopSize());
- int xmid = desktopSize.x / 2;
- int ymid = desktopSize.y / 2;
- int xtext = 300;
- int ytext = textSize.y + 6;
-
- dwt::Rectangle r(xmid - xtext/2, ymid - ytext/2, xtext, ytext);
- resize(r);
- text->resize(dwt::Rectangle(0, 0, xtext, ytext));
-
- ::HideCaret(text->handle());
- text->setVisible(true);
- text->bringToFront();
- text->redraw(true);
+const long iconSize = 256;
+
+SplashWindow::SplashWindow() :
+dwt::Window(0),
+icon(WinUtil::createIcon(IDI_DCPP, iconSize))
+{
+ {
+ // create a layered window (WS_EX_LAYERED); it will be shown later with UpdateLayeredWindow.
+ Seed seed(_T(APPNAME) _T(" ") _T(VERSIONSTRING));
+ seed.style = WS_POPUP | WS_VISIBLE;
+ seed.exStyle = WS_EX_LAYERED;
+ create(seed);
+ }
+
+ setFont(0); // default font since settings haven't been loaded yet
+
+ // start showing when loading settings. language info isn't loaded at this point...
+ operator()(Text::fromT(_T(APPNAME)));
}
SplashWindow::~SplashWindow() {
- tmp->close();
}
void SplashWindow::operator()(const string& status) {
- text->setText(str(TF_("Loading DC++, please wait... (%1%)") % Text::toT(status) ));
- text->redraw(true);
+ auto text = str(TF_("Loading DC++, please wait... (%1%)") % Text::toT(status));
+ auto textSize = getTextSize(text);
+
+ const long spacing = 6; // space between the icon and the text
+ SIZE size = { std::max(iconSize, textSize.x), iconSize + spacing + textSize.y };
+
+ dwt::UpdateCanvas windowCanvas(this);
+ dwt::CompatibleCanvas canvas(windowCanvas.handle());
+
+ // create the bitmap with CreateDIBSection to have access to its bits (used when drawing text).
+ BITMAPINFO info = { { sizeof(BITMAPINFOHEADER), size.cx, -size.cy, 1, 32, BI_RGB } };
+ RGBQUAD* bits;
+ dwt::Bitmap bitmap(::CreateDIBSection(windowCanvas.handle(), &info, DIB_RGB_COLORS, &reinterpret_cast<void*&>(bits), 0, 0));
+ auto select(canvas.select(bitmap));
+
+ canvas.drawIcon(icon, dwt::Rectangle(std::max(textSize.x - iconSize, 0L) / 2, 0, iconSize, iconSize));
+
+ dwt::Rectangle textRect(std::max(iconSize - textSize.x, 0L) / 2, size.cy - textSize.y, textSize.x, textSize.y);
+ auto bkMode(canvas.setBkMode(true));
+ canvas.fill(textRect, dwt::Brush(dwt::Brush::Window));
+ canvas.setTextColor(dwt::Color::predefined(COLOR_WINDOWTEXT));
+ auto selectFont(canvas.select(*getFont()));
+ canvas.drawText(text.c_str(), textRect, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
+ // set bits within the text rectangle to not be transparent. rgbReserved is the alpha value.
+ for(long x = textRect.left(); x < textRect.right(); ++x) {
+ for(long y = textRect.top(); y < textRect.bottom(); ++y) {
+ bits[x + y * size.cx].rgbReserved = 255;
+ }
+ }
+
+ auto desktop = getDesktopSize();
+ POINT pt = { std::max(desktop.x - size.cx, 0L) / 2, std::max(desktop.y - size.cy - iconSize, 0L) / 2 };
+ POINT canvasPt = { 0 };
+ BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
+ ::UpdateLayeredWindow(handle(), windowCanvas.handle(), &pt, &size, canvas.handle(), &canvasPt, 0, &blend, ULW_ALPHA);
}
=== modified file 'win32/SplashWindow.h'
--- win32/SplashWindow.h 2011-05-04 19:32:00 +0000
+++ win32/SplashWindow.h 2011-12-22 19:24:21 +0000
@@ -1,5 +1,23 @@
-#ifndef SPLASHWINDOW_H_
-#define SPLASHWINDOW_H_
+/*
+ * Copyright (C) 2001-2011 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef DCPLUSPLUS_WIN32_SPLASHWINDOW_H
+#define DCPLUSPLUS_WIN32_SPLASHWINDOW_H
#include <dwt/widgets/Window.h>
@@ -7,10 +25,11 @@
public:
SplashWindow();
virtual ~SplashWindow();
- void operator()(const string& str);
+
+ void operator()(const string& status);
+
private:
- dwt::Window* tmp;
- dwt::TextBoxPtr text;
+ dwt::IconPtr icon;
};
-#endif /*SPLASHWINDOW_H_*/
+#endif