linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #02262
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2266: allow the stats window to print to any device context
------------------------------------------------------------
revno: 2266
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-10-28 22:21:23 +0200
message:
allow the stats window to print to any device context
modified:
dwt/include/dwt/aspects/AspectPainting.h
win32/StatsFrame.cpp
win32/StatsFrame.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 'dwt/include/dwt/aspects/AspectPainting.h'
--- dwt/include/dwt/aspects/AspectPainting.h 2010-07-10 14:36:48 +0000
+++ dwt/include/dwt/aspects/AspectPainting.h 2010-10-28 20:21:23 +0000
@@ -37,6 +37,7 @@
#define DWT_AspectPainting_h
#include "../CanvasClasses.h"
+#include "../Dispatchers.h"
namespace dwt {
@@ -50,32 +51,49 @@
{
WidgetType& W() { return *static_cast<WidgetType*>(this); }
- struct PaintDispatcher {
- typedef std::function<void (PaintCanvas&)> F;
-
- PaintDispatcher(const F& f_, Widget* widget_) : f(f_), widget(widget_) { }
-
- bool operator()(const MSG& msg, LRESULT& ret) const {
+ struct PaintDispatcher : Dispatchers::Base<void (PaintCanvas&)> {
+ typedef Dispatchers::Base<void (PaintCanvas&)> BaseType;
+ PaintDispatcher(const typename BaseType::F& f, Widget* widget_) :
+ BaseType(f),
+ widget(widget_)
+ { }
+
+ bool operator()(const MSG& msg, LRESULT&) const {
PaintCanvas canvas(widget);
-
f(canvas);
return true;
}
- F f;
+ private:
Widget* widget;
};
+
+ struct PrintDispatcher : Dispatchers::Base<void (Canvas&)> {
+ typedef Dispatchers::Base<void (Canvas&)> BaseType;
+ PrintDispatcher(const F& f_) : BaseType(f_) { }
+
+ bool operator()(const MSG& msg, LRESULT& ret) const {
+ FreeCanvas canvas(reinterpret_cast<HDC>(msg.wParam));
+ f(canvas);
+ return true;
+ }
+ };
+
public:
/// \ingroup EventHandlersAspectPainting
/// Painting event handler setter
- /** If supplied, event handler is called with a Canvas & which you can use to
+ /** If supplied, event handler is called with a PaintCanvas& which you can use to
* paint stuff onto the window with. <br>
- * Parameters passed is Canvas &
+ * Parameters passed is PaintCanvas&
*/
void onPainting(const typename PaintDispatcher::F& f) {
W().addCallback(Message(WM_PAINT), PaintDispatcher(f, &W()));
}
+ void onPrinting(const typename PrintDispatcher::F& f) {
+ W().addCallback(Message(WM_PRINTCLIENT), PrintDispatcher(f));
+ }
+
protected:
virtual ~AspectPainting()
{}
=== modified file 'win32/StatsFrame.cpp'
--- win32/StatsFrame.cpp 2010-08-27 13:47:33 +0000
+++ win32/StatsFrame.cpp 2010-10-28 20:21:23 +0000
@@ -42,7 +42,13 @@
{
setFont(WinUtil::font);
- onPainting(std::bind(&StatsFrame::handlePaint, this, _1));
+ onPainting([this](dwt::PaintCanvas& canvas) {
+ dwt::Rectangle rect = canvas.getPaintRect();
+ if(rect.width() == 0 || rect.height() == 0)
+ return;
+ draw(canvas, rect);
+ });
+ onPrinting([this](dwt::Canvas& canvas) { draw(canvas, dwt::Rectangle(getClientSize())); });
initStatus();
@@ -55,12 +61,7 @@
StatsFrame::~StatsFrame() {
}
-void StatsFrame::handlePaint(dwt::PaintCanvas& canvas) {
- dwt::Rectangle rect = canvas.getPaintRect();
-
- if(rect.width() == 0 || rect.size.y == 0)
- return;
-
+void StatsFrame::draw(dwt::Canvas& canvas, const dwt::Rectangle& rect) {
{
dwt::Canvas::Selector select(canvas, *WinUtil::bgBrush);
::BitBlt(canvas.handle(), rect.x(), rect.y(), rect.width(), rect.height(), NULL, 0, 0, PATCOPY);
@@ -182,7 +183,7 @@
return true;
}
-void StatsFrame::drawLine(dwt::Canvas& canvas, StatIter begin, StatIter end, dwt::Rectangle& rect, long clientRight) {
+void StatsFrame::drawLine(dwt::Canvas& canvas, StatIter begin, StatIter end, const dwt::Rectangle& rect, long clientRight) {
StatIter i;
for(i = begin; i != end; ++i) {
if((clientRight - (long)i->scroll) < rect.right())
=== modified file 'win32/StatsFrame.h'
--- win32/StatsFrame.h 2010-02-11 21:44:13 +0000
+++ win32/StatsFrame.h 2010-10-28 20:21:23 +0000
@@ -73,12 +73,12 @@
int64_t lastDown;
int64_t max;
- void handlePaint(dwt::PaintCanvas& canvas);
+ void draw(dwt::Canvas& canvas, const dwt::Rectangle& rect);
void layout();
bool eachSecond();
- void drawLine(dwt::Canvas& canvas, StatIter begin, StatIter end, dwt::Rectangle& rect, long clientRight);
+ void drawLine(dwt::Canvas& canvas, StatIter begin, StatIter end, const dwt::Rectangle& rect, long clientRight);
void addTick(int64_t bdiff, int64_t tdiff, StatList& lst, AvgList& avg, int scroll);
};