-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #996 from vktr/feature/piece-progress
Add piece progress bar
- Loading branch information
Showing
6 changed files
with
152 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "pieceprogressbar.hpp" | ||
|
||
#include <wx/dcbuffer.h> | ||
|
||
namespace lt = libtorrent; | ||
using pt::UI::Widgets::PieceProgressBar; | ||
|
||
PieceProgressBar::PieceProgressBar(wxWindow* parent, wxWindowID id, lt::typed_bitfield<lt::piece_index_t> field) | ||
: wxPanel(parent, id, wxDefaultPosition, wxSize(-1, parent->FromDIP(15)), wxTAB_TRAVERSAL | wxNO_BORDER | wxBG_STYLE_PAINT), | ||
m_bitfield(field) | ||
{ | ||
Connect(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(PieceProgressBar::OnEraseBackground)); | ||
Connect(wxEVT_PAINT, wxPaintEventHandler(PieceProgressBar::OnPaint)); | ||
Connect(wxEVT_SIZE, wxSizeEventHandler(PieceProgressBar::OnSize)); | ||
} | ||
|
||
void PieceProgressBar::UpdateBitfield(lt::typed_bitfield<lt::piece_index_t> const& field) | ||
{ | ||
m_bitfield = field; | ||
Refresh(); | ||
} | ||
|
||
void PieceProgressBar::OnEraseBackground(wxEraseEvent&) | ||
{ | ||
} | ||
|
||
void PieceProgressBar::OnSize(wxSizeEvent&) | ||
{ | ||
Refresh(); | ||
} | ||
|
||
void PieceProgressBar::OnPaint(wxPaintEvent&) | ||
{ | ||
wxBufferedPaintDC dc(this); | ||
RenderProgress(dc); | ||
} | ||
|
||
void PieceProgressBar::RenderProgress(wxDC& dc) | ||
{ | ||
static wxColor bar("#35b1e1"); | ||
static wxColor darkBorder(50, 50, 50); | ||
|
||
if (m_bitfield.size() > 0) | ||
{ | ||
wxBitmap prg(m_bitfield.size() + 2, this->GetClientSize().GetHeight()); | ||
wxMemoryDC memDC; | ||
|
||
memDC.SelectObject(prg); | ||
memDC.SetBrush(*wxWHITE); | ||
memDC.SetPen(darkBorder); | ||
memDC.DrawRectangle({ 0, 0 }, prg.GetSize()); | ||
|
||
memDC.SetPen(bar); | ||
|
||
for (int idx = 0; idx < m_bitfield.size(); idx++) | ||
{ | ||
lt::piece_index_t pcs{ idx }; | ||
|
||
if (m_bitfield[pcs]) | ||
{ | ||
memDC.DrawLine(idx + 1, 1, idx + 1, prg.GetHeight() - 1); | ||
} | ||
} | ||
|
||
dc.StretchBlit( | ||
{ 0, 0 }, | ||
this->GetClientSize(), | ||
&memDC, | ||
{ 0, 0 }, | ||
prg.GetSize()); | ||
} | ||
else | ||
{ | ||
dc.SetBrush(*wxWHITE); | ||
dc.SetPen(wxColor(190, 190, 190)); | ||
dc.DrawRectangle(this->GetClientRect()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <wx/wxprec.h> | ||
#ifndef WX_PRECOMP | ||
#include <wx/wx.h> | ||
#endif | ||
|
||
#include <libtorrent/bitfield.hpp> | ||
#include <libtorrent/fwd.hpp> | ||
|
||
namespace pt::UI::Widgets | ||
{ | ||
class PieceProgressBar : public wxPanel | ||
{ | ||
public: | ||
PieceProgressBar(wxWindow* parent, wxWindowID id, libtorrent::typed_bitfield<libtorrent::piece_index_t> field = {}); | ||
void UpdateBitfield(libtorrent::typed_bitfield<libtorrent::piece_index_t> const& field); | ||
|
||
protected: | ||
void OnEraseBackground(wxEraseEvent&); | ||
void OnSize(wxSizeEvent&); | ||
void OnPaint(wxPaintEvent&); | ||
|
||
private: | ||
void RenderProgress(wxDC& dc); | ||
|
||
libtorrent::typed_bitfield<libtorrent::piece_index_t> m_bitfield; | ||
}; | ||
} |