コード例 #1
0
void COptionTreeColorPopUp::OnPaint() 
{
    // Declare variables
	CPaintDC dc(this);
	CRect rcClient;

	// Get client rect
	GetClientRect(rcClient);

    // Draw the Default Area text
    if (m_strDefaultText.GetLength())
	{
        DrawCell(&dc, OT_COLOR_DEFAULTBOXVALUE);
	}
 
    // Draw color cells
    for (int i = 0; i < m_nNumColors; i++)
	{
        DrawCell(&dc, i);
	}
    
    // Draw custom text
    if (m_strCustomText.GetLength())
	{
        DrawCell(&dc, OT_COLOR_CUSTOMBOXVALUE);
	}

    // Draw raised window edge (ex-window style WS_EX_WINDOWEDGE is sposed to do this, but for some reason isn't
    dc.DrawEdge(rcClient, EDGE_RAISED, BF_RECT);
}
コード例 #2
0
ファイル: ColourPopup.cpp プロジェクト: Fetze/busmaster
/*******************************************************************************
  Function Name  : OnPaint
  Input(s)       : -
  Output         : -
  Functionality  : Draws the color pallete, selection and user text.
  Member of      : CColourPopup
  Author(s)      : Raja N
  Date Created   : 09/12/2004
  Modifications  : 
*******************************************************************************/
void CColourPopup::OnPaint() 
{
    CPaintDC dc(this); // device context for painting

    // Draw the Default Area text
    if (m_strDefaultText.GetLength() > 0)
    {
        DrawCell(&dc, DEFAULT_BOX_VALUE);
    }
 
    // Draw colour cells
    for (int i = 0; i < m_nNumColours; i++)
    {
        DrawCell(&dc, i);
    }

    // Draw custom text
    if (m_strCustomText.GetLength() > 0)
    {
        DrawCell(&dc, CUSTOM_BOX_VALUE);
    }
    // Draw raised window edge
    CRect rect;
    GetClientRect(rect);
    dc.DrawEdge(rect, EDGE_RAISED, BF_RECT);
}
コード例 #3
0
void CColourPopup::ChangeSelection(int nIndex)
{
    CClientDC dc(this);        // device context for drawing

    if (nIndex > m_nNumColours)
        nIndex = CUSTOM_BOX_VALUE; 

    if ((m_nCurrentSel >= 0 && m_nCurrentSel < m_nNumColours) ||
        m_nCurrentSel == CUSTOM_BOX_VALUE || m_nCurrentSel == DEFAULT_BOX_VALUE)
    {
        // Set Current selection as invalid and redraw old selection (this way
        // the old selection will be drawn unselected)
        int OldSel = m_nCurrentSel;
        m_nCurrentSel = INVALID_COLOUR;
        DrawCell(&dc, OldSel);
    }

    // Set the current selection as row/col and draw (it will be drawn selected)
    m_nCurrentSel = nIndex;
    DrawCell(&dc, m_nCurrentSel);

    // Store the current colour
    if (m_nCurrentSel == CUSTOM_BOX_VALUE)
        m_pParent->SendMessage(CPN_SELCHANGE, (WPARAM) m_crInitialColour, 0);
    else if (m_nCurrentSel == DEFAULT_BOX_VALUE)
    {
        m_crColour = CLR_DEFAULT;
        m_pParent->SendMessage(CPN_SELCHANGE, (WPARAM) CLR_DEFAULT, 0);
    }
    else
    {
        m_crColour = GetColour(m_nCurrentSel);
        m_pParent->SendMessage(CPN_SELCHANGE, (WPARAM) m_crColour, 0);
    }
}
コード例 #4
0
void DrawCell( TMVA::PDEFoamCell *cell, TMVA::PDEFoam *foam,
	       Double_t x, Double_t y,
	       Double_t xscale,  Double_t yscale )
{
   // recursively draw cell and it's daughters

   Float_t xsize = xscale*1.5;
   Float_t ysize = yscale/3;
   if (xsize > 0.15) xsize=0.1; //xscale/2;
   if (cell->GetDau0() != NULL) {
      TLine *a1 = new TLine(x-xscale/4, y-ysize, x-xscale, y-ysize*2);
      a1->SetLineWidth(2);
      a1->Draw();
      DrawCell(cell->GetDau0(), foam, x-xscale, y-yscale, xscale/2, yscale);
   }
   if (cell->GetDau1() != NULL){
      TLine *a1 = new TLine(x+xscale/4, y-ysize, x+xscale, y-ysize*2);
      a1->SetLineWidth(2);
      a1->Draw();
      DrawCell(cell->GetDau1(), foam, x+xscale, y-yscale, xscale/2, yscale);
   }

   TPaveText *t = new TPaveText(x-xsize, y-ysize, x+xsize, y+ysize, "NDC");

   t->SetBorderSize(1);
   t->SetFillStyle(1);

   // draw all cell elements
   t->AddText( Form("Intg=%.5f", cell->GetIntg()) );
   t->AddText( Form("Var=%.5f", cell->GetDriv()) );
   TVectorD *vec = (TVectorD*) cell->GetElement();
   if (vec != NULL){
      for (Int_t i = 0; i < vec->GetNrows(); ++i) {
	 t->AddText( Form("E[%i]=%.5f", i, vec(i)) );
      }
   }

   if (cell->GetStat() != 1) {
      // cell is inactive --> draw split point
      t->SetFillColor( TColor::GetColor("#BBBBBB") );
      t->SetTextColor( TColor::GetColor("#000000") );

      // cell position and size
      TMVA::PDEFoamVect cellPosi(foam->GetTotDim()), cellSize(foam->GetTotDim());
      cell->GetHcub(cellPosi, cellSize);
      Int_t    kBest = cell->GetBest(); // best division variable
      Double_t xBest = cell->GetXdiv(); // best division point
      t->AddText( Form("dim=%i", kBest) );
      t->AddText( Form("cut=%.5g", foam->VarTransformInvers(kBest,cellPosi[kBest] + xBest*cellSize[kBest])) );
   } else {
      t->SetFillColor( TColor::GetColor("#DD0033") );
      t->SetTextColor( TColor::GetColor("#FFFFFF") );
   }

   t->Draw();

   return;
}
コード例 #5
0
short UpdateNewMove(void)
{
    short from, dest, p;
    from = newmove.from; dest = newmove.dest; p = piece[dest];
    piece[dest] = piece[from]; piece[from] = EMPTY;
    color[dest] = color[from]; color[from] = EMPTY;
    DrawCell(from, NORMAL); DrawCell(dest, NORMAL);
    return p == KING;
}
コード例 #6
0
short GetHumanMove(void)
{
    static short x = 4, y = 5;
    short ch, from, t, i, selecting = 0;

    Gen(); /* for check legal move only */

    while (1)
    {
        MoveTo (x, y);
        ch = (short)getch();
        switch (ch)
        {
        case 13:
        case 32: /* Enter or Spacebar */
            t = x + y*SIZE_X;
            if (!selecting)
            {
                if (color[t]==side)
                {
                    selecting = 1; from = t; DrawCell(t, SELECT);
                }
            }
            else
            {
                if (t != from) DrawCell(from, NORMAL);
                if (color[t]==side)
                {
                    from = t; DrawCell(t, SELECT);
                }
                else

                {
                    newmove.from = from; newmove.dest = t;
                    for (i=gen_begin[ply]; i<gen_end[ply]; i++)
                        if (gen_dat[i].m.from==newmove.from && gen_dat[i].m.dest==newmove.dest) return 0;
                    DrawCell(from, SELECT);
                }
            }
            break;

        case 27: return 1; /* ESC */

        case 0xE0:
            ch = (short)getch();
            switch (ch)
            {
            case 75: if (x) x--; else x = SIZE_X-1; break; /* LEFT */
            case 77: if (x<SIZE_X-1) x++; else x = 0; break; /* RIGHT */
            case 72: if (y) y--; else y = SIZE_Y-1; break; /* UP */
            case 80: if (y<SIZE_Y-1) y++; else y = 0; break; /* DOWN */
            }
            break;
        } /* switch */
    } /* while */
}
コード例 #7
0
void ProcessEvent(PSEvent* event) {
  switch(event->type) {
    /* If the view updates, build a new Graphics 2D Context */
    case PSE_INSTANCE_DIDCHANGEVIEW: {
      struct PP_Rect rect;

      g_pView->GetRect(event->as_resource, &rect);
      UpdateContext(rect.size.width, rect.size.height);
      break;
    }

    case PSE_INSTANCE_HANDLEINPUT: {
      PP_InputEvent_Type type = g_pInputEvent->GetType(event->as_resource);
      PP_InputEvent_Modifier modifiers =
          g_pInputEvent->GetModifiers(event->as_resource);

      switch(type) {
        case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
          struct PP_Point location =
              g_pMouseInput->GetPosition(event->as_resource);
          DrawCell(location.x, location.y);
          break;
        }

        case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
            struct PP_Point location =
                g_pMouseInput->GetPosition(event->as_resource);

            /* If the button is down, draw */
            if (modifiers & PP_INPUTEVENT_MODIFIER_LEFTBUTTONDOWN) {
              DrawCell(location.x, location.y);
            }
          break;
        }

        case PP_INPUTEVENT_TYPE_KEYDOWN: {
          PP_Bool fullscreen = g_pFullscreen->IsFullscreen(PSGetInstanceId());
          g_pFullscreen->SetFullscreen(PSGetInstanceId(),
                                       fullscreen ? PP_FALSE : PP_TRUE);
          break;
        }
        default:
          break;
      }
      /* case PSE_INSTANCE_HANDLEINPUT */
      break;
    }

    default:
      break;
  }
}
コード例 #8
0
ファイル: mainfrm.cpp プロジェクト: BorisMomtchev/ConwaysLife
void CMainFrame::Die ()
{
	int r,c;
	CPoint* pCell;

	CPtrList* pTempList=new CPtrList;
	TransferList(&pTempList,&m_pDie);

	while(!pTempList->IsEmpty ())
	{
		pCell=(CPoint*)pTempList->RemoveHead ();
		c=pCell->x;
		r=pCell->y;
		delete pCell;

		if ((m_world[r][c]==ALIVE)&&(m_nbrs[r][c]!=2)&&(m_nbrs[r][c]!=3))
		{
			m_world[r][c]=DEAD;
			DrawCell(c,r,FALSE);
			CPoint* pCell=new CPoint(c,r);
			m_pDie->AddTail (pCell);
		}
	}
	delete pTempList;
}
コード例 #9
0
ファイル: life.cpp プロジェクト: crankycoder/wxPython-2.9.2.4
// draw all changed cells
void LifeCanvas::DrawChanged()
{
    wxClientDC dc(this);

    size_t ncells;
    LifeCell *cells;
    bool done = false;

    m_life->BeginFind(m_viewportX,
                      m_viewportY,
                      m_viewportX + m_viewportW,
                      m_viewportY + m_viewportH,
                      true);

    if (m_cellsize == 1)
    {
        dc.SetPen(*wxBLACK_PEN);
    }
    else
    {
        dc.SetPen(*wxTRANSPARENT_PEN);
        dc.SetBrush(*wxBLACK_BRUSH);
    }
    dc.SetLogicalFunction(wxINVERT);

    while (!done)
    {
        done = m_life->FindMore(&cells, &ncells);

        for (size_t m = 0; m < ncells; m++)
            DrawCell(cells[m].i, cells[m].j, dc);
    }
}
コード例 #10
0
void PlotCellTree( TString fin = "weights/TMVAClassification_PDEFoam.weights_foams.root",
		   TString cv_long, bool useTMVAStyle=kTRUE )
{
   // Draw the PDEFoam cell tree

   cout << "read file: " << fin << endl;
   TFile *file = TFile::Open(fin);

   if (useTMVAStyle)  TMVAGlob::SetTMVAStyle();

   // find foams
   TListIter foamIter(gDirectory->GetListOfKeys());
   TKey *foam_key = NULL; // the foam key
   TCanvas *canv = NULL;  // the canvas
   while (foam_key = (TKey*) foamIter()) {
      TString name(foam_key->GetName());
      TString class_name(foam_key->GetClassName());
      if (!class_name.Contains("PDEFoam"))
	 continue;
      cout << "PDEFoam found: " << class_name << " " << name << endl;

      // read the foam
      TMVA::PDEFoam *foam = (TMVA::PDEFoam*) foam_key->ReadObj();
      canv = new TCanvas(Form("canvas_%s",name.Data()),
			 Form("%s of %s",cv_long.Data(),name.Data()), 640, 480);

      // get cell tree depth
      const UInt_t   depth = foam->GetRootCell()->GetTreeDepth();
      const Double_t ystep = 1.0 / depth;
      DrawCell(foam->GetRootCell(), foam, 0.5, 1.-0.5*ystep, 0.25, ystep);
   }

   file->Close();
}
コード例 #11
0
void DrawBoard(void)
{
    int i;
    textcolor(7); textbackground(0); clrscr(); gotoxy(1,1);
    printf("\n");
    printf(" +----+----+----+----+----+----+----+----+ 9\n");
    printf(" |    |    |    |  \\ | /  |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 8\n");
    printf(" |    |    |    |  / | \\  |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 7\n");
    printf(" |    |    |    |    |    |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 6\n");
    printf(" |    |    |    |    |    |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 5\n");
    printf(" |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 4\n");
    printf(" |    |    |    |    |    |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 3\n");
    printf(" |    |    |    |    |    |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 2\n");
    printf(" |    |    |    |  \\ | /  |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 1\n");
    printf(" |    |    |    |  / | \\  |    |    |    |\n");
    printf(" +----+----+----+----+----+----+----+----+ 0\n");
    printf(" A    B    C    D    E    F    G    H    I\n");
    gotoxy(1,25); printf("Up, Down, Right, Left: cursor move Enter or Space: select ESC: escape");
    gotoxy(48,1); printf("VERY SIMPLE CHINESE CHESS PROGRAM");
    gotoxy(50,2); printf("(C) Pham Hong Nguyen. Ver %s", VERSION);

    for (i=0; i<BOARD_SIZE; i++) DrawCell(i, NORMAL);
}
コード例 #12
0
ファイル: SimpleList.cpp プロジェクト: slawer/krs_kal
void SimpleList::OnPaint()
{
	m_v_scroll_bar.Invalidate(FALSE);

	CPaintDC pdc(this);
	CDC* dc = (m_mem_dc_available)?(&m_mem_dc):(&pdc);

	int i;
	DWORD data;
	list<DWORD>::iterator c = m_data.begin();
	for (i = 0; i < m_v_scroll_bar.GetFirstVisibleElement(); i++)
		if (c != m_data.end())
			c ++;
	for (i = 0; i < m_num_visible_cells; i++)
	{
		if (c == m_data.end())
			data = 0xFFFFFFFF;
		else
		{
			data = *c;
			c++;
		}
		DrawCell(dc, i, i + m_v_scroll_bar.GetFirstVisibleElement(), data, 0, i*m_cell_h);
	}

	if (m_mem_dc_available)
		pdc.BitBlt(0, 0, m_cell_w, m_total_h, &m_mem_dc, 0, 0, SRCCOPY);
}
コード例 #13
0
ファイル: life.cpp プロジェクト: crankycoder/wxPython-2.9.2.4
// draw a cell
void LifeCanvas::DrawCell(wxInt32 i, wxInt32 j, bool alive)
{
    wxClientDC dc(this);

    dc.SetPen(alive? *wxBLACK_PEN : *wxWHITE_PEN);
    dc.SetBrush(alive? *wxBLACK_BRUSH : *wxWHITE_BRUSH);

    DrawCell(i, j, dc);
}
コード例 #14
0
void DrawSquare(HDC hdc, RECT rcClient, int ** field_array)
{
	for (int i = 0; i < Rows; i++)
	{
		for (int j = 0; j < Columns; j++)
		{
			DrawCell(hdc, field_array[i][j], rcClient.top + i * 25, rcClient.left + j * 25);
		}
	}
	return;
}
コード例 #15
0
ファイル: mainfrm.cpp プロジェクト: BorisMomtchev/ConwaysLife
void CMainFrame::OnRandomCells ()
{
	srand ((unsigned)time(NULL));

	for (UINT cell=0;cell<1000;++cell)
	{
		UINT col=rand() % NUMBEROFCOLS;
		UINT row=rand() % NUMBEROFROWS;
		m_world[row][col]=ALIVE;
		DrawCell(col,row,TRUE);
	}
}
コード例 #16
0
void __fastcall TIntMinerField::CustomDrawCellHandler(Cxgridcustomtableview::TcxCustomGridTableView* Sender, Cxgraphics::TcxCanvas* ACanvas, Cxgridcustomtableview::TcxGridTableDataCellViewInfo* AViewInfo, bool &ADone)
{
  TCellStateRec CellRec;
  int ACol = AViewInfo->Item->Index;
  int ARow = AViewInfo->RecordViewInfo->Index;
  TRect DrawRect = AViewInfo->Bounds;
  int vType = VarType(AViewInfo->Value);
  if((vType == varEmpty) || (vType == varNull)) return;
  CellRec = *(PCellStateRec)(int)AViewInfo->Value;
  DrawCell(CellRec, ACol, ARow, DrawRect, ACanvas->Canvas);
  ADone = true;
}
コード例 #17
0
void CColourPopup::OnPaint() 
{
    CPaintDC dc(this); // device context for painting

    // Draw the Default Area text
    if (m_strDefaultText.GetLength())
        DrawCell(&dc, DEFAULT_BOX_VALUE);
 
    // Draw colour cells
    for (int i = 0; i < m_nNumColours; i++)
        DrawCell(&dc, i);
    
    // Draw custom text
    if (m_strCustomText.GetLength())
        DrawCell(&dc, CUSTOM_BOX_VALUE);

    // Draw raised window edge (ex-window style WS_EX_WINDOWEDGE is sposed to do this,
    // but for some reason isn't
    CRect rect;
    GetClientRect(rect);
    dc.DrawEdge(rect, EDGE_RAISED, BF_RECT);
}
コード例 #18
0
void COptionTreeColorPopUp::ChangeSelection(int nIndex)
{
    CClientDC dc(this);

    if (nIndex > m_nNumColors)
	{
        nIndex = OT_COLOR_CUSTOMBOXVALUE; 
	}

    if ((m_nCurrentSel >= 0 && m_nCurrentSel < m_nNumColors) || m_nCurrentSel == OT_COLOR_CUSTOMBOXVALUE || m_nCurrentSel == OT_COLOR_DEFAULTBOXVALUE)
    {
        // -- Set Current selection as invalid and redraw old selection (this way
        // the old selection will be drawn unselected)
        int OldSel = m_nCurrentSel;
        m_nCurrentSel = OT_COLOR_INVALIDCOLOR;
        DrawCell(&dc, OldSel);
    }

    // Set the current selection as row/col and draw (it will be drawn selected)
    m_nCurrentSel = nIndex;
    DrawCell(&dc, m_nCurrentSel);

    // Store the current color
    if (m_nCurrentSel == OT_COLOR_CUSTOMBOXVALUE)
	{
        m_wndParent->SendMessage(OT_COLOR_SELCHANGE, (WPARAM) m_crInitialColor, 0);
	}
    else if (m_nCurrentSel == OT_COLOR_DEFAULTBOXVALUE)
    {
        m_crColor = m_crDefault;
        m_wndParent->SendMessage(OT_COLOR_SELCHANGE, (WPARAM) m_crDefault, 0);
    }
    else
    {
        m_crColor = GetColor(m_nCurrentSel);
        m_wndParent->SendMessage(OT_COLOR_SELCHANGE, (WPARAM) m_crColor, 0);
    }
}
コード例 #19
0
/*----------------------------------------------------------------------------------------------
	Change to a new cell, redrawing both old and new to indicate the change.
----------------------------------------------------------------------------------------------*/
void IconComboPopup::ChangeSelection(int ival)
{
    Assert(0 <= ival && ival < m_cvals);
    if (ival == m_ivalHot)
        return;

    HDC hdc = ::GetDC(m_hwnd);

    // Draw the old selection (that we're about to change).
    if (m_ivalHot >= 0)
        DrawCell(hdc, m_ivalHot, false, m_prgfPressed[m_ivalHot]);

    // Set the current selection as row/col and draw as selected.
    m_ivalHot = ival;
    DrawCell(hdc, m_ivalHot, true, m_prgfPressed[m_ivalHot]);

    // Store the current Color
    *m_pival = m_ivalHot;
    ::SendMessage(m_hwndParent, WM_COMMAND, MAKEWPARAM(m_wid, CBN_SELCHANGE), (LPARAM)m_hwnd);
    int iSuccess;
    iSuccess = ::ReleaseDC(m_hwnd, hdc);
    Assert(iSuccess);
}
コード例 #20
0
/*----------------------------------------------------------------------------------------------
	Draw the popup table
----------------------------------------------------------------------------------------------*/
void IconComboPopup::OnPaint()
{
    PAINTSTRUCT ps;
    HDC hdc = ::BeginPaint(m_hwnd, &ps); // Get device context for painting.

    // Draw Color cells.
    for (int ival = 0; ival < m_cvals; ival++)
        DrawCell(hdc, ival, ival == m_ivalHot, m_prgfPressed[ival]);

    // Draw raised window edge (ex-window style WS_EX_WINDOWEDGE is supposed to do this,
    // but for some reason it doesn't.
    Rect rc;
    GetClientRect(rc);
    ::DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT);

    ::EndPaint(m_hwnd, &ps);
}
コード例 #21
0
ファイル: mainfrm.cpp プロジェクト: BorisMomtchev/ConwaysLife
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
	if (m_curGeneration!=0)
		return;

	if(ClickInsideGrid(point))
	{
		UINT gridCol=(point.x - HOROFFSET)/SQUARESIZE;
		UINT gridRow=(point.y - VEROFFSET)/SQUARESIZE;

		if(m_world[gridRow][gridCol]==DEAD)
		{
			m_world[gridRow][gridCol]=ALIVE;
			DrawCell(gridCol,gridRow,TRUE);
		}
	}
}
コード例 #22
0
void CIconSelector::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	CMemDC memDC(&dc);
	CRect rc, rcClip;
	int i, j;

	GetClientRect(rc);
	memDC.FillSolidRect(rc, ICONSEL_COLOR_BACK);
	
	for(i = 0; i < (int)m_nRowCount; i++)
	{
		for(j = 0; j < (int)m_nColCount; j++)
		{
			GetCellRect(i, j, rcClip);
			DrawCell((CDC *)&memDC, i, j, rcClip);
		}
	}

	DrawCellLine((CDC *)&memDC);
}
コード例 #23
0
ファイル: life.c プロジェクト: Connlaio/chromium
void ProcessTouchEvent(PSEvent* event) {
  uint32_t count = g_pTouchInput->GetTouchCount(event->as_resource,
      PP_TOUCHLIST_TYPE_TOUCHES);
  uint32_t i, j;
  for (i = 0; i < count; i++) {
    struct PP_TouchPoint touch = g_pTouchInput->GetTouchByIndex(
        event->as_resource, PP_TOUCHLIST_TYPE_TOUCHES, i);
    int radius = (int)touch.radius.x;
    int x = (int)touch.position.x;
    int y = (int)touch.position.y;
    /* num = 1/100th the area of touch point */
    int num = (int)(M_PI * radius * radius / 100.0f);
    for (j = 0; j < num; j++) {
      int dx = rand() % (radius * 2) - radius;
      int dy = rand() % (radius * 2) - radius;
      /* only plot random cells within the touch area */
      if (dx * dx + dy * dy <= radius * radius)
        DrawCell(x + dx, y + dy);
    }
  }
}
コード例 #24
0
ファイル: bmpalctrl.cpp プロジェクト: vata/xarino
void BitmapExportPaletteControl::RenderPalette(DocRect *pPaletteSize, RenderRegion *pRender, INT32 controlHeight,
											   DocRect* pClipRect)
{
	INT32 nColours = m_Palette.GetNumberOfColours();

	// See if the background needs rendering
	if (nColours < m_NumberOfColoursAtLastRedraw)
		RenderGrey(pPaletteSize, pRender);

	m_NumberOfColoursAtLastRedraw = nColours;

	pRender->SetLineColour(COLOUR_BLACK);

	DocRect cell;

	// Draw each cell in turn
	for (INT32 i = 0; i < nColours; ++i)
	{
		GetRectForCell(i, &cell, controlHeight);
		if (cell.IsIntersectedWith(*pClipRect))
		{
			BYTE r, g, b;
			r = m_Palette.GetRed(i);
			g = m_Palette.GetGreen(i);
			b = m_Palette.GetBlue(i);
			DrawCell(&cell, DocColour(r, g, b), m_Palette.GetFlags(i), pRender,
				IsColourWebSafe(r, g, b), i == m_SelectedCell);
		}
	}

	// Draw the mouse over high light
	if (m_MouseOverCell != INVALID_COLOUR_VALUE)
	{
		GetRectForCell(m_MouseOverCell, &cell, controlHeight);
		pRender->SetFillColour(COLOUR_TRANS);
		pRender->SetLineColour(COLOUR_WHITE);
		pRender->DrawRect(&cell);
	}

}
コード例 #25
0
ファイル: GameDrawer.cpp プロジェクト: ajorians/nBinaryPuzzle
void GameDrawer::Draw()
{
   boxRGBA(m_pSurface, m_pBoardMetrics->GetBoardLeft(), m_pBoardMetrics->GetBoardTop(), m_pBoardMetrics->GetBoardRight(), m_pBoardMetrics->GetBoardBottom(), GAME_BACKGROUND_R, GAME_BACKGROUND_G, GAME_BACKGROUND_B, 230);

   for(int nX=0; nX<=m_pBoardMetrics->GetWidth(); nX++) {
       vlineRGBA(m_pSurface, m_pBoardMetrics->GetLeftSpots() + nX*m_pBoardMetrics->GetPieceSize(), m_pBoardMetrics->GetTopSpots(), m_pBoardMetrics->GetBottomSpots(), 0, 0, 0, 255);
   }

   for(int nY=0; nY<=m_pBoardMetrics->GetHeight(); nY++) {
       hlineRGBA(m_pSurface, m_pBoardMetrics->GetLeftSpots(), m_pBoardMetrics->GetRightSpots(), m_pBoardMetrics->GetTopSpots() + nY*m_pBoardMetrics->GetPieceSize(), 0, 0, 0, 255);
   }

   for(int nX=0; nX<m_pBoardMetrics->GetWidth(); nX++)
      if( IsBinaryColDuplicate(m_Binary, nX) != BINARYLIB_ROW_UNIQUE ) {
         SDL_Rect rect;
         rect.w = m_pBoardMetrics->GetPieceSize();
         rect.h = m_pBoardMetrics->GetBottomSpots() - m_pBoardMetrics->GetTopSpots();
         rect.x = m_pBoardMetrics->GetXPos(nX);
         rect.y = m_pBoardMetrics->GetTopSpots();
         SDL_FillRect(m_pSurface, &rect, SDL_MapRGB(m_pSurface->format, 255, 255, 0));
      }

   for(int nY=0; nY<m_pBoardMetrics->GetHeight(); nY++)
      if( IsBinaryRowDuplicate(m_Binary, nY) != BINARYLIB_ROW_UNIQUE ) {
         SDL_Rect rect;
         rect.w = m_pBoardMetrics->GetRightSpots() - m_pBoardMetrics->GetLeftSpots();
         rect.h = m_pBoardMetrics->GetPieceSize();
         rect.x = m_pBoardMetrics->GetLeftSpots();
         rect.y = m_pBoardMetrics->GetYPos(nY);
         SDL_FillRect(m_pSurface, &rect, SDL_MapRGB(m_pSurface->format, 255, 255, 0));
      }

   for(int nX=0; nX<m_pBoardMetrics->GetWidth(); nX++) {
       for(int nY=0; nY<m_pBoardMetrics->GetHeight(); nY++) {
           DrawCell(nX, nY);
       }
   }
}
コード例 #26
0
void CCellView::ResizeCol(BPoint where, int colNr)
{
	float x, minX, maxRow;
	BPoint newP, lastP;
	BRect bounds(Bounds()), r, b;
	ulong buttons, cnt;
	bool multi;
	int mCol = colNr;
	CRunArray backup(fCellWidths);

	StPenState save(this);
	ClearAnts();

	cnt = fSelection.right - fSelection.left + 1;

	while (fCellWidths[colNr + 1] == fCellWidths[colNr])
		colNr++;

	multi = fSelection.left != fSelection.right
					&& colNr >= fSelection.left
					&& colNr <= fSelection.right;

	if (colNr <= fFrozen.h)
	{
		x = fBorderWidth + fCellWidths[colNr];
		minX = fBorderWidth + fCellWidths[multi?fSelection.left - 1 : colNr - 1];
	}
	else
	{
		x = fBorderWidth + fCellWidths[colNr] + fCellWidths[fFrozen.h] - 
			fCellWidths[fPosition.h - 1];
		minX = fBorderWidth + fCellWidths[fFrozen.h] - fCellWidths[fPosition.h - 1] + 
			fCellWidths[multi?fSelection.left - 1 : colNr - 1];
	}
	
	r.top = 1;
	r.bottom = fBorderHeight - 1;
	r.left = minX + 1;
	if (multi)
		r.right = minX + fCellWidths[fSelection.right] - 
			fCellWidths[fSelection.left - 1] - 1;
	else
		r.right = minX + fCellWidths[colNr] - fCellWidths[colNr - 1] - 1;
		
	b = bounds;
	b.left = r.right;
	
	maxRow = fPosition.v;
	while (fCellHeights[++maxRow] - fCellHeights[fPosition.v] < bounds.bottom - fBorderHeight)
		;
	
	lastP = where;
	newP = where;
	do
	{
		if (newP.x != lastP.x)
		{
			float dx;
			int k = colNr;
			
			dx = newP.x - lastP.x;
			
			if (lastP.x + dx < bounds.left + fBorderWidth)
				dx = std::min(lastP.x - bounds.left - fBorderWidth, (float)0);
			if (lastP.x + dx > bounds.right)
				dx = std::max(bounds.right - lastP.x, (float)0);
			
			if (multi && x + dx < minX)
				dx = minX - x;

			if (multi)
			{
				float w, t;
				
				w = x + dx - minX;
				if (w > 0)
					w = Round(w / (colNr - fSelection.left + 1));
				
				t = fCellWidths[fSelection.right];				
				fCellWidths.SetValue(fSelection.left, fSelection.right, w);
				dx = fCellWidths[fSelection.right] - t;
			}
			else if (x + dx < minX)
			{
				int t = k;
				
				fCellWidths.SetValue(colNr, 0);

				while (k > 1 && backup[k - 1] + fBorderWidth >= x + dx)
					k--;

				ASSERT(k<colNr);

				if (k <= mCol)
					while (mCol > k)
						fCellWidths.SetValue(mCol--, 0);
				else
				{
					t = mCol;
					for (;mCol<k;mCol++)
						fCellWidths.SetValue(mCol, backup[mCol] - backup[mCol - 1]);
				}

				float kw = x + dx - fBorderWidth;
				kw -= backup[k - 1];
				fCellWidths.SetValue(k, std::max(kw, (float)0));

				mCol = k;
				k = t;
			}
			else
			{
				k = mCol;
				for (; mCol < colNr; mCol++)
					fCellWidths.SetValue(mCol, backup[mCol] - backup[mCol - 1]);

				fCellWidths.SetValue(colNr, x + dx - minX);
			}
					
			if (dx != 0)
			{
				x += dx;
				lastP.x += dx;

				if (dx < 0)
					b.left += dx;
				
				StPenState save(this);
				StClipCells clip(this);
				ScrollRect(b, dx, 0);
				Window()->UpdateIfNeeded();
				
				if (dx > 0)
					b.left += dx;
				
				if (multi)
				{
					int h = fSelection.left, v;
					do
					{
						for (v = 1; v < fFrozen.v; v++)
							DrawCell(cell(h, v));
						for (v = fPosition.v; v < maxRow; v++)
							DrawCell(cell(h, v));
						DrawBorderCell(h++, true);
					}
					while (h <= fSelection.right && bounds.left + fCellWidths[h] + fBorderWidth < bounds.right);
				}
				else
				{
					int v;
					for (v = 1; v < fFrozen.v; v++)
						DrawCell(cell(mCol, v));
					for (v = fPosition.v; v < maxRow; v++)
						DrawCell(cell(mCol, v));
					DrawBorderCell(mCol, true);
				}
				
				for (; k < colNr; k++)
				{
					int v;
					for (v = 1; v < fFrozen.v; v++)
						DrawCell(cell(k, v));
					for (v = fPosition.v; v < maxRow; v++)
						DrawCell(cell(k, v));
					DrawBorderCell(k, true);
				}
			}
			
			if (dx < 0)
			{
				float X;
				int h;
				
				X = bounds.right + dx - fBorderWidth;
				h = fSelection.right;
				do h++;
				while (fCellWidths[h] < X);
				
				while (h <= kColCount && bounds.left + fCellWidths[h] + fBorderWidth < bounds.right)
				{
					int v;
					for (v = 1; v < fFrozen.v; v++)
						DrawCell(cell(h, v));
					for (v = fPosition.v; v < maxRow; v++)
						DrawCell(cell(h, v));
					DrawBorderCell(h++, true);
				}
			}
			
			if (dx && fFirstGraphic)
				fFirstGraphic->HandleUpdate(bounds);
		}
		GetMouse(&newP, &buttons);
	}
	while (buttons);

	if (!(backup == fCellWidths))
	{
		CRunArray temp(fCellWidths);
		fCellWidths = backup;
		
		((CCellWindow*)Window())->RegisterCommand(new CResizeCommand(this, temp, false));
		((CCellWindow*)Window())->SetDirty(true);
	}
} /* ResizeCol */
コード例 #27
0
ファイル: life.cpp プロジェクト: crankycoder/wxPython-2.9.2.4
void LifeCanvas::OnMouse(wxMouseEvent& event)
{
    if (!m_interactive)
        return;

    // which cell are we pointing at?
    wxInt32 i = XToCell( event.GetX() );
    wxInt32 j = YToCell( event.GetY() );

#if wxUSE_STATUSBAR
    // set statusbar text
    wxString msg;
    msg.Printf(_("Cell: (%d, %d)"), i, j);
    ((LifeFrame *) wxGetApp().GetTopWindow())->SetStatusText(msg, 1);
#endif // wxUSE_STATUSBAR

    // NOTE that wxMouseEvent::LeftDown() and wxMouseEvent::LeftIsDown()
    // have different semantics. The first one is used to signal that the
    // button was just pressed (i.e., in "button down" events); the second
    // one just describes the current status of the button, independently
    // of the mouse event type. LeftIsDown is typically used in "mouse
    // move" events, to test if the button is _still_ pressed.

    // is the button down?
    if (!event.LeftIsDown())
    {
        m_status = MOUSE_NOACTION;
        return;
    }

    // was it pressed just now?
    if (event.LeftDown())
    {
        // yes: start a new action and toggle this cell
        m_status = (m_life->IsAlive(i, j)? MOUSE_ERASING : MOUSE_DRAWING);

        m_mi = i;
        m_mj = j;
        m_life->SetCell(i, j, m_status == MOUSE_DRAWING);
        DrawCell(i, j, m_status == MOUSE_DRAWING);
    }
    else if ((m_mi != i) || (m_mj != j))
    {
        // no: continue ongoing action
        bool alive = (m_status == MOUSE_DRAWING);

        // prepare DC and pen + brush to optimize drawing
        wxClientDC dc(this);
        dc.SetPen(alive? *wxBLACK_PEN : *wxWHITE_PEN);
        dc.SetBrush(alive? *wxBLACK_BRUSH : *wxWHITE_BRUSH);

        // draw a line of cells using Bresenham's algorithm
        wxInt32 d, ii, jj, di, ai, si, dj, aj, sj;
        di = i - m_mi;
        ai = abs(di) << 1;
        si = (di < 0)? -1 : 1;
        dj = j - m_mj;
        aj = abs(dj) << 1;
        sj = (dj < 0)? -1 : 1;

        ii = m_mi;
        jj = m_mj;

        if (ai > aj)
        {
            // iterate over i
            d = aj - (ai >> 1);

            while (ii != i)
            {
                m_life->SetCell(ii, jj, alive);
                DrawCell(ii, jj, dc);
                if (d >= 0)
                {
                    jj += sj;
                    d  -= ai;
                }
                ii += si;
                d  += aj;
            }
        }
コード例 #28
0
ファイル: life.cpp プロジェクト: crankycoder/wxPython-2.9.2.4
// event handlers
void LifeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
{
    wxPaintDC dc(this);
    wxRect  rect = GetUpdateRegion().GetBox();
    wxCoord x, y, w, h;
    wxInt32 i0, j0, i1, j1;

    // find damaged area
    x = rect.GetX();
    y = rect.GetY();
    w = rect.GetWidth();
    h = rect.GetHeight();

    i0 = XToCell(x);
    j0 = YToCell(y);
    i1 = XToCell(x + w - 1);
    j1 = YToCell(y + h - 1);

    size_t ncells;
    LifeCell *cells;

    m_life->BeginFind(i0, j0, i1, j1, false);
    bool done = m_life->FindMore(&cells, &ncells);

    // erase all damaged cells and draw the grid
    dc.SetBrush(*wxWHITE_BRUSH);

    if (m_cellsize <= 2)
    {
       // no grid
       dc.SetPen(*wxWHITE_PEN);
       dc.DrawRectangle(x, y, w, h);
    }
    else
    {
        x = CellToX(i0);
        y = CellToY(j0);
        w = CellToX(i1 + 1) - x + 1;
        h = CellToY(j1 + 1) - y + 1;

        dc.SetPen(*wxLIGHT_GREY_PEN);
        for (wxInt32 yy = y; yy <= (y + h - m_cellsize); yy += m_cellsize)
            dc.DrawRectangle(x, yy, w, m_cellsize + 1);
        for (wxInt32 xx = x; xx <= (x + w - m_cellsize); xx += m_cellsize)
            dc.DrawLine(xx, y, xx, y + h);
    }

    // draw all alive cells
    dc.SetPen(*wxBLACK_PEN);
    dc.SetBrush(*wxBLACK_BRUSH);

    while (!done)
    {
        for (size_t m = 0; m < ncells; m++)
            DrawCell(cells[m].i, cells[m].j, dc);

        done = m_life->FindMore(&cells, &ncells);
    }

    // last set
    for (size_t m = 0; m < ncells; m++)
        DrawCell(cells[m].i, cells[m].j, dc);
}
コード例 #29
0
ファイル: render.cpp プロジェクト: boo1ean/CAD_Coursework
cad_picture *RenderMap(cad_render_module *self, cad_route_map * map, bool forceDrawLayer, uint32_t forceDrawLayerNunber)
{
 	if (map == NULL) 
	{
		return draw_Nothing( self );
	}

	int w = map->width;
	int h = map->height;

	int width, height;
	uint32_t value;
	int addw, addh;
	int cell_size;
	int image_width, image_height;

	cell_size = (int) max( ceil((double) WANT_WIDTH / w), ceil((double) WANT_HEIGHT / h) );

	if (cell_size % 2 == 0) cell_size += 1;

	if (cell_size < MIN_CELL_SIZE) cell_size = MIN_CELL_SIZE;
	
	image_width = w * cell_size + w - 1;
	image_height = h * cell_size + h - 1;

	SetPitcureSize( self, image_width, image_height );

	auto picture = allocate_picture( self ); 

	memset( picture->data, 220, image_width * image_height * sizeof( uint32_t ) );
	
//=================================================================================
	// HORIZONTAL LINES
//=================================================================================
	for (int y=cell_size; y < image_height; ) // horizontal lines
		{
			for (int i=0;  i < image_width; i++)
				picture->data[image_width * y + i] = 0xeeeeee; 
			y += (cell_size + 1);
		}
//=================================================================================
	// VERTICAL LINES
//=================================================================================
	for (int z=cell_size; z < image_width;) //vertical lines
		{
			for (int i=0; i < image_height; i++)
				picture->data[image_width * i + z] = 0xeeeeee; 
			z += (cell_size + 1);
		}
	//int n = MapElement3D(map, 0,0,map->currerntLayer);	
		
	for (int r1 =0 ; r1<h; r1 ++ )
		for (int r2=0; r2<w; r2++)
		{	
			value = MapElement3D(map, r1, r2, map->currerntLayer);
			DrawCell(picture, r1, r2, value, w);
		}

	return picture;

}
コード例 #30
0
void DlgPalette::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
    for (int i = 0; i<m_numcolors; i++) DrawCell(&dc, i);
}