~ubuntu-branches/ubuntu/raring/ginkgocadx/raring-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/wx/ginkgostyle/ginkgostyle.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2011-09-09 08:39:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: package-import@ubuntu.com-20110909083926-iktecd132cnku5cd
Tags: 2.5.4.0~rc-1
New upstream version (patches were applied)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <wx/aui/auibar.h>
19
19
#include <wx/dcbuffer.h>
20
20
#include <wx/settings.h>
 
21
#include <wx/window.h>
21
22
#include <resources/ginkgoresourcemanager.h>
22
23
#include <algorithm>
23
24
 
42
43
 
43
44
        int x = -1,y = -1;
44
45
        if (m_titulo != wxEmptyString) {
45
 
                wxPaintDC dc;
 
46
                wxClientDC dc(this);;
46
47
                dc.SetFont(m_fuente);
47
48
                dc.GetTextExtent(m_titulo, &x, &y, NULL, NULL, NULL);
48
49
        }
858
859
{
859
860
}
860
861
 
 
862
/////////////////////////////////////////////GinkgoBoxPanel/////////////////////////////////////
 
863
GinkgoBoxPanel::GinkgoBoxPanel(wxWindow *parent,
 
864
         wxWindowID winid ,
 
865
         const wxPoint& pos,
 
866
         const wxSize& size ,
 
867
                        long style):wxPanel(parent, winid, pos, size, style)
 
868
{
 
869
        m_backgroudColor = wxColour(248,247,243);
 
870
        m_borderColor = wxColour(216, 215, 209, 255);
 
871
        SetBackgroundColour(m_backgroudColor);
 
872
 
 
873
        this->Connect( wxEVT_PAINT, wxPaintEventHandler( GinkgoBoxPanel::OnPaint ), NULL, this );
 
874
}
 
875
 
 
876
GinkgoBoxPanel::~GinkgoBoxPanel()
 
877
{
 
878
        this->Disconnect( wxEVT_PAINT, wxPaintEventHandler( GinkgoBoxPanel::OnPaint ), NULL, this );    
 
879
}
 
880
 
 
881
void GinkgoBoxPanel::OnPaint(wxPaintEvent &event)
 
882
{
 
883
        wxPaintDC dc(this);
 
884
 
 
885
        dc.SetBrush(wxBrush(m_borderColor,wxTRANSPARENT));
 
886
        dc.SetPen(wxPen(m_borderColor, 1, wxSOLID));
 
887
 
 
888
        dc.DrawRectangle(wxRect(wxPoint(0,0), wxPoint(dc.GetSize().x-1, dc.GetSize().y-1)));
 
889
        event.Skip(false);
 
890
}
 
891
 
 
892
/////////////////////////////////////////////GinkgoGauge/////////////////////////////////////
 
893
GinkgoGauge::GinkgoGauge(wxWindow *parent,
 
894
            wxWindowID winid,
 
895
            const wxPoint& pos,
 
896
            const wxSize& size,
 
897
                                long style): wxPanel(parent, winid, pos, size, style)
 
898
{
 
899
        SetMinSize(wxSize(150, 15));
 
900
        m_progress = 0.0f;
 
901
        wxFont font(8, GetFont().GetFamily(), GetFont().GetStyle(), GetFont().GetWeight());
 
902
        SetFont(font);
 
903
        wxWindow::SetBackgroundStyle(wxBG_STYLE_CUSTOM);
 
904
 
 
905
        wxClientDC dc(this);
 
906
        dc.SetFont(font);
 
907
        int height,width;
 
908
        dc.GetTextExtent(wxT("000% "), &width, &height, NULL, NULL, NULL);
 
909
        m_maxSizeOfText = GetSize().x - (width +15);
 
910
 
 
911
        RecreateBuffer(size);
 
912
 
 
913
 
 
914
        this->Connect( wxEVT_PAINT, wxPaintEventHandler( GinkgoGauge::OnPaint ), NULL, this );
 
915
        this->Connect( wxEVT_ERASE_BACKGROUND, wxEraseEventHandler( GinkgoGauge::OnEraseBackground ), NULL, this);
 
916
        this->Connect( wxEVT_SIZE, wxSizeEventHandler( GinkgoGauge::OnSize ), NULL, this );
 
917
}
 
918
 
 
919
GinkgoGauge::~GinkgoGauge()
 
920
{
 
921
        this->Disconnect( wxEVT_PAINT, wxPaintEventHandler( GinkgoGauge::OnPaint ), NULL, this );
 
922
        this->Disconnect( wxEVT_ERASE_BACKGROUND, wxEraseEventHandler( GinkgoGauge::OnEraseBackground ), NULL, this);
 
923
        this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( GinkgoGauge::OnSize ), NULL, this );
 
924
}       
 
925
 
 
926
void GinkgoGauge::SetStatus(const wxString& status)
 
927
{
 
928
        m_status = status;
 
929
        wxClientDC dc(this);
 
930
        dc.SetFont(GetFont());
 
931
        int width,height;
 
932
        dc.GetTextExtent(m_status, &width, &height, NULL, NULL, NULL);
 
933
        while (width > m_maxSizeOfText && m_status.size() > 2) {
 
934
                m_status = m_status.substr(0, m_status.size() - 2);                             
 
935
                dc.GetTextExtent(m_status, &width, &height, NULL, NULL, NULL);
 
936
        } 
 
937
 
 
938
        Refresh(true);
 
939
}
 
