Ejemplo n.º 1
0
/* draw route on the map */
void GPXRoute::Draw(kGUICorners *c)
{
	unsigned int i;
	GPXRouteEntry *re;
	kGUIColor col;
	kGUIColor col2;
	int px,py,lpx=0,lpy=0;
	GPXRow *row;

	/* todo, bounding box for route, compare against the corners */

	col=GPX::GetTableColor(GetColorIndex());
	col2=GPX::GetTableTColor(GetColorIndex());

	for(i=0;i<m_numentries;++i)
	{
		re=m_entries.GetEntry(i);
		row=gpx->Locate(&re->m_wptname);
		if(!row)
			return;	/* error, missing waypoint in track!!! */
		gpx->m_curmap->ToMap(row->GetCoord(),&px,&py);
		px-=c->lx;
		py-=c->ty;
		if(i)
			GPXRoute::DrawLine(i,px,py,lpx,lpy,col);
		lpx=px;
		lpy=py;
	}
}
Ejemplo n.º 2
0
//悔棋控制
bool CGameLogic::RegretChess(WORD wStepCount)
{
	//效验参数
	ASSERT(wStepCount<=(WORD)m_ChessManualInfo.GetCount());

	//变量定义
	tagChessManual * pChessManual=NULL;
	INT_PTR nManualCount=m_ChessManualInfo.GetCount();

	//悔棋操作
	for (WORD i=0;i<wStepCount;i++)
	{
		//变量定义
		pChessManual=&m_ChessManualInfo[nManualCount-i-1];

		//获取棋子
		tagChessItem * pSourceChessItem=&m_ChessItem[GetColorIndex(pChessManual->cbSourceColor)][pChessManual->cbSourceID];
		tagChessItem * pTargetChessItem=(pChessManual->cbUniteChess!=NO_CHESS)?pTargetChessItem=&m_ChessItem[GetColorIndex(pChessManual->cbUniteColor)][pChessManual->cbUniteID]:NULL;

		//效验坐标
		ASSERT(pSourceChessItem->cbXPos!=255);
		ASSERT(pSourceChessItem->cbYPos!=255);

		//设置步数
		m_wStepCount[GetColorIndex(pChessManual->cbSourceColor)]--;

		//设置源棋
		pSourceChessItem->wWalkCount--;
		pSourceChessItem->cbChess=pChessManual->cbSourceChess;
		pSourceChessItem->cbXPos=pChessManual->cbXSourceChessPos;
		pSourceChessItem->cbYPos=pChessManual->cbYSourceChessPos;

		//关联棋子
		if (pTargetChessItem!=NULL)
		{
			pTargetChessItem->cbXPos=pChessManual->cbXUniteChessPos;
			pTargetChessItem->cbYPos=pChessManual->cbYUniteChessPos;
			if (pSourceChessItem->cbColor==pTargetChessItem->cbColor) pTargetChessItem->wWalkCount--;
		}
	}

	//删除棋谱
	m_ChessManualInfo.RemoveAt(nManualCount-wStepCount,wStepCount);

	//更新棋盘
	UpdateChessBorad();

	return true;
}
Ejemplo n.º 3
0
//重绘选项卡
void SiTabCtl_OnDrawItem(DRAWITEMSTRUCT* item)
{
	HBRUSH hBrush;
	TCITEM tci;
	char text[SI_BUF_SIZE];
	int type;

	memset(&tci,0,sizeof(TCITEM));
	tci.mask = TCIF_TEXT | TCIF_STATE;
	tci.pszText = (LPSTR)text;
	tci.cchTextMax = SI_BUF_SIZE;
	TabCtrl_GetItem(hwnd_tab_ctl,item->itemID,&tci);

	type = GetColorIndex(text);
	//创建颜色为hdc(窗口矩形)背景色的实画刷
	hBrush = CreateSolidBrush(color_table[type]);
	if(SiTabCtl_GetCurItem() == item->itemID)
	{
		hBrush = CreateSolidBrush(RGB(255,0,0));
	}
    //SetTextColor(lpDrawItem->hDC, RGB(0, 0, 255));
    //FrameRect(item->hDC,&item->rcItem,hBrush);
    FillRect(item->hDC,&item->rcItem,hBrush);
    DeleteObject(hBrush);
    SetBkMode(item->hDC,TRANSPARENT);
    DrawText(item->hDC,text,strlen(text),&item->rcItem,DT_CENTER|DT_LEFT|DT_VCENTER|DT_SINGLELINE);
}
Ejemplo n.º 4
0
bool GPXRoute::Compare(kGUITableObj *table,kGUITickBoxObj *draw,kGUIComboBoxObj *color)
{
	unsigned int e;
	kGUIObj *obj;
	GPXRow *row;
	GPXRouteEntry *re;

	if(table->GetNumChildren(0)!=m_numentries)
		return(true);

	/* draw flag has changed */
	if(draw->GetSelected()!=GetDraw())
		return(true);

	/* color has changed? */
	if((unsigned int)color->GetSelection()!=GetColorIndex())
		return(true);

	for(e=0;e<m_numentries;++e)
	{
		re=m_entries.GetEntry(e);	/* route record */
		obj=table->GetChild(e);
		row=static_cast<GPXRow *>(obj);

		if(strcmp(row->GetWptName(),re->m_wptname.GetString()))
			return(true);
	}
	return(false);	/* same! */
}
Ejemplo n.º 5
0
// Flattens the canvas 
// Starting from layer 1 and moving up, any non-default colors are overlayed onto layer 0
void FlattenCanvas(Canvas *c) {
  for (int l = 1; l < c->num_layers; l++) {
    for (int y = 0; y < c->y_size; y++) {
      for (int x = 0; x < c->x_size; x++) {
        int color = GetColorIndex(c, y, x, l);
        if (color != CANVAS_DEFAULT_COLOR) {
          SetColor(c, y, x, 0, color);
        }
      }
    }
  }
}
Ejemplo n.º 6
0
void GPXRoute::Load(kGUITableObj *table,kGUITickBoxObj *draw,kGUIComboBoxObj *color)
{
	unsigned int e;
	GPXRow *row;
	GPXRow *fullrow;
	GPXRouteEntry *re;

	draw->SetSelected(GetDraw());
	color->SetSelectionz(GetColorIndex());

	table->DeleteChildren();
	for(e=0;e<m_numentries;++e)
	{
		re=m_entries.GetEntry(e);	/* route record */
		fullrow=gpx->Locate(&re->m_wptname);
		if(fullrow)
		{
			row=new GPXRow();	/* copy record from full table */
			row->Copy(fullrow);
			table->AddRow(row);
		}
	}
}
Ejemplo n.º 7
0
void GPXRoute::Save(kGUIXMLItem *xml)
{
	unsigned int e;
	unsigned int nc;
	GPXRouteEntry *re;
	kGUIXMLItem *fxml;
	kGUIXMLItem *flxml;

	/* count number of points in the route */
	nc=0;
	for(e=0;e<m_numentries;++e)
	{
		re=m_entries.GetEntry(e);	/* route record */
		if(gpx->Locate(&re->m_wptname))
			++nc;
	}

	/* if no entries in route then don't save it */
	if(nc)
	{
		fxml=xml->AddChild("route");
		fxml->AddParm("name",m_name.GetString());

		fxml->AddParm("draw",GetDraw()==true?"1":"0");
		fxml->AddParm("color",GPX::GetTableColorName(GetColorIndex()));

		for(e=0;e<m_numentries;++e)
		{
			re=m_entries.GetEntry(e);	/* route record */
	
			/* only save if point is still in the main table */
			if(gpx->Locate(&re->m_wptname))
				flxml=fxml->AddChild("wptname",re->m_wptname.GetString());
		}
	}
}
Ejemplo n.º 8
0
//获取步数
WORD CGameLogic::GetStepCount(BYTE cbColor)
{
	ASSERT((cbColor==BLACK_CHESS)||(cbColor==WHITE_CHESS));
	return m_wStepCount[GetColorIndex(cbColor)];
}
/*!
	対括弧の強調表示
	@date 2002/09/18 ai
	@date 2003/02/18 ai 再描画対応の為大改造
*/
void CEditView::DrawBracketPair( bool bDraw )
{
	// 03/03/06 ai すべて置換、すべて置換後のUndo&Redoがかなり遅い問題に対応
	if( m_bDoing_UndoRedo || !GetDrawSwitch() ){
		return;
	}

	if( !m_pTypeData->m_ColorInfoArr[COLORIDX_BRACKET_PAIR].m_bDisp ){
		return;
	}

	// 括弧の強調表示位置が未登録の場合は終了
	if( m_ptBracketPairPos_PHY.HasNegative() || m_ptBracketCaretPos_PHY.HasNegative() ){
		return;
	}

	// 描画指定(bDraw=true)				かつ
	// ( テキストが選択されている		又は
	//   選択範囲を描画している			又は
	//   フォーカスを持っていない		又は
	//   アクティブなペインではない )	場合は終了
	if( bDraw
	 &&( GetSelectionInfo().IsTextSelected() || GetSelectionInfo().m_bDrawSelectArea || !m_bDrawBracketPairFlag
	 || ( m_pcEditWnd->GetActivePane() != m_nMyIndex ) ) ){
		return;
	}

	CGraphics gr;
	gr.Init(::GetDC(GetHwnd()));
	bool bCaretChange = false;
	gr.SetTextBackTransparent(true);

	for( int i = 0; i < 2; i++ )
	{
		// i=0:対括弧,i=1:カーソル位置の括弧
		// 2011.11.23 ryoji 対括弧 -> カーソル位置の括弧 の順に処理順序を変更
		//   # { と } が異なる行にある場合に { を BS で消すと } の強調表示が解除されない問題(Wiki BugReport/89)の対策
		//   # この順序変更によりカーソル位置が括弧でなくなっていても対括弧があれば対括弧側の強調表示は解除される

		CLayoutPoint	ptColLine;

		if( i == 0 ){
			m_pcEditDoc->m_cLayoutMgr.LogicToLayout( m_ptBracketPairPos_PHY,  &ptColLine );
		}else{
			m_pcEditDoc->m_cLayoutMgr.LogicToLayout( m_ptBracketCaretPos_PHY, &ptColLine );
		}

		if ( ( ptColLine.x >= GetTextArea().GetViewLeftCol() ) && ( ptColLine.x <= GetTextArea().GetRightCol() )
			&& ( ptColLine.y >= GetTextArea().GetViewTopLine() ) && ( ptColLine.y <= GetTextArea().GetBottomLine() ) )
		{	// 表示領域内の場合
			if( !bDraw && GetSelectionInfo().m_bDrawSelectArea && ( 0 == IsCurrentPositionSelected( ptColLine ) ) )
			{	// 選択範囲描画済みで消去対象の括弧が選択範囲内の場合
				continue;
			}
			const CLayout* pcLayout;
			CLogicInt		nLineLen;
			const wchar_t*	pLine = m_pcEditDoc->m_cLayoutMgr.GetLineStr( ptColLine.GetY2(), &nLineLen, &pcLayout );
			if( pLine )
			{
				EColorIndexType		nColorIndex;
				CLogicInt	OutputX = LineColumnToIndex( pcLayout, ptColLine.GetX2() );
				if( bDraw )	{
					nColorIndex = COLORIDX_BRACKET_PAIR;
				}
				else{
					if( IsBracket( pLine, OutputX, CLogicInt(1) ) ){
						DispPos _sPos(0,0); // 注意:この値はダミー。CheckChangeColorでの参照位置は不正確
						SColorStrategyInfo _sInfo;
						SColorStrategyInfo* pInfo = &_sInfo;
						pInfo->m_pDispPos = &_sPos;
						pInfo->m_pcView = this;

						// 03/10/24 ai 折り返し行のColorIndexが正しく取得できない問題に対応
						// 2009.02.07 ryoji GetColorIndex に渡すインデックスの仕様変更(元はこっちの仕様だった模様)
						CColor3Setting cColor = GetColorIndex( pcLayout, ptColLine.GetY2(), OutputX, pInfo );
						nColorIndex = cColor.eColorIndex2;
					}
					else{
						SetBracketPairPos( false );
						break;
					}
				}
				CTypeSupport    cCuretLineBg(this,COLORIDX_CARETLINEBG);
				EColorIndexType nColorIndexBg = (cCuretLineBg.IsDisp() && ptColLine.GetY2() == GetCaret().GetCaretLayoutPos().GetY2()
					? COLORIDX_CARETLINEBG
					: CTypeSupport(this,COLORIDX_EVENLINEBG).IsDisp() && ptColLine.GetY2() % 2 == 1
						? COLORIDX_EVENLINEBG
						: COLORIDX_TEXT);
				// 03/03/03 ai カーソルの左に括弧があり括弧が強調表示されている状態でShift+←で選択開始すると
				//             選択範囲内に反転表示されない部分がある問題の修正
				CLayoutInt caretX = GetCaret().GetCaretLayoutPos().GetX2();
				bool bCaretHide = (!bCaretChange && (ptColLine.x == caretX || ptColLine.x + 1 == caretX) && GetCaret().GetCaretShowFlag());
				if( bCaretHide ){
					bCaretChange = true;
					GetCaret().HideCaret_( GetHwnd() );	// キャレットが一瞬消えるのを防止
				}
				{
					int nWidth  = GetTextMetrics().GetHankakuDx();
					int nHeight = GetTextMetrics().GetHankakuDy();
					int nLeft = (GetTextArea().GetDocumentLeftClientPointX()) + GetTextMetrics().GetCharPxWidth(ptColLine.x);
					int nTop  = (Int)( ptColLine.GetY2() - GetTextArea().GetViewTopLine() ) * nHeight + GetTextArea().GetAreaTop();
					CLayoutXInt charsWidth = m_pcEditDoc->m_cLayoutMgr.GetLayoutXOfChar(pLine, nLineLen, OutputX);

					//色設定
					CTypeSupport cTextType(this,COLORIDX_TEXT);
					cTextType.SetGraphicsState_WhileThisObj(gr);
					// 2013.05.24 背景色がテキストの背景色と同じならカーソル行の背景色を適用
					CTypeSupport cColorIndexType(this,nColorIndex);
					CTypeSupport cColorIndexBgType(this,nColorIndexBg);
					CTypeSupport* pcColorBack = &cColorIndexType;
					if( cColorIndexType.GetBackColor() == cTextType.GetBackColor() && nColorIndexBg != COLORIDX_TEXT ){
						pcColorBack = &cColorIndexBgType;
					}

					SetCurrentColor( gr, nColorIndex, nColorIndex, nColorIndexBg );
					bool bTrans = false;
					// DEBUG_TRACE( _T("DrawBracket %d %d ") , ptColLine.y, ptColLine.x );
					if( IsBkBitmap() &&
							cTextType.GetBackColor() == pcColorBack->GetBackColor() ){
						bTrans = true;
						RECT rcChar;
						rcChar.left  = nLeft;
						rcChar.top = nTop;
						rcChar.right = nLeft + GetTextMetrics().GetCharPxWidth(charsWidth);
						rcChar.bottom = nTop + nHeight;
						HDC hdcBgImg = ::CreateCompatibleDC(gr);
						HBITMAP hBmpOld = (HBITMAP)::SelectObject(hdcBgImg, m_pcEditDoc->m_hBackImg);
						DrawBackImage(gr, rcChar, hdcBgImg);
						::SelectObject(hdcBgImg, hBmpOld);
						::DeleteDC(hdcBgImg);
					}
					DispPos sPos(nWidth, nHeight);
					sPos.InitDrawPos(CMyPoint(nLeft, nTop));
					GetTextDrawer().DispText(gr, &sPos, 0, &pLine[OutputX], 1, bTrans);
					GetTextDrawer().DispNoteLine(gr, nTop, nTop + nHeight, nLeft, nLeft + (Int)charsWidth * nWidth);
					// 2006.04.30 Moca 対括弧の縦線対応
					GetTextDrawer().DispVerticalLines(gr, nTop, nTop + nHeight, ptColLine.x, ptColLine.x + charsWidth); //※括弧が全角幅である場合を考慮
					cTextType.RewindGraphicsState(gr);
				}

				if( ( m_pcEditWnd->GetActivePane() == m_nMyIndex )
					&& ( ( ptColLine.y == GetCaret().GetCaretLayoutPos().GetY() ) || ( ptColLine.y - 1 == GetCaret().GetCaretLayoutPos().GetY() ) ) ){	// 03/02/27 ai 行の間隔が"0"の時にアンダーラインが欠ける事がある為修正
					GetCaret().m_cUnderLine.CaretUnderLineON( true, false );
				}
			}
		}
	}
	if( bCaretChange ){
		GetCaret().ShowCaret_( GetHwnd() );	// キャレットが一瞬消えるのを防止
	}

	::ReleaseDC( GetHwnd(), gr );
}
Ejemplo n.º 10
0
Archivo: png.c Proyecto: ncareol/ncplot
/* -------------------------------------------------------------------- */
static void _SavePNG(char file_name[], XImage *image)
{
  int		i, j;
  FILE		*outFP;
  unsigned short *s;
  png_structp	png_ptr;
  png_infop	info_ptr;
  png_bytep	row_pointers[2000];

  png_color	*palette;


  if ((outFP = fopen(file_name, "wb")) == NULL)
    return;


  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
			(png_voidp)NULL, NULL, NULL);

  if (!png_ptr) {
    fclose(outFP);
    return;
  }

  info_ptr = png_create_info_struct(png_ptr);

  if (!info_ptr) {
    png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    fclose(outFP);
    return;
    }


