2019-01-09 12:33:11 +00:00
|
|
|
|
/*************************************************************************/
|
|
|
|
|
/** Copyright. **/
|
|
|
|
|
/** FileName: wxLCD.cpp **/
|
|
|
|
|
/** Author: Polarix **/
|
|
|
|
|
/** Description: LCD display panel in wxWidgets frame. **/
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
//=======================================================================//
|
2021-03-30 13:40:07 +00:00
|
|
|
|
//= Include files. =//
|
2019-01-09 12:33:11 +00:00
|
|
|
|
//=======================================================================//
|
2019-01-06 15:07:03 +00:00
|
|
|
|
#include "wxLCD.h"
|
2021-03-30 12:00:34 +00:00
|
|
|
|
#include "SGUI_Common.h"
|
2020-08-06 15:52:30 +00:00
|
|
|
|
#include <math.h>
|
2020-08-11 09:44:53 +00:00
|
|
|
|
#include <wx/log.h>
|
2019-01-09 12:33:11 +00:00
|
|
|
|
//=======================================================================//
|
2021-03-30 13:40:07 +00:00
|
|
|
|
//= Function define. =//
|
2019-01-09 12:33:11 +00:00
|
|
|
|
//=======================================================================//
|
2019-01-06 15:07:03 +00:00
|
|
|
|
wxLCD::wxLCD(wxWindow *pclsParent, wxWindowID iWinID, const wxPoint& clsPosition, const wxSize& clsSizeInPixel):
|
|
|
|
|
wxLCDBase(pclsParent, iWinID, clsPosition, clsSizeInPixel)
|
|
|
|
|
{
|
2019-01-09 12:33:11 +00:00
|
|
|
|
m_clsPixelLColour.Set(0x00000000);
|
2019-01-06 15:07:03 +00:00
|
|
|
|
m_clsPixelHColour.Set(0x00000000);
|
2020-08-06 15:52:30 +00:00
|
|
|
|
m_clsPixelPalette=NULL;
|
2019-01-06 15:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxLCD::~wxLCD(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wxLCD::SetPanelColour(const wxColour& clsPanelColour, bool bRefreshNow)
|
|
|
|
|
{
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
|
/* Process */
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
|
// Replace old panel color.
|
|
|
|
|
ReplaceColour(m_clsPixelLColour, clsPanelColour);
|
|
|
|
|
// Set new panel color.
|
|
|
|
|
m_clsPixelLColour = clsPanelColour;
|
|
|
|
|
// Refresh display.
|
|
|
|
|
if(true == bRefreshNow)
|
|
|
|
|
{
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wxLCD::SetPixelColour(const wxColour& clsPixelColour, bool bRefreshNow)
|
|
|
|
|
{
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
|
/* Process */
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
|
// Replace old pixel color.
|
|
|
|
|
ReplaceColour(m_clsPixelHColour, clsPixelColour);
|
|
|
|
|
// Set new pixel color.
|
|
|
|
|
m_clsPixelHColour = clsPixelColour;
|
|
|
|
|
// Refresh display.
|
|
|
|
|
if(true == bRefreshNow)
|
|
|
|
|
{
|
|
|
|
|
RefreshDisplay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-06 15:52:30 +00:00
|
|
|
|
void wxLCD::SetPixelDepth(const int depth)
|
|
|
|
|
{
|
2021-03-30 13:14:51 +00:00
|
|
|
|
this->m_iPixelDepth=depth;
|
|
|
|
|
if(this->m_clsPixelPalette != NULL)
|
|
|
|
|
{
|
|
|
|
|
free(m_clsPixelPalette);
|
|
|
|
|
m_clsPixelPalette=NULL;
|
|
|
|
|
}
|
|
|
|
|
// Generate a scaled Palette bettween the BackgroundColor and PixelColor
|
|
|
|
|
m_clsPixelPalette = new wxColor[depth];
|
|
|
|
|
wxLogDebug("<EFBFBD><EFBFBD>ɫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
|
|
|
|
|
unsigned char ucRH=this->m_clsPixelHColour.Red();
|
|
|
|
|
unsigned char ucGH=this->m_clsPixelHColour.Green();
|
|
|
|
|
unsigned char ucBH=this->m_clsPixelHColour.Blue();
|
|
|
|
|
wxLogDebug("<EFBFBD><EFBFBD>ɫ<EFBFBD>߽<EFBFBD>A(%d,%d,%d)",ucRH,ucGH,ucBH);
|
|
|
|
|
unsigned char ucRL=m_clsPixelLColour.Red();
|
|
|
|
|
unsigned char ucGL=m_clsPixelLColour.Green();
|
|
|
|
|
unsigned char ucBL=m_clsPixelLColour.Blue();
|
|
|
|
|
wxLogDebug("<EFBFBD><EFBFBD>ɫ<EFBFBD>߽<EFBFBD>B(%d,%d,%d)",ucRL,ucGL,ucBL);
|
|
|
|
|
double dbRDiff=(ucRH-ucRL)*1.0/(depth-1);
|
|
|
|
|
double dbGDiff=(ucGH-ucGL)*1.0/(depth-1);
|
|
|
|
|
double dbBDiff=(ucBH-ucBL)*1.0/(depth-1);
|
|
|
|
|
wxLogDebug("ɫ<EFBFBD><EFBFBD>(%.2f,%.2f,%.2f)",dbRDiff,dbGDiff,dbBDiff);
|
|
|
|
|
double dbR=(int)ucRL*1.0;
|
|
|
|
|
double dbG=(int)ucGL*1.0;
|
|
|
|
|
double dbB=(int)ucBL*1.0;
|
2020-08-06 15:52:30 +00:00
|
|
|
|
|
2021-03-30 13:14:51 +00:00
|
|
|
|
for(int i=0; i<depth; i++)
|
|
|
|
|
{
|
|
|
|
|
wxLogDebug("<EFBFBD><EFBFBD>ɫ0x%02X<32><58>ӳ<EFBFBD><D3B3>Ϊ(%d,%d,%d)",i,(unsigned char)floor(dbR+0.5),(unsigned char)floor(dbG+0.5),(unsigned char)floor(dbB+0.5));
|
|
|
|
|
m_clsPixelPalette[i]=wxColor((unsigned char)floor(dbR+0.5),(unsigned char)floor(dbG+0.5),(unsigned char)floor(dbB+0.5));
|
|
|
|
|
dbR+=dbRDiff;
|
|
|
|
|
dbG+=dbGDiff;
|
|
|
|
|
dbB+=dbBDiff;
|
|
|
|
|
}
|
2020-08-06 15:52:30 +00:00
|
|
|
|
}
|
2020-03-19 14:34:59 +00:00
|
|
|
|
int wxLCD::GetPixel(const int iX, const int iY)
|
2019-01-06 15:07:03 +00:00
|
|
|
|
{
|
2020-08-06 15:52:30 +00:00
|
|
|
|
int iReturn=-1;
|
2021-03-30 13:14:51 +00:00
|
|
|
|
int iLeft=0;
|
|
|
|
|
int iRight=m_iPixelDepth-1;
|
|
|
|
|
int iMid=(iLeft+iRight)/2;
|
|
|
|
|
wxColor clsLeftColor,clsRightColor;
|
|
|
|
|
wxColor clsTargetColor=GetPixelUnitColor(iX, iY);
|
|
|
|
|
wxColor clsMidColor;
|
2019-01-06 15:07:03 +00:00
|
|
|
|
|
2020-08-06 15:52:30 +00:00
|
|
|
|
while(iLeft<iRight)
|
2019-01-06 15:07:03 +00:00
|
|
|
|
{
|
2020-08-06 15:52:30 +00:00
|
|
|
|
iMid=(iLeft+iRight)/2;
|
2021-03-30 13:14:51 +00:00
|
|
|
|
clsLeftColor=m_clsPixelPalette[iLeft];
|
|
|
|
|
clsMidColor=m_clsPixelPalette[iMid];
|
|
|
|
|
clsRightColor=m_clsPixelPalette[iRight];
|
|
|
|
|
// use Red to search
|
|
|
|
|
if((clsLeftColor.Red()<=clsTargetColor.Red() && clsTargetColor.Red()<clsMidColor.Red()) ||
|
|
|
|
|
(clsLeftColor.Red()>=clsTargetColor.Red() && clsTargetColor.Red()>clsMidColor.Red()))
|
|
|
|
|
{
|
|
|
|
|
iRight=iMid-1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if((clsRightColor.Red()>=clsTargetColor.Red() && clsTargetColor.Red()>clsMidColor.Red())||
|
|
|
|
|
(clsRightColor.Red()<=clsTargetColor.Red() && clsTargetColor.Red()<clsMidColor.Red()))
|
|
|
|
|
{
|
|
|
|
|
iLeft=iMid+1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// use Green to search
|
|
|
|
|
if((clsLeftColor.Green()<=clsTargetColor.Green() && clsTargetColor.Green()<clsMidColor.Green()) ||
|
|
|
|
|
(clsLeftColor.Green()>=clsTargetColor.Green() && clsTargetColor.Green()>clsMidColor.Green()))
|
|
|
|
|
{
|
|
|
|
|
iRight=iMid-1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if((clsRightColor.Green()>=clsTargetColor.Green() && clsTargetColor.Green()>clsMidColor.Green())||
|
|
|
|
|
(clsRightColor.Green()<=clsTargetColor.Green() && clsTargetColor.Green()<clsMidColor.Green()))
|
|
|
|
|
{
|
|
|
|
|
iLeft=iMid+1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// use Blue to search
|
|
|
|
|
if((clsLeftColor.Blue()<=clsTargetColor.Blue() && clsTargetColor.Blue()<clsMidColor.Blue()) ||
|
|
|
|
|
(clsLeftColor.Blue()>=clsTargetColor.Blue() && clsTargetColor.Blue()>clsMidColor.Blue()))
|
|
|
|
|
{
|
|
|
|
|
iRight=iMid-1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if((clsRightColor.Blue()>=clsTargetColor.Blue() && clsTargetColor.Blue()>clsMidColor.Blue())||
|
|
|
|
|
(clsRightColor.Blue()<=clsTargetColor.Blue() && clsTargetColor.Blue()<clsMidColor.Blue()))
|
|
|
|
|
{
|
|
|
|
|
iLeft=iMid+1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// iMid is the target color
|
|
|
|
|
iReturn=iMid;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(iReturn==-1 && iLeft==iRight)
|
|
|
|
|
iReturn=iLeft;
|
|
|
|
|
return iReturn;
|
2019-01-06 15:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 14:34:59 +00:00
|
|
|
|
void wxLCD::SetPixel(const int iX, const int iY, const int iValue)
|
2019-01-06 15:07:03 +00:00
|
|
|
|
{
|
2021-03-30 13:14:51 +00:00
|
|
|
|
int iCheckedValue;
|
|
|
|
|
iCheckedValue = SGUI_MIN_OF(iValue,m_iPixelDepth-1);
|
|
|
|
|
iCheckedValue = SGUI_MAX_OF(iCheckedValue,0);
|
2020-08-06 15:52:30 +00:00
|
|
|
|
|
2021-03-30 13:14:51 +00:00
|
|
|
|
SetPixelUnitColor(iX,iY,m_clsPixelPalette[iCheckedValue]);
|
2019-01-06 15:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wxLCD::CleanScreen(void)
|
|
|
|
|
{
|
|
|
|
|
SetDisplayBuffer(m_clsPixelLColour);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wxLCD::SetParameter(PixelPanelParameter* pstPanelParameter)
|
|
|
|
|
{
|
|
|
|
|
if(NULL != pstPanelParameter)
|
|
|
|
|
{
|
2019-01-26 15:12:10 +00:00
|
|
|
|
SetPixelUnitSize(wxSize(pstPanelParameter->PixelUnitWidth, pstPanelParameter->PixelUnitHeight));
|
2021-03-30 13:40:07 +00:00
|
|
|
|
SetGridVisibled(pstPanelParameter->EnableGrid);
|
2019-01-06 15:07:03 +00:00
|
|
|
|
SetPixelNumber(pstPanelParameter->HorizontalPixelNumber, pstPanelParameter->VerticalPixelNumber);
|
2019-02-15 13:58:23 +00:00
|
|
|
|
SetBorderWidth(pstPanelParameter->BorderWidth);
|
2019-01-06 15:07:03 +00:00
|
|
|
|
|
2019-01-09 12:33:11 +00:00
|
|
|
|
SetPixelColour(wxColor(pstPanelParameter->PixelColor), false);
|
|
|
|
|
SetPanelColour(wxColor(pstPanelParameter->PanelColor), false);
|
|
|
|
|
SetGridColor(wxColor(pstPanelParameter->GridColor));
|
2020-08-06 15:52:30 +00:00
|
|
|
|
SetPixelDepth(pstPanelParameter->PixelUnitDepth);
|
2019-02-15 13:58:23 +00:00
|
|
|
|
|
|
|
|
|
Layout();
|
2019-01-06 15:07:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|