940
 
 
941
void GinkgoGauge::SetProgress(float progress)
 
942
{
 
943
        if (progress >= 0.0f && progress <= 1.0f) {
 
944
                m_progress = progress;
 
945
                Refresh(true);
 
946
        }
 
947
}
 
948
 
 
949
void GinkgoGauge::OnPaint(wxPaintEvent &event)
 
950
{
 
951
        wxBufferedPaintDC dc(this, m_bufferBitmap);
 
952
        PrepareDC(dc);
 
953
 
 
954
        dc.SetFont(GetFont());
 
955
        dc.SetPen( wxPen( m_borderColour, 1, wxSOLID ) );
 
956
        dc.SetBrush(wxColour(255,255,255));
 
957
 
 
958
        int width = dc.GetSize().x;
 
959
        int height = dc.GetSize().y;
 
960
        wxRect cr(0,0, width, height);
 
961
 
 
962
        dc.DrawRectangle(cr);
 
963
 
 
964
        cr.width = (int) ( (float)width * m_progress );
 
965
 
 
966
        dc.GradientFillLinear(cr, m_startColour, m_endColour, wxEAST);
 
967
 
 
968
        int func = dc.GetLogicalFunction();
 
969
        dc.SetLogicalFunction(wxXOR);
 
970
 
 
971
        wxCoord tx = 0, ty = 0;
 
972
        wxString str = wxString::Format(wxT("%.00f%% "), 100.0f * m_progress) + m_status;
 
973
        dc.GetTextExtent(str, &tx, &ty, NULL, NULL, NULL);
 
974
 
 
975
 
 
976
        dc.DrawText(str, (width >> 1)  - (tx >> 1), (height >> 1) - (ty >> 1) );
 
977
        dc.SetLogicalFunction(func);
 
978
        event.Skip(false);
 
979
}
 
980
 
 
981
void GinkgoGauge::OnEraseBackground( wxEraseEvent&  )
 
982
{
 
983
}
 
984
 
 
985
 
 
986
void GinkgoGauge::OnSize(wxSizeEvent& )
 
987
{
 
988
        RecreateBuffer();
 
989
}
 
990
 
 
991
void GinkgoGauge::SetMinSize(const wxSize &minSize)
 
992
{
 
993
        wxPanel::SetMinSize(minSize);
 
994
        RecreateBuffer();
 
995
}
 
996
 
 
997
void GinkgoGauge::SetSize(const wxSize &minSize)
 
998
{
 
999
        wxPanel::SetSize(minSize);
 
1000
        RecreateBuffer();
 
1001
}
 
1002
 
 
1003
void GinkgoGauge::SetColorSchema(TColorSchema schema)
 
1004
{
 
1005
        switch (schema) {
 
1006
                case TCS_BLUE:
 
1007
                        m_fontColour = wxColour(0,0,0);
 
1008
                        m_startColour = wxColour(224, 237, 255);
 
1009
                        m_endColour = wxColour(119, 169, 255);
 
1010
                        m_borderColour = wxColour(58, 143, 255);
 
1011
                        break;
 
1012
                case TCS_RED:
 
1013
                        m_fontColour = wxColour(0,0,0);
 
1014
                        m_startColour = wxColour(255, 224, 237);
 
1015
                        m_endColour = wxColour(255, 169, 119);
 
1016
                        m_borderColour = wxColour(255, 0, 0);
 
1017
                        break;
 
1018
                case TCS_GREY:
 
1019
                        m_fontColour = wxColour(0,0,0);
 
1020
                        m_startColour = wxColour(237, 237, 237);
 
1021
                        m_endColour = wxColour(100, 100, 100);
 
1022
                        m_borderColour = wxColour(143, 143, 143);
 
1023
                        break;
 
1024
                case TCS_GREEN:
 
1025
                        m_fontColour = wxColour(0,0,0);
 
1026
                        m_startColour = wxColour(237, 255, 224);
 
1027
                        m_endColour = wxColour(120, 198, 83);
 
1028
                        m_borderColour = wxColour(143, 255, 58);
 
1029
                        break;
 
1030
        }
 
1031
        SetForegroundColour(m_fontColour);
 
1032
}
 
1033
 
 
1034
bool GinkgoGauge::RecreateBuffer(const wxSize& size)
 
1035
{
 
1036
    wxSize sz = size;
 
1037
    if (sz == wxDefaultSize)
 
1038
        sz = GetClientSize();
 
1039
 
 
1040
    if (sz.x < 1 || sz.y < 1)
 
1041
        return false;
 
1042
 
 
1043
         wxClientDC dc(this);
 
1044
         dc.SetFont(GetFont());
 
1045
         int height,width;
 
1046
         dc.GetTextExtent(wxT("000% "), &width, &height, NULL, NULL, NULL);
 
1047
         m_maxSizeOfText = sz.x - (width +15);
 
1048
 
 
1049
    if (!m_bufferBitmap.Ok() || m_bufferBitmap.GetWidth() < sz.x || m_bufferBitmap.GetHeight() < sz.y)
 
1050
        m_bufferBitmap = wxBitmap(sz.x, sz.y);
 
1051
 
 
1052
    return m_bufferBitmap.Ok();
 
1053
}
861
1054
 
862
1055
 
863
1056