예제 #1
0
void UiNumericDisplay::removeChar1(){
	if(_l1str.Length() == 1){
		setText1(L"0");
		_isEmpty = true;
		return;
	}
	_l1str = _l1str.SubStr(0,_l1str.Length() - 1);
}
예제 #2
0
void UiNumericDisplay::addChar1(wchar_t chCharCode){
	//only accept 0-9,dot,-
	int inputlen = _l1str.Length();
	//排除连续输入0的问题
	if(inputlen == 1 && _l1str == L"0" && chCharCode == '0') return;
	//排除在输入运算符后输入dot的问题
	if(_isEmpty && chCharCode == '.'){
		_isEmpty = false;
		_l1str = L"0.";
		_dotPos = 2;
		return;
	}
	//only 2 digital after dot
	if(chCharCode != 0x08 && _dotPos != 0 && (inputlen - _dotPos > 1)) return;
	//only 8 digital before dot
	if(chCharCode != 0x08 &&  chCharCode != '.' && _dotPos == 0 && inputlen > 8) return;


	if(chCharCode < '0' || chCharCode > '9'){
		if(chCharCode != '.' && chCharCode != '-' && chCharCode != 0x08){
			return;
		}
		if(chCharCode == '-'){
			if(_isEmpty) return;
			if(_l1str.C_Str()[0] == '-'){
				_l1str = _l1str.SubStr(1,_l1str.Length() - 1);
			}else{
				CMzString Ssign = L"-";
				_l1str = Ssign + _l1str;
			}
			return;
		}
		if(chCharCode == '.'){
			if(_dotPos != 0){
				return;
			}else{
				_dotPos = inputlen + 1;
				chCharCode = '.';
			}
		}
		if(chCharCode == 0x08){ //backspace
			if(inputlen == _dotPos){
				_dotPos = 0;
			}
			removeChar1();
			return;
		}
	}
	addChar(chCharCode,_l1str);
	if(_isEmpty) _isEmpty = false;
}
예제 #3
0
double UiNumericDisplay::getInputval(){
	double retval = 0.0;
	if(_l1str.Length()){
		swscanf(_l1str.C_Str(),L"%lf",&retval);
	}
	return retval;
}
예제 #4
0
void UiLineGraph::PaintWin(HDC hdc, RECT* prcWin, RECT* prcUpdate){
	UiWin::PaintWin(hdc,prcWin,prcUpdate);
	m_x = 70;
	m_y = m_h - 20;

	if(_reqUpdate){
		_reqUpdate = false;

		SelectObject(pMemDC, pBitmap);
		HBRUSH myBrush = CreateSolidBrush(RGB(255-16,255-16,255-16));
		RECT rect;
		rect.top = 0;
		rect.bottom = m_nMaxY;
		rect.left = 0;
		rect.right = m_nMaxX;

		FillRect(pMemDC,&rect,myBrush);//画之前先擦除.
		SetTextColor(RGB(0,0,0));
		SetBkMode(pMemDC,TRANSPARENT);

		//无数据是显示提示
		if(m_items.size() == 0){
			HFONT font = FontHelper::GetFont(30);
			SelectObject(pMemDC,font);
			HPEN pen = CreatePen(PS_SOLID, 0,RGB(128,128,128));
			HPEN poldpen = (HPEN)SelectObject(pMemDC,pen);
			int cx = m_x + m_nMaxX / 2;
			int cy = m_y + m_nMaxY / 2 - 20 * 5;
			int ch = m_nMaxX / 2;
			int cw = m_nMaxY / 2;
			RECT textrect = {cx,cy,cx+cw,cy+ch};
			wchar_t text[16];
			wsprintf(text,LOADSTRING(IDS_STR_NO_DATA).C_Str());
			DrawText(pMemDC,text,lstrlen(text),&textrect,DT_TOP|DT_LEFT);
			SelectObject(pMemDC,poldpen);//恢复系统笔
			BitBlt(hdc,prcWin->left,prcWin->top,m_nMaxX,m_nMaxY,pMemDC,0,0,SRCCOPY);
			return;
		}
		
		
		HPEN poldpen;//用来保存系统笔

		//转换成相对值,用户只需直接输入数值就好了
		ReformatArray();
		//设置绘画高度和间隔
		int stepwidth = m_w / m_nItems;
		int viewRectHeight = (m_h/2 - 15);
		int sy = m_y/2 + 10;
		int stepheight = (m_h - 15) / 10;
		m_y = sy + stepheight*5;
		//绘制方格
		//竖线
		HBRUSH brush = CreateSolidBrush(RGB(128,128,128));
		SelectObject(pMemDC,brush);
		HPEN pen = CreatePen(PS_DASH, 1,RGB(128,128,128));
		SelectObject(pMemDC,pen);
		for(int i = 0; i <= m_nItems; i++){
			drawLine(m_x + i*stepwidth,sy - viewRectHeight,m_x + i*stepwidth,m_y);
		}
		
		int i = 0;
		drawLine(m_x,sy - viewRectHeight,m_x + m_nItems*stepwidth, sy - viewRectHeight);
		drawLine(m_x,m_y,m_x + m_nItems*stepwidth, m_y);
		while(1){
			int y1 = sy - stepheight*i;
			int y2 = sy + stepheight*i;
			if(y1 < sy - viewRectHeight || y2 > m_y) break;
			drawLine(m_x,y1,m_x + m_nItems*stepwidth, y1);
			drawLine(m_x,y2,m_x + m_nItems*stepwidth, y2);
			i++;
		}
		//横线
		DeleteObject(brush);
		DeleteObject(pen);
		//绘制折线
		//viewRectHeight -= 10;
		list<LineGraphInfo_ptr>::iterator it = m_items.begin();
		int gsy = sy + (m_B + 1);
		for(; it != m_items.end(); it++){
			LineGraphInfo_ptr lg = *it;
			if(lg->formatdata.size() == 0) continue;

			HBRUSH brush = CreateSolidBrush(lg->color);
			SelectObject(pMemDC,brush);
			HPEN pen = CreatePen(PS_SOLID, m_B,lg->color);
			SelectObject(pMemDC,pen);

			list<int>::iterator idt = lg->formatdata.begin();
			int predt = *idt++;
			int x0 = m_x;
			int y0 = gsy - ((viewRectHeight*predt)/100);
			int cnt = 1;
			for(; idt != lg->formatdata.end(); idt++){
				int dt = *idt;
				int x1 = m_x + cnt*stepwidth;
				int y1 = gsy - ((viewRectHeight*dt)/100);
				drawLine(x0,y0,x1,y1);
				x0 = x1;
				y0 = y1;
				cnt++;
			}
			DeleteObject(brush);
			DeleteObject(pen);
			gsy -= (m_B + 1);
		}

		//绘制y轴
		HFONT font = FontHelper::GetFont(15);
		SelectObject(pMemDC,font);
		pen = CreatePen(PS_SOLID, 4,RGB(0,0,0));
		poldpen = (HPEN)SelectObject(pMemDC,pen);

		RECT textrect = {0, sy - 10,65,sy + 10};
		wchar_t strval[36];
		strval[0] = '0';
		strval[1] = 0;
		DrawText(pMemDC,strval,1,&textrect,DT_VCENTER|DT_RIGHT);

		RECT textrect2;
		textrect2.left = textrect.left;
		textrect2.right = textrect.right;
		int maxYs = 5;
		if(maxval < 600){
			maxYs = maxval/100-1;
		}
		int stepval = maxval/(100*5);
		for(int i = 1; i <= maxYs; i++){
			textrect2.top = textrect.top - i * stepheight;
			textrect2.bottom = textrect2.top + 20;
			wsprintf(strval,L"%d",stepval*i);
			DrawText(pMemDC,strval,lstrlen(strval),&textrect2,DT_VCENTER|DT_RIGHT);
			textrect2.top = textrect.top + i * stepheight;
			textrect2.bottom = textrect2.top + 20;
			wsprintf(strval,L"%d",stepval*i*(-1));
			DrawText(pMemDC,strval,lstrlen(strval),&textrect2,DT_VCENTER|DT_RIGHT);
		}
		
		//m_x + i*stepwidth,sy - viewRectHeight,m_x + i*stepwidth,m_y
		textrect.top = m_y + 5;
		textrect.bottom = m_y + 20;
		list<CMzString>::iterator istr = m_xnames.begin();
		int cnt = 0;
		for(; istr != m_xnames.end(); istr++){
			if(cnt%2 == 0){
				textrect.left = m_x - stepwidth/2 + cnt * stepwidth;
				textrect.right = textrect.left + 60;
				CMzString s = *istr;
				DrawText(pMemDC,s.C_Str(),s.Length(),&textrect,DT_LEFT|DT_VCENTER);
			}
			cnt++;
		}
		DeleteObject(pen);

		if(_showLegend){
			////////////////
			//绘制图例标签:
			list<LineGraphInfo_ptr>::iterator it = m_items.begin();

			HFONT font = FontHelper::GetFont(15);
			SelectObject(pMemDC,font);
			int cnt = 0;
			int lsx = m_x + m_w - 200;
			int lsy = sy - viewRectHeight;
			for(;it != m_items.end();it++)
			{
				LineGraphInfo_ptr pitem = *it;
				int x1 = lsx;
				int y1 = lsy + 30 * cnt;
				int x2 = x1 + 30;
				int y2 = y1;

				HPEN pen = CreatePen(PS_SOLID, 4,pitem->color);
				poldpen = (HPEN)SelectObject(pMemDC,pen);
				drawLine(x1,y1 + 10,x2,y2 + 10);

				RECT textrect = {x1 + 35, y1,x1 + 200,y1 + 30};
				DrawText(pMemDC,pitem->name.C_Str(),pitem->name.Length(),&textrect,DT_TOP|DT_LEFT);
				cnt++;
				DeleteObject(pen);
			}
			/////////////////////////////////////////*/
			SelectObject(pMemDC,poldpen);//恢复系统笔
		}

	}
	BitBlt(hdc,prcWin->left,prcWin->top,m_nMaxX,m_nMaxY,pMemDC,0,0,SRCCOPY);
}