#if PNG_LIBPNG_VER >= 10500
  if (setjmp(png_jmpbuf(png_ptr))) {
#else
   if (setjmp(png_ptr->jmpbuf)) {
#endif
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(outFP);
    return;
    }


  png_init_io(png_ptr, outFP);


  png_set_IHDR(png_ptr, info_ptr,
	image->width, image->height, 8,
	PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
	PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);


  if ((palette = new png_color[NumberOfColors()]) == NULL)
      return;

  for (i = 0; i < NumberOfColors(); i++) {
    s = GetColorRGB_X(i);
    palette[i].red   = s[0];
    palette[i].green = s[1];
    palette[i].blue  = s[2];
    }

  /* Force background to white.
   */
  palette[i-1].red = palette[i-1].green = palette[i-1].blue = 0xffff;

  png_set_PLTE(png_ptr, info_ptr, palette, NumberOfColors());


  /* Write header info to PNG file. */
  png_write_info(png_ptr, info_ptr);

  for (i = 0; i < image->height; ++i)
    {
    char *p = &(image->data[i * image->bytes_per_line]);

    row_pointers[i] = new png_byte[image->width];

    switch (image->depth)
      {
      case 8:
        for (j = 0; j < image->width; ++j)
          row_pointers[i][j] = (png_byte)GetColorIndex(((char *)p)[j]);
        break;

      case 16:
        for (j = 0; j < image->width; ++j)
          row_pointers[i][j] = (png_byte)GetColorIndex(((uint16_t *)p)[j]);

        break;

      case 24: case 32:
        for (j = 0; j < image->width; ++j)
          row_pointers[i][j] = (png_byte)GetColorIndex(((uint32_t *)p)[j]);

        break;
      }
    }


  /* Write the data! */
  png_write_image(png_ptr, row_pointers);
  png_write_end(png_ptr, info_ptr);

  png_destroy_write_struct(&png_ptr, &info_ptr);

  for (i = 0; i < image->height; ++i)
    delete [] row_pointers[i];

  delete [] palette;
  fclose(outFP);

}
Ejemplo n.º 11
0
Archivo: LCD.c Proyecto: byxob/calendar
void LCD_SetBkColorIndex(int Index) { LCD_ACOLORINDEX[GetColorIndex(0)] = Index; }
Ejemplo n.º 12
0
/*!
	行のテキスト/選択状態の描画
	1回で1ロジック行分を作画する。

	@return EOFを作画したらtrue

	@date 2001.02.17 MIK
	@date 2001.12.21 YAZAKI 改行記号の描きかたを変更
	@date 2007.08.31 kobake 引数 bDispBkBitmap を削除
*/
bool CEditView::DrawLogicLine(
	HDC				_hdc,			//!< [in]     作画対象
	DispPos*		_pDispPos,		//!< [in,out] 描画する箇所、描画元ソース
	CLayoutInt		nLineTo			//!< [in]     作画終了するレイアウト行番号
)
{
//	MY_RUNNINGTIMER( cRunningTimer, "CEditView::DrawLogicLine" );
	bool bDispEOF = false;
	SColorStrategyInfo _sInfo;
	SColorStrategyInfo* pInfo = &_sInfo;
	pInfo->m_gr.Init(_hdc);
	pInfo->m_pDispPos = _pDispPos;
	pInfo->m_pcView = this;

	//CColorStrategyPool初期化
	CColorStrategyPool* pool = CColorStrategyPool::getInstance();
	pool->SetCurrentView(this);
	pool->NotifyOnStartScanLogic();
	bool bSkipBeforeLayout = pool->IsSkipBeforeLayout();

	//DispPosを保存しておく
	pInfo->m_sDispPosBegin = *pInfo->m_pDispPos;

	//処理する文字位置
	pInfo->m_nPosInLogic = CLogicInt(0); //☆開始

	// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
	//          論理行データの取得 -> pLine, pLineLen              //
	// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- //
	// 前行の最終設定色
	{
		const CLayout* pcLayout = pInfo->m_pDispPos->GetLayoutRef();
		if( bSkipBeforeLayout ){
			EColorIndexType eRet = COLORIDX_TEXT;
			const CLayoutColorInfo* colorInfo = NULL;
			if( pcLayout ){
				eRet = pcLayout->GetColorTypePrev(); // COLORIDX_TEXTのはず
				colorInfo = pcLayout->GetColorInfo();
			}
			pInfo->m_pStrategy = pool->GetStrategyByColor(eRet);
			if( pInfo->m_pStrategy ){
				pInfo->m_pStrategy->InitStrategyStatus();
				pInfo->m_pStrategy->SetStrategyColorInfo(colorInfo);
			}
		}else{
			CColor3Setting cColor = GetColorIndex(pcLayout, pInfo->m_pDispPos->GetLayoutLineRef(), 0, pInfo, true);
			SetCurrentColor(pInfo->m_gr, cColor.eColorIndex, cColor.eColorIndex2, cColor.eColorIndexBg);
		}
	}

	//開始ロジック位置を算出
	{
		const CLayout* pcLayout = pInfo->m_pDispPos->GetLayoutRef();
		pInfo->m_nPosInLogic = pcLayout?pcLayout->GetLogicOffset():CLogicInt(0);
	}

	for (;;) {
		//対象行が描画範囲外だったら終了
		if( GetTextArea().GetBottomLine() < pInfo->m_pDispPos->GetLayoutLineRef() ){
			pInfo->m_pDispPos->SetLayoutLineRef(nLineTo + CLayoutInt(1));
			break;
		}
		if( nLineTo < pInfo->m_pDispPos->GetLayoutLineRef() ){
			break;
		}

		//レイアウト行を1行描画
		bDispEOF = DrawLayoutLine(pInfo);

		//行を進める
		CLogicInt nOldLogicLineNo = pInfo->m_pDispPos->GetLayoutRef()->GetLogicLineNo();
		pInfo->m_pDispPos->ForwardDrawLine(1);		//描画Y座標++
		pInfo->m_pDispPos->ForwardLayoutLineRef(1);	//レイアウト行++

		// ロジック行を描画し終わったら抜ける
		if(pInfo->m_pDispPos->GetLayoutRef()->GetLogicLineNo()!=nOldLogicLineNo){
			break;
		}

		// nLineToを超えたら抜ける
		if(pInfo->m_pDispPos->GetLayoutLineRef() >= nLineTo + CLayoutInt(1)){
			break;
		}
	}

	return bDispEOF;
}