← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3217: Rotate the icon while DC++ is loading

 

------------------------------------------------------------
revno: 3217
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2013-03-11 18:34:35 +0100
message:
  Rotate the icon while DC++ is loading
modified:
  changelog.txt
  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 'changelog.txt'
--- changelog.txt	2013-03-04 12:40:34 +0000
+++ changelog.txt	2013-03-11 17:34:35 +0000
@@ -1,3 +1,5 @@
+* Rotate the icon while DC++ is loading (poy)
+
 -- 0.811 2013-03-04 --
 * Fix status bar parts when the window is too small (poy)
 * [L#534440] [NMDC] Preserve encodings in some search results (poy)

=== modified file 'win32/SplashWindow.cpp'
--- win32/SplashWindow.cpp	2013-02-14 19:14:20 +0000
+++ win32/SplashWindow.cpp	2013-03-11 17:34:35 +0000
@@ -31,6 +31,7 @@
 
 SplashWindow::SplashWindow() :
 	dwt::Window(0),
+	logoRot(0),
 	progress(0)
 {
 	// 256x icons only work on >= Vista. on failure, try loading a 48x image.
@@ -73,6 +74,7 @@
 void SplashWindow::draw() {
 	auto text = status;
 	if(progress) { text += _T(" [") + Text::toT(Util::toString(progress * 100.)) + _T("%]"); }
+	logoRot = (logoRot + 1) % 4;
 
 	// set up sizes.
 	const long spacing { 6 }; // space between the icon and the text
@@ -80,6 +82,7 @@
 	const auto textSize = getTextSize(text) + padding + padding;
 	SIZE size { std::max(iconSize, textSize.x), iconSize + spacing + textSize.y };
 	dwt::Rectangle textRect { std::max(iconSize - textSize.x, 0L) / 2, size.cy - textSize.y, textSize.x, textSize.y };
+	dwt::Rectangle iconRect { std::max(textSize.x - iconSize, 0L) / 2, 0, iconSize, iconSize };
 
 	dwt::UpdateCanvas windowCanvas { this };
 	dwt::CompatibleCanvas canvas { windowCanvas.handle() };
@@ -90,8 +93,46 @@
 	dwt::Bitmap bitmap { ::CreateDIBSection(windowCanvas.handle(), &info, DIB_RGB_COLORS, &reinterpret_cast<void*&>(bits), 0, 0) };
 	auto select(canvas.select(bitmap));
 
+	auto bit = [&](long x, long y) -> RGBQUAD& { return bits[x + y * size.cx]; };
+
 	// draw the icon.
-	canvas.drawIcon(icon, dwt::Rectangle(std::max(textSize.x - iconSize, 0L) / 2, 0, iconSize, iconSize));
+	canvas.drawIcon(icon, iconRect);
+
+	// rotate the icon by swapping its bits, quarter by quarter (just because I can).
+	auto iconBit = [&](long x, long y) -> RGBQUAD& { return bit(iconRect.left() + x, iconRect.top() + y); };
+	for(long y = 0; y < iconSize / 2; ++y) {
+		for(long x = 0; x < iconSize / 2; ++x) {
+			auto &bit1 = iconBit(x, y), &bit3 = iconBit(iconSize - 1 - x, iconSize - 1 - y),
+				&bit2 = iconBit(y, iconSize - 1 - x), &bit4 = iconBit(iconSize - 1 - y, x);
+			switch(logoRot) {
+			case 0: break; // identity
+			case 1: // 90
+				{
+					auto prev = bit1;
+					bit1 = bit2;
+					bit2 = bit3;
+					bit3 = bit4;
+					bit4 = prev;
+					break;
+				}
+			case 2: // 180
+				{
+					std::swap(bit1, bit3);
+					std::swap(bit2, bit4);
+					break;
+				}
+			case 3: // 270
+				{
+					auto prev = bit1;
+					bit1 = bit4;
+					bit4 = bit3;
+					bit3 = bit2;
+					bit2 = prev;
+					break;
+				}
+			}
+		}
+	}
 
 	// draw text borders and fill the text background.
 	::RECT rc = textRect;
@@ -108,10 +149,10 @@
 	long pos = textRect.left() + progress * static_cast<float>(textRect.width());
 	for(long y = textRect.top(), yn = textRect.bottom(); y < yn; ++y) {
 		for(long x = textRect.left(); x < pos; ++x) {
-			bits[x + y * size.cx].rgbReserved = 191;
+			bit(x, y).rgbReserved = 191;
 		}
 		for(long x = pos, xn = textRect.right(); x < xn; ++x) {
-			bits[x + y * size.cx].rgbReserved = 255;
+			bit(x, y).rgbReserved = 255;
 		}
 	}
 

=== modified file 'win32/SplashWindow.h'
--- win32/SplashWindow.h	2013-02-14 16:25:20 +0000
+++ win32/SplashWindow.h	2013-03-11 17:34:35 +0000
@@ -34,6 +34,7 @@
 
 	long iconSize;
 	dwt::IconPtr icon;
+	uint32_t logoRot;
 
 	tstring status;
 	float progress;