Esempio n. 1
2
void draw_planet(HDC hDC, planetstruct *planet)
{
	HBRUSH hbrColor, hbrOld;
	gravstruct *gp = &gravs;
	double D;						// a DX variable to work with
	unsigned char cmpt;

	D = POS(X) * POS(X) + POS(Y) * POS(Y) + POS(Z) * POS(Z);
	if (D < COLLIDE)
		D = COLLIDE;
	D = sqrt(D);
	D = D * D * D;
	for (cmpt = X; cmpt < DIMENSIONS; cmpt++) {
		ACC(cmpt) = POS(cmpt) * GRAV / D;
		if (iDamping) {
			if (ACC(cmpt) > MaxA)
				ACC(cmpt) = MaxA;
			else if (ACC(cmpt) < -MaxA)
				ACC(cmpt) = -MaxA;
			VEL(cmpt) = VEL(cmpt) + ACC(cmpt);
			VEL(cmpt) *= DAMP;
		} else {
			// update velocity
			VEL(cmpt) = VEL(cmpt) + ACC(cmpt);
		}
		// update position
		POS(cmpt) = POS(cmpt) + VEL(cmpt);
	}

	gp->x = planet->xi;
	gp->y = planet->yi;

	if (POS(Z) > -ALMOST) {
		planet->xi = (unsigned int)
			((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST)));
		planet->yi = (unsigned int)
			((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST)));
	}
	else
		planet->xi = planet->yi = -1;	

	// Mask
	hbrOld = (HBRUSH)SelectObject(hDC, (HBRUSH)GetStockObject(BLACK_BRUSH));
	Planet(gp->x, gp->y);

	if (iTrails)
		SetPixel(hDC, gp->x, gp->y, PALETTEINDEX(100));

	// Move
	gp->x = planet->xi;
	gp->y = planet->yi;
	planet->ri = RADIUS;

	if (iColorCycle) {
		if (planet->colors++ > (PALSIZE-21))
			planet->colors = 1;
	}

	// Redraw
	hbrColor = CreateSolidBrush(PALETTEINDEX(planet->colors));
	SelectObject(hDC, hbrColor);
	Planet(gp->x, gp->y);

	SelectObject(hDC, hbrOld);
	DeleteObject(hbrColor);
}
Esempio n. 2
0
void ShowSubdiv(HWND hw)
{
	HDC	dc = GetDC	(hw);

	u32 CB = RGB(255,0,0);
	for (int z=0; z<dimZ; z++)
	{
		for (int x=0; x<dimX; x++)
		{
			Texel&	T	= texels[z*dimX+x];
			if (T.N)	{
				pixel	(dc,x,z,RGB(127,127,127));
				vertex&	N = *T.N;

				int		_x=x*3,_y=z*3;
				if		(isBorder(N,0))	{		// left
					SetPixel(dc,_x,_y+0,CB);
					SetPixel(dc,_x,_y+1,CB);
					SetPixel(dc,_x,_y+2,CB);
				}
				if		(isBorder(N,1))	{		// fwd
					SetPixel(dc,_x+0,_y,CB);
					SetPixel(dc,_x+1,_y,CB);
					SetPixel(dc,_x+2,_y,CB);
				}
				if		(isBorder(N,2))	{		// right
					SetPixel(dc,_x+2,_y+0,CB);
					SetPixel(dc,_x+2,_y+1,CB);
					SetPixel(dc,_x+2,_y+2,CB);
				}
				if		(isBorder(N,3))	{		// back
					SetPixel(dc,_x+0,_y+2,CB);
					SetPixel(dc,_x+1,_y+2,CB);
					SetPixel(dc,_x+2,_y+2,CB);
				}
			} else {
				pixel	(dc,x,z,RGB(0,127,0));
			}
		}
	}

	ReleaseDC		(hw, dc);
}
Esempio n. 3
0
void main(int argc, char *argv[])
{
	double      r, g, b;
	uint        rows, cols;
	char        fname[256];
	double      colormag;
	time_t      tstart, tend;
    int         nrgbr = 63, nrgbg = 63, nrgbb = 63;
	OctreeType  *octree;
	RGBType		color;
	FILE		*f;
	char		title[40];
	char		description[128];
    ulong       i;
    uint        j;
	int			n;
	RGBType		palette[256];
	ulong		image_start;
	union REGS	regs;
	int			resx, resy;
	int			px, py;
	int			ii;
	int			cols2, rows2;
	int			k;
	int			cli;
    int         maxr=0, maxg=0, maxb=0;

#if defined METAWINDO
	rect        screen;
#endif

	printf("Image file : ");
	scanf("%s",fname);
	if ((f = fopen(fname,"rb")) == NULL) {
        printf("%s not found.\n",fname);
		exit(1);
	}

    /*
    ** Read the image file header
    */
	fgets(title,40,f);
	fgets(description,128,f);
	fscanf(f,"%d %d",&cols,&rows);
    fscanf(f,"%lf",&colormag);
	image_start = ftell(f);

	cols2 = cols/2;
	rows2 = rows/2;
	time(&tstart);

	/*
    ** Initialize the color octree
	*/
    octree = CreateOctNode(0);

	/*
    ** Loop through the image and store each unique color.
	*/
	for (i = 0L; i < (ulong)rows*(ulong)cols; i++) {
		/*
		** Show progress...
		*/
		if ((i % (ulong)cols) == 0L) printf("%ld\r",i/cols);

        fscanf(f,"%lf %lf %lf",&r,&g,&b);
		/*
		** Convert input floating point values to bytes.  NOTE: We assume that
		** all input values are between 0..1.0
		*/
        color.r = (unsigned char)(r  * nrgbr);
        color.g = (unsigned char)(g  * nrgbg);
        color.b = (unsigned char)(b  * nrgbb);
		if (color.r > nrgbr) color.r = nrgbr;
		if (color.g > nrgbg) color.g = nrgbg;
		if (color.b > nrgbb) color.b = nrgbb;

		/*
		** Insert this color into the octree
		*/
		InsertTree(&octree, &color, 0);

		/*
		** If there are too many colors in the tree as a result of this
		** insert, reduce the octree
		*/
		while (TotalLeafNodes() > npal) {
			ReduceTree();
		}
	}

	/*
	** Make a pass through the completed octree to average down the
	** rgb components.  When done, 'n' contains the actual number of
	** colors in the palette table.
	*/
	n = 0;
	MakePaletteTable(octree, palette, &n);

	/*
	** How long did it take?
	*/
	time(&tend);
	printf("Processed %ld pixels per second\ninto %d quantized colors\n",
		   ((long)rows*(long)cols)/(tend-tstart), n);

	j = 0;
	while (j != 3) {
		printf("Output to (1)monitor or (2).PCX file or (3) quit: ");
		scanf("%s",title);
		j = atoi(title);
		if (j == 2) {
			fseek(f,image_start,0);
            SaveAsPCX(f, octree, cols, rows, nrgbr, nrgbg, nrgbb, npal, palette);
		}
		else if (j == 1) {
#if defined METAWINDO
			/*
			** NOTE: This section requires MetaWINDOW graphics lib
			**
			** Let the user choose his graphics device and resolution
			*/
			MetQuery(argc,argv);
			if (InitGraphics(GrafixCard) != 0) {
				printf("\n---Error initializing graphics device---\n");
				exit(1);
			}
			SetDisplay(GrafPg0);
			BackColor(0);
			/*
			** Set the VGA palette
			*/
			for (j = 0; j < n; j++) {
				regs.h.al = 0x10;
				regs.h.ah = 0x10;
				regs.h.bl = j;
				regs.h.bh = 0;
				regs.h.ch = (int)(palette[j].g);
				regs.h.cl = (int)(palette[j].b);
				regs.h.dh = (int)(palette[j].r);
				int86(0x10,&regs,&regs);
			}

			/*
			** Center the image on the screen
			*/
			ScreenRect(&screen);
			resx = screen.Xmax;
			resy = screen.Ymax;
			px = resx/2 - npal;

			/*
			** Display a color bar at the top of the screen
			*/
			for (ii = 0; ii < npal; ii++){
				PenColor(ii);
				SetPixel(ii*2+px,1);
				SetPixel(ii*2+px+1,1);
				SetPixel(ii*2+px,2);
				SetPixel(ii*2+px+1,2);
				SetPixel(ii*2+px,3);
				SetPixel(ii*2+px+1,3);
				SetPixel(ii*2+px,4);
				SetPixel(ii*2+px+1,4);
			}

			fseek(f,image_start,0);

			py = resy/2 - rows2 - 1;
			for (ii = 0; ii < rows ; ii++) {
				px = resx/2 - cols2;
				for (k = 0; k < cols; k++) {
					if (fscanf(f,"%f %f %f",&r,&g,&b) == EOF) {
						goto pdone;
					}
					color.r = (byte)(nrgbr * r);
					color.g = (byte)(nrgbg * g);
					color.b = (byte)(nrgbb * b);
					cli = QuantizeColor(octree, &color);
					PenColor(cli);
					SetPixel(px,py);
					px++;
				}
				py++;
			}
pdone:      getch();
			SetDisplay(TextPg0);
			StopGraphics();
#endif
		}
	}
}
Esempio n. 4
0
void RgbEffects::RenderText(int Position1, const wxString& Line1, const wxString& FontString1,int dir1,int TextRotation1,bool COUNTDOWN1,
                            int Position2, const wxString& Line2, const wxString& FontString2,int dir2,int TextRotation2,bool COUNTDOWN2)
{
    wxColour c;
    wxString vertMsg;
    wxBitmap bitmap(BufferWi,BufferHt);
    wxMemoryDC dc(bitmap);

    wxFont font;
    int ColorIdx,itmp,i;
    long L1,longsecs1,longsecs2,seconds;
    bool COUNTDOWN=true;
    int days,hours,minutes;
    bool DAYS_STRING=true;


    size_t colorcnt=GetColorCount();
    srand(1); // always have the same random numbers for each frame (state)
    wxImage::HSVValue hsv; //   we will define an hsv color model. The RGB colot model would have been "wxColour color;"
    ColorIdx=rand() % colorcnt; // Select random numbers from 0 up to number of colors the user has checked. 0-5 if 6 boxes checked
    palette.GetHSV(ColorIdx, hsv); // Now go and get the hsv value for this ColorIdx

    font.SetNativeFontInfoUserDesc(FontString1);
    dc.SetFont(font);


    palette.GetColor(0,c);
    dc.SetTextForeground(c);
    wxString msg;
    wxSize sz1 = dc.GetTextExtent(Line1);
    int maxwidth=sz1.GetWidth();
    int maxht=sz1.GetHeight();

    L1=0;
    if(state==0 and COUNTDOWN1 and Line1.ToLong(&L1))
    {
        timer_countdown1=L1+1; // set their counter one higher since teh first thing we do it subtract one from it.
    }
    if(state==0 and COUNTDOWN2 and Line2.ToLong(&L1))
    {
        timer_countdown2=L1+1; // we can have concurrent timers, one for each line of text
    }



    if(dir1==4)
    {
        maxht = maxht*Line1.length();
        for(i=0; i<Line1.length(); i++)
        {
            msg = msg + Line1.GetChar(i) + "\n";
        }
    }
    else if(dir1==5)
    {
        maxht = maxht*Line1.length();
        for(i=0; i<Line1.length(); i++)
        {
            msg = msg + Line1.GetChar(Line1.length()-i-1) + "\n";
        }
    }
    else
    {
        msg = Line1;
        if(COUNTDOWN1)
        {
            longsecs1=wxGetUTCTime	()	;
            if(longsecs1 != old_longsecs1)  timer_countdown1--;
            old_longsecs1=longsecs1;
            if(timer_countdown1 < 0) timer_countdown1=0;
            msg=wxString::Format(wxT("%i"),timer_countdown1);

        }
        if(TextRotation1==1)
        {
            itmp=maxwidth;
            maxwidth=maxht;
            maxht=itmp;
        }
    }


    int dctop= Position1 * BufferHt / 50 - BufferHt/2;
    int xlimit=(BufferWi+maxwidth)*8 + 1;
    int ylimit=(BufferHt+maxht)*8 + 1;
//  int xcentered=(BufferWi-maxwidth)/2;  // original way
    int xcentered=Position1 * BufferWi / 50 - BufferWi/2;


    TextRotation1 *=90.0;
    switch (dir1)
    {
    case 0:
        // left
        //dc.DrawText(msg,BufferWi-state % xlimit/8,dctop);

        dc.DrawRotatedText(msg,BufferWi-state % xlimit/8,dctop,TextRotation1);
        break;
    case 1:
        // right
        //dc.DrawText(msg,state % xlimit/8-BufferWi,dctop);
        dc.DrawRotatedText(msg,state % xlimit/8-BufferWi,dctop,TextRotation1);
        break;
    case 2:
        // up
        //  dc.DrawText(msg,xcentered,BufferHt-state % ylimit/8);
        dc.DrawRotatedText(msg,xcentered,BufferHt-state % ylimit/8,TextRotation1);
        break;
    case 3:
        // down
        //  dc.DrawText(msg,xcentered,state % ylimit / 8 - BufferHt);
        dc.DrawRotatedText(msg,xcentered,state % ylimit / 8 - BufferHt,TextRotation1);
        break;
    case 4:
        // vertical text up
        dc.DrawText(msg,xcentered,BufferHt-(state % ylimit/8));
        break;
    case 5:
        // vertical text down
        dc.DrawText(msg,xcentered,(state % ylimit/8) - maxht);
        break;
    default:
        // no movement - centered
        //   dc.DrawText(msg,xcentered,dctop);
        dc.DrawRotatedText(msg,xcentered,dctop,TextRotation1);
        break;
    }


    // Line2
    msg="";
    font.SetNativeFontInfoUserDesc(FontString2);
    dc.SetFont(font);
    if(colorcnt>1) palette.GetColor(1,c); // scm 7-18-13. added if,. only pull color if we have at least two colors checked in palette
    dc.SetTextForeground(c);
    wxSize sz2 = dc.GetTextExtent(Line2);
    maxwidth=sz2.GetWidth();
    maxht=sz2.GetHeight();

    if(dir2==4)
    {
        maxht = maxht*Line2.length();
        for(i=0; i<Line2.length(); i++)
        {
            msg = msg + Line2.GetChar(i) + "\n";
        }
    }
    else if(dir2==5)
    {
        maxht = maxht*Line2.length();
        for(i=0; i<Line2.length(); i++)
        {
            msg = msg + Line2.GetChar(Line2.length()-i-1) + "\n";
        }
    }
    else
    {
        msg = Line2;
        if(COUNTDOWN2)
        {
            longsecs2=wxGetUTCTime	()	;
            if(longsecs2 != old_longsecs2)  timer_countdown2--;
            old_longsecs2=longsecs2;
            if(timer_countdown2 < 0) timer_countdown2=0;
            if(DAYS_STRING)
            {
                days = timer_countdown2 / 60 / 60 / 24;
                hours = (timer_countdown2 / 60 / 60) % 24;
                minutes = (timer_countdown2 / 60) % 60;
                seconds = timer_countdown2 % 60;
                msg=wxString::Format(wxT("%i d %i h %i m %i s"),days,hours,minutes,seconds);
            }
            else
                {
                    msg=wxString::Format(wxT("%i"),timer_countdown2);
                }
        }
        if(TextRotation2==1)
        {
            itmp=maxwidth;
            maxwidth=maxht;
            maxht=itmp;
        }
    }


    dctop= Position2 * BufferHt / 50 - BufferHt/2;
    xlimit=(BufferWi+maxwidth)*8 + 1;
    ylimit=(BufferHt+maxht)*8 + 1;
//  int xcentered=(BufferWi-maxwidth)/2;  // original way
    xcentered=Position2 * BufferWi / 50 - BufferWi/2;


    TextRotation2 *=90.0;
    switch (dir2)
    {
    case 0:
        // left
        //dc.DrawText(msg,BufferWi-state % xlimit/8,dctop);

        dc.DrawRotatedText(msg,BufferWi-state % xlimit/8,dctop,TextRotation2);
        break;
    case 1:
        // right
        //dc.DrawText(msg,state % xlimit/8-BufferWi,dctop);
        dc.DrawRotatedText(msg,state % xlimit/8-BufferWi,dctop,TextRotation2);
        break;
    case 2:
        // up
        //  dc.DrawText(msg,xcentered,BufferHt-state % ylimit/8);
        dc.DrawRotatedText(msg,xcentered,BufferHt-state % ylimit/8,TextRotation2);
        break;
    case 3:
        // down
        //  dc.DrawText(msg,xcentered,state % ylimit / 8 - BufferHt);
        dc.DrawRotatedText(msg,xcentered,state % ylimit / 8 - BufferHt,TextRotation2);
        break;
    case 4:
        // vertical text up
        dc.DrawText(msg,xcentered,BufferHt-(state % ylimit/8));
        break;
    case 5:
        // vertical text down
        dc.DrawText(msg,xcentered,(state % ylimit/8) - maxht);
        break;
    default:
        // no movement - centered
        //   dc.DrawText(msg,xcentered,dctop);
        dc.DrawRotatedText(msg,xcentered,dctop,TextRotation2);
        break;
    }


    // copy dc to buffer
    for(wxCoord x=0; x<BufferWi; x++)
    {
        for(wxCoord y=0; y<BufferHt; y++)
        {
            dc.GetPixel(x,BufferHt-y-1,&c);
            SetPixel(x,y,c);

//        ColorIdx=(n % BlockHt) / BarHt;
//        palette.GetHSV(ColorIdx, hsv);

        }
    }
}
Esempio n. 5
0
/* Load image data from file in PFM format */
STStatus
STHDRImage::LoadPFM(const char* filename) {
  FILE* fin = fopen(filename, "rb");
  char buffer[128];

  if (fin == NULL) {
    printf("Error opening file: %s\n", filename);
    return ST_ERROR;
  }

  // Check the format
  char format;
  fgets(buffer, 80, fin);
  if ( sscanf(buffer, "P%c", &format) != 1 || (format != 'f' && format != 'F') ) {
    printf("Invalid PFM file\n");
    fclose(fin);
    return ST_ERROR;
  }
  // Get the dimensions
  int w, h;
  fgets(buffer, 80, fin);
  if ( sscanf(buffer, "%i %i", &w, &h) != 2 || w <= 0 || h <= 0 ) {
    printf("Invalid PFM file\n");
    fclose(fin);
    return ST_ERROR;
  }
  // Get the scale factor, we just discard this
  // FIXME endianness
  float scale;
  fgets(buffer, 80, fin);
  if ( sscanf(buffer, "%f", &scale) != 1 ) {
    printf("Invalid PFM file\n");
    fclose(fin);
    return ST_ERROR;
  }

  mWidth = w;
  mHeight = h;
  mPixels = new STHDRImage::Pixel[w*h];

  // Now we can read the data
  if (format == 'f') { // grayscale
    float gval;
    for(int j = 0; j < h; j++) {
      for(int i = 0; i < w; i++) {
        if ( fread(&gval, sizeof(float), 1, fin) != 1 ) {
          printf("Invalid PFM file\n");
          fclose(fin);
          return ST_ERROR;
        }
        SetPixel(i,j, STHDRImage::Pixel(gval, gval, gval));
      }
    }
  }
  else { // if (format == 'F') color
    if ( fread(mPixels, sizeof(STHDRImage::Pixel), w*h, fin) != w*h ) {
      printf("Invalid PFM file\n");
      fclose(fin);
      return ST_ERROR;
    }
  }

  fclose(fin);

  return ST_OK;
}
Esempio n. 6
0
void
endPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
    switch (activeTool)
    {
        case TOOL_FREESEL:
        {
            POINT *ptStackCopy;
            int i;
            rectSel_src[0] = rectSel_src[1] = 0x7fffffff;
            rectSel_src[2] = rectSel_src[3] = 0;
            for (i = 0; i <= ptSP; i++)
            {
                if (ptStack[i].x < rectSel_src[0])
                    rectSel_src[0] = ptStack[i].x;
                if (ptStack[i].y < rectSel_src[1])
                    rectSel_src[1] = ptStack[i].y;
                if (ptStack[i].x > rectSel_src[2])
                    rectSel_src[2] = ptStack[i].x;
                if (ptStack[i].y > rectSel_src[3])
                    rectSel_src[3] = ptStack[i].y;
            }
            rectSel_src[2] += 1 - rectSel_src[0];
            rectSel_src[3] += 1 - rectSel_src[1];
            rectSel_dest[0] = rectSel_src[0];
            rectSel_dest[1] = rectSel_src[1];
            rectSel_dest[2] = rectSel_src[2];
            rectSel_dest[3] = rectSel_src[3];
            if (ptSP != 0)
            {
                DeleteObject(hSelMask);
                hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL);
                DeleteObject(SelectObject(hSelDC, hSelMask));
                ptStackCopy = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * (ptSP + 1));
                for (i = 0; i <= ptSP; i++)
                {
                    ptStackCopy[i].x = ptStack[i].x - rectSel_src[0];
                    ptStackCopy[i].y = ptStack[i].y - rectSel_src[1];
                }
                Poly(hSelDC, ptStackCopy, ptSP + 1, 0x00ffffff, 0x00ffffff, 1, 2, TRUE);
                HeapFree(GetProcessHeap(), 0, ptStackCopy);
                SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3]));
                resetToU1();
                MaskBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0],
                        rectSel_src[1], hSelMask, 0, 0, MAKEROP4(SRCCOPY, WHITENESS));
                Poly(hdc, ptStack, ptSP + 1, bg, bg, 1, 2, TRUE);
                newReversible();

                MaskBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0,
                        0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));

                placeSelWin();
                ShowWindow(hSelection, SW_SHOW);
                /* force refresh of selection contents */
                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
            }
            HeapFree(GetProcessHeap(), 0, ptStack);
            ptStack = NULL;
            break;
        }
        case TOOL_RECTSEL:
            resetToU1();
            if ((rectSel_src[2] != 0) && (rectSel_src[3] != 0))
            {
                DeleteObject(hSelMask);
                hSelMask = CreateBitmap(rectSel_src[2], rectSel_src[3], 1, 1, NULL);
                DeleteObject(SelectObject(hSelDC, hSelMask));
                Rect(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], 0x00ffffff, 0x00ffffff, 1, 2);
                SelectObject(hSelDC, hSelBm = CreateDIBWithProperties(rectSel_src[2], rectSel_src[3]));
                resetToU1();
                BitBlt(hSelDC, 0, 0, rectSel_src[2], rectSel_src[3], hDrawingDC, rectSel_src[0],
                       rectSel_src[1], SRCCOPY);
                Rect(hdc, rectSel_src[0], rectSel_src[1], rectSel_src[0] + rectSel_src[2],
                     rectSel_src[1] + rectSel_src[3], bgColor, bgColor, 0, TRUE);
                newReversible();

                BitBlt(hDrawingDC, rectSel_src[0], rectSel_src[1], rectSel_src[2], rectSel_src[3], hSelDC, 0,
                       0, SRCCOPY);

                placeSelWin();
                ShowWindow(hSelection, SW_SHOW);
                /* force refresh of selection contents */
                SendMessage(hSelection, WM_LBUTTONDOWN, 0, 0);
                SendMessage(hSelection, WM_MOUSEMOVE, 0, 0);
                SendMessage(hSelection, WM_LBUTTONUP, 0, 0);
            }
            break;
        case TOOL_RUBBER:
            Erase(hdc, last.x, last.y, x, y, bg, rubberRadius);
            break;
        case TOOL_PEN:
            Line(hdc, last.x, last.y, x, y, fg, 1);
            SetPixel(hdc, x, y, fg);
            break;
        case TOOL_LINE:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                roundTo8Directions(start.x, start.y, &x, &y);
            Line(hdc, start.x, start.y, x, y, fg, lineWidth);
            break;
        case TOOL_BEZIER:
            pointSP++;
            if (pointSP == 4)
                pointSP = 0;
            break;
        case TOOL_RECT:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            Rect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle);
            break;
        case TOOL_SHAPE:
            resetToU1();
            pointStack[pointSP].x = x;
            pointStack[pointSP].y = y;
            if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0))
                roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y,
                                   &pointStack[pointSP].x, &pointStack[pointSP].y);
            pointSP++;
            if (pointSP >= 2)
            {
                if ((pointStack[0].x - x) * (pointStack[0].x - x) +
                    (pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
                {
                    Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, TRUE);
                    pointSP = 0;
                }
                else
                {
                    Poly(hdc, pointStack, pointSP, fg, bg, lineWidth, shapeStyle, FALSE);
                }
            }
            if (pointSP == 255)
                pointSP--;
            break;
        case TOOL_ELLIPSE:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            Ellp(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle);
            break;
        case TOOL_RRECT:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            RRect(hdc, start.x, start.y, x, y, fg, bg, lineWidth, shapeStyle);
            break;
    }
}
Esempio n. 7
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)	/*운영체제가 호출하는 CALL BACK 함수*/
{
	HDC hdc;
	PAINTSTRUCT ps;
	
	HANDLE hFile;
	DWORD dwRead;
	
	static TCHAR c_image[1024 * 1024];
	static char str[125] = {0, };
	
	static BITMAPFILEHEADER *bfp;	
	static BITMAPINFOHEADER *bip;
	
	static char *image_p;
	
	int i_cnt_x = 10;
	int i_cnt_y = 10;
		
    switch(iMessage)
    {
		case WM_CREATE:
			hWndMain = hWnd;
					
			/*비트맵 파일을 불러온다.*/
			hFile = CreateFile(TEXT("1.bmp"), GENERIC_READ, 0, NULL,
						OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
			if(hFile == INVALID_HANDLE_VALUE)	/*실패하면 프로그램 종료*/
			{
				SendMessage(hWnd, WM_DESTROY, 0, 0);
				
				return 0;
			}
			else
			{
				/*메모리에 이미지를 적재한다.*/
				ReadFile(hFile, c_image, 1024 * 1024, &dwRead, NULL);	
				CloseHandle(hFile);
				
				bfp = (BITMAPFILEHEADER *)c_image;
				bip = (BITMAPINFOHEADER *)(c_image + sizeof(BITMAPFILEHEADER));
				
				wsprintf(str, TEXT("%d"), bfp -> bfSize);	/*파일 크기 정보*/
			}
			InvalidateRect(hWnd, NULL, TRUE);
							
			return 0;

		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			
			//TextOut(hdc, 10, 10, str, lstrlen(str)); 	/*파일의 총 크기를 출력*/
									
			/*for(i_cnt_x = 10; 40 >= i_cnt_x; ++i_cnt_x)
			{
				SetPixel(hdc, i_cnt_x, i_cnt_y, RGB(255, 0, 0));
			}*/
			
			image_p = c_image + (bfp -> bfOffBits);	/*image_p 는 image의 처음을 가리키게 된다.*/
							
			/*화면에 사진을 출력*/
			for(i_cnt_y = 0; (bip -> biHeight) > i_cnt_y; ++i_cnt_y)
			{	
				for(i_cnt_x = 0; (bip -> biWidth) > i_cnt_x; ++i_cnt_x)
				{							
					/*사진을 픽셀 단위로 출력*/
					SetPixel(hdc, i_cnt_x, (bip -> biHeight) - i_cnt_y, RGB(*(image_p + 2), *(image_p + 1), *(image_p + 0)));	/*이미지의 한 줄만 출력해 본다. BGR 순으로 나온다.*/
					
					image_p = image_p + 3;	/*3바이트가 한 픽셀의 정보이기 때문에 이동 시켜준다.*/
				}
				
				/*4의 보수 픽셀 보정*/
				image_p = image_p + (bip -> biWidth % 4);																	
			}		
			
			EndPaint(hWnd, &ps);
			return 0;
	
		case WM_LBUTTONDOWN:
						
			return 0; 
		
		case WM_KEYDOWN:		/*키 입력이 들어왔을 때 여기로 들어 온다.*/
			
			return 0;

		case WM_COMMAND:
			
			return 0;
			
		case WM_DESTROY:
			PostQuitMessage(0);	/*종료 메세지인 WM_DESTROY를 만든다.*/
			return 0;
	}
    return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
Esempio n. 8
0
void RgbEffects::draw_chase(int x,int y,wxImage::HSVValue hsv,int ColorScheme,int Number_Chases,
                            int width,bool R_TO_L1,int Chase_Width,bool Chase_Fade3d1,
                            int ChaseDirection)
{
    float  orig_v,new_v;
    int new_x,i,max_chase_width,pixels_per_chase;
    wxColour color;
    size_t colorcnt=GetColorCount();
    int ColorIdx;

    orig_v=hsv.value;
    SetPixel(x,y,hsv); // Turn pixel on

    max_chase_width = width * Chase_Width/100.0;
    pixels_per_chase = width/Number_Chases;

    int pulsar=0;
    int n;
    float val;
    int mid = 0.5 + (max_chase_width/2.0);
    int pixels_per_color=max_chase_width/colorcnt;
    if(pixels_per_color<1) pixels_per_color=1;
    /*


    RRRRGGGG........+........................
    .RRRRGGGG.......+........................
    ..RRRRGGGG......+........................
    ...RRRRGGGG.....+........................
    ....RRRRGGGG....+........................
    .....RRRRGGGG...+........................
    ......RRRRGGGG..+........................
    .......RRRRGGGG.+........................
    ........RRRRGGGG+..............<===========   this is what fist version would end at
    .........RRRRGGG+........................
     .........RRRRGG+........................
      .........RRRRG+........................
       .........RRRR+........................
        .........RRR+........................



    */
    if(max_chase_width>=1)
    {
        for (i=0; i<=max_chase_width; i++)
        {
            if(pulsar==1)
            {
                n=state%10;
                switch (n)
                {
                case 0:
                case 4:
                    pulse(x,y,hsv,0.30);
                    break;
                case 1:
                case 3:
                    pulse(x,y,hsv,0.50);
                    pulse(x-1,y,hsv,0.30);
                    pulse(x+1,y,hsv,0.30);

                    break;
                case 2:
                    pulse(x,y,hsv,1.0);
                    pulse(x-1,y,hsv,0.50);
                    pulse(x+1,y,hsv,0.50);
                    pulse(x-2,y,hsv,0.30);
                    pulse(x+2,y,hsv,0.30);
                    break;
                }
            }
            else // not pulsar
            {
                if(ColorScheme==0)
                {
                    if(max_chase_width) hsv.hue = 1.0 - (i*1.0/max_chase_width); // rainbow hue
                }
                //  if(R_TO_L1)
                if(ChaseDirection==1) // are we going R-L?
                    new_x = x-i;    //  yes
                else
                    new_x = x+i;
                if(new_x<0)
                {
                    y++;
                    ChaseDirection=1;   // we were going R to L, now switch to L-R
                    new_x+=width;
                }
                else if(new_x>width)
                {
                    y++;
                    ChaseDirection=0;   // we were going L-R, now switch to R-L
                    new_x-=width;
                }
                //new_x=new_x%BufferWi;
                if(i<=pixels_per_chase) // as long as the chase fits, keep drawing it
                {
                    if(ColorScheme==0)
                        SetPixel(new_x,y,hsv); // Turn pixel on
                    else
                    {
                        if(colorcnt==1)
                            ColorIdx=0;
                        else
                        {
                            ColorIdx=i/pixels_per_color;
                        }
                        if(ColorIdx>=colorcnt) ColorIdx=colorcnt-1;
                        palette.GetHSV(ColorIdx, hsv);
                        if(Chase_Fade3d1) hsv.value=orig_v - (i*1.0/max_chase_width); // fades data down over chase width
                        if(hsv.value<0.0) hsv.value=0.0;
                        SetPixel(new_x,y,hsv); // Turn pixel on
                    }
                }
            }
        }
    }
}
Esempio n. 9
0
//----------------------------------------------------------------------------
void ConvexHull2D::OnDisplay ()
{
    ClearScreen();

    ColorRGB black(0,0,0), gray(128,128,128), blue(0,0,255);

    int dimension = mHull->GetDimension();
    int numSimplices = mHull->GetNumSimplices();
    const int* indices = mHull->GetIndices();

    int i0, i1, x0, y0, x1, y1;
    Vector2f v0, v1;

    if (dimension == 0)
    {
        // draw point
        v0 = mVertices[0];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());
        SetPixel(x0, y0, gray);
    }
    else if (dimension == 1)
    {
        // draw line segment
        v0 = mVertices[indices[0]];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());

        v1 = mVertices[indices[1]];
        x1 = UnitToScreen(v1.X());
        y1 = UnitToScreen(v1.Y());

        DrawLine(x0, y0, x1, y1, gray);
    }
    else
    {
        // draw convex polygon
        for (i0 = numSimplices - 1, i1 = 0; i1 < numSimplices; i0 = i1++)
        {
            v0 = mVertices[indices[i0]];
            x0 = UnitToScreen(v0.X());
            y0 = UnitToScreen(v0.Y());

            v1 = mVertices[indices[i1]];
            x1 = UnitToScreen(v1.X());
            y1 = UnitToScreen(v1.Y());

            DrawLine(x0, y0, x1, y1, gray);
        }
    }

    // draw input points
    for (i0 = 0; i0 < mNumVertices; ++i0)
    {
        v0 = mVertices[i0];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());
        SetThickPixel(x0, y0, 1, blue);
    }

    // draw hull vertices
    if (indices)
    {
        for (i0 = 0; i0 < numSimplices; ++i0)
        {
            v0 = mVertices[indices[i0]];
            x0 = UnitToScreen(v0.X());
            y0 = UnitToScreen(v0.Y());
            SetThickPixel(x0, y0, 1, black);
        }
    }
    else
    {
        v0 = mVertices[0];
        x0 = UnitToScreen(v0.X());
        y0 = UnitToScreen(v0.Y());
        SetThickPixel(x0, y0, 1, black);
    }

    WindowApplication2::OnDisplay();
}
Esempio n. 10
0
void setPixel(int x, int y, COLORREF color, HWND sHwnd) {
	HDC hdc = GetDC(sHwnd);
	SetPixel(hdc, x, y, color);
	ReleaseDC(sHwnd, hdc);
	return;
}
Esempio n. 11
0
void DrawPixel(int x, int y)
{
	SetPixel(hdc, x, y, xor ? GetPixel(hdc, x, y) ^ Mask : win_draw_color);
}
Esempio n. 12
0
void RgbEffects::RenderSnowflakes(int Count, int SnowflakeType)
{
    int i,n,x,y0,y,check,delta_y;
    wxColour color1,color2;
    if (state == 0 || Count != LastSnowflakeCount || SnowflakeType != LastSnowflakeType)
    {
        // initialize
        LastSnowflakeCount=Count;
        LastSnowflakeType=SnowflakeType;
        palette.GetColor(0,color1);
        palette.GetColor(1,color2);
        ClearTempBuf();
        // place Count snowflakes
        for (n=0; n < Count; n++)
        {
            delta_y=BufferHt/4;
            y0=(n % 4)*delta_y;
            if (y0+delta_y > BufferHt) delta_y = BufferHt-y0;
            // find unused space
            for (check=0; check < 20; check++)
            {
                x=rand() % BufferWi;
                y=y0 + (rand() % delta_y);
                if (GetTempPixelRGB(x,y) == 0) break;
            }
            // draw flake, SnowflakeType=0 is random type
            switch (SnowflakeType == 0 ? rand() % 5 : SnowflakeType-1)
            {
            case 0:
                // single node
                SetTempPixel(x,y,color1);
                break;
            case 1:
                // 5 nodes
                if (x < 1) x+=1;
                if (y < 1) y+=1;
                if (x > BufferWi-2) x-=1;
                if (y > BufferHt-2) y-=1;
                SetTempPixel(x,y,color1);
                SetTempPixel(x-1,y,color2);
                SetTempPixel(x+1,y,color2);
                SetTempPixel(x,y-1,color2);
                SetTempPixel(x,y+1,color2);
                break;
            case 2:
                // 3 nodes
                if (x < 1) x+=1;
                if (y < 1) y+=1;
                if (x > BufferWi-2) x-=1;
                if (y > BufferHt-2) y-=1;
                SetTempPixel(x,y,color1);
                if (rand() % 100 > 50)      // % 2 was not so random
                {
                    SetTempPixel(x-1,y,color2);
                    SetTempPixel(x+1,y,color2);
                }
                else
                {
                    SetTempPixel(x,y-1,color2);
                    SetTempPixel(x,y+1,color2);
                }
                break;
            case 3:
                // 9 nodes
                if (x < 2) x+=2;
                if (y < 2) y+=2;
                if (x > BufferWi-3) x-=2;
                if (y > BufferHt-3) y-=2;
                SetTempPixel(x,y,color1);
                for (i=1; i<=2; i++)
                {
                    SetTempPixel(x-i,y,color2);
                    SetTempPixel(x+i,y,color2);
                    SetTempPixel(x,y-i,color2);
                    SetTempPixel(x,y+i,color2);
                }
                break;
            case 4:
                // 13 nodes
                if (x < 2) x+=2;
                if (y < 2) y+=2;
                if (x > BufferWi-3) x-=2;
                if (y > BufferHt-3) y-=2;
                SetTempPixel(x,y,color1);
                SetTempPixel(x-1,y,color2);
                SetTempPixel(x+1,y,color2);
                SetTempPixel(x,y-1,color2);
                SetTempPixel(x,y+1,color2);

                SetTempPixel(x-1,y+2,color2);
                SetTempPixel(x+1,y+2,color2);
                SetTempPixel(x-1,y-2,color2);
                SetTempPixel(x+1,y-2,color2);
                SetTempPixel(x+2,y-1,color2);
                SetTempPixel(x+2,y+1,color2);
                SetTempPixel(x-2,y-1,color2);
                SetTempPixel(x-2,y+1,color2);
                break;
            case 5:
                // 45 nodes (not enabled)
                break;
            }
        }
    }

    // move snowflakes
    int new_x,new_y,new_x2,new_y2;
    for (x=0; x<BufferWi; x++)
    {
        new_x = (x+state/20) % BufferWi; // CW
        new_x2 = (x-state/20) % BufferWi; // CCW
        if (new_x2 < 0) new_x2+=BufferWi;
        for (y=0; y<BufferHt; y++)
        {
            new_y = (y+state/10) % BufferHt;
            new_y2 = (new_y + BufferHt/2) % BufferHt;
            GetTempPixel(new_x,new_y,color1);
            if (color1.GetRGB() == 0) GetTempPixel(new_x2,new_y2,color1);
            SetPixel(x,y,color1);
        }
    }
}
Esempio n. 13
0
// use tempbuf for calculations
void RgbEffects::RenderLife(int Count, int Type)
{
    int i,x,y,cnt;
    bool isLive;
    wxColour color;
    Count=BufferWi * BufferHt * Count / 200 + 1;
    if (state == 0 || Count != LastLifeCount || Type != LastLifeType)
    {
        // seed tempbuf
        LastLifeCount=Count;
        LastLifeType=Type;
        ClearTempBuf();
        for(i=0; i<Count; i++)
        {
            x=rand() % BufferWi;
            y=rand() % BufferHt;
            GetMultiColorBlend(rand01(),false,color);
            SetTempPixel(x,y,color);
        }
    }
    long TempState=state % 400 / 20;
    if (TempState == LastLifeState)
    {
        pixels=tempbuf;
        return;
    }
    else
    {
        LastLifeState=TempState;
    }
    for (x=0; x < BufferWi; x++)
    {
        for (y=0; y < BufferHt; y++)
        {
            GetTempPixel(x,y,color);
            isLive=(color.GetRGB() != 0);
            cnt=Life_CountNeighbors(x,y);
            switch (Type)
            {
            case 0:
                // B3/S23
                /*
                Any live cell with fewer than two live neighbours dies, as if caused by under-population.
                Any live cell with two or three live neighbours lives on to the next generation.
                Any live cell with more than three live neighbours dies, as if by overcrowding.
                Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
                */
                if (isLive && cnt >= 2 && cnt <= 3)
                {
                    SetPixel(x,y,color);
                }
                else if (!isLive && cnt == 3)
                {
                    GetMultiColorBlend(rand01(),false,color);
                    SetPixel(x,y,color);
                }
                break;
            case 1:
                // B35/S236
                if (isLive && (cnt == 2 || cnt == 3 || cnt == 6))
                {
                    SetPixel(x,y,color);
                }
                else if (!isLive && (cnt == 3 || cnt == 5))
                {
                    GetMultiColorBlend(rand01(),false,color);
                    SetPixel(x,y,color);
                }
                break;
            case 2:
                // B357/S1358
                if (isLive && (cnt == 1 || cnt == 3 || cnt == 5 || cnt == 8))
                {
                    SetPixel(x,y,color);
                }
                else if (!isLive && (cnt == 3 || cnt == 5 || cnt == 7))
                {
                    GetMultiColorBlend(rand01(),false,color);
                    SetPixel(x,y,color);
                }
                break;
            case 3:
                // B378/S235678
                if (isLive && (cnt == 2 || cnt == 3 || cnt >= 5))
                {
                    SetPixel(x,y,color);
                }
                else if (!isLive && (cnt == 3 || cnt == 7 || cnt == 8))
                {
                    GetMultiColorBlend(rand01(),false,color);
                    SetPixel(x,y,color);
                }
                break;
            case 4:
                // B25678/S5678
                if (isLive && (cnt >= 5))
                {
                    SetPixel(x,y,color);
                }
                else if (!isLive && (cnt == 2 || cnt >= 5))
                {
                    GetMultiColorBlend(rand01(),false,color);
                    SetPixel(x,y,color);
                }
                break;
            }
        }
    }
    // copy new life state to tempbuf
    tempbuf=pixels;
}
Esempio n. 14
0
void RgbEffects::RenderGarlands(int GarlandType, int Spacing)
{
    int x,y,yadj,ylimit,ring;
    double ratio;
    wxColour color;
    int PixelSpacing=Spacing*BufferHt/100+3;
    int limit=BufferHt*PixelSpacing*4;
    int GarlandsState=(limit - (state % limit))/4;
    // ring=0 is the top ring
    for (ring=0; ring<BufferHt; ring++)
    {
        ratio=double(ring)/double(BufferHt);
        GetMultiColorBlend(ratio, false, color);
        y=GarlandsState - ring*PixelSpacing;
        ylimit=BufferHt-ring-1;
        for (x=0; x<BufferWi; x++)
        {
            yadj=y;
            switch (GarlandType)
            {
            case 1:
                switch (x%5)
                {
                case 2:
                    yadj-=2;
                    break;
                case 1:
                case 3:
                    yadj-=1;
                    break;
                }
                break;
            case 2:
                switch (x%5)
                {
                case 2:
                    yadj-=4;
                    break;
                case 1:
                case 3:
                    yadj-=2;
                    break;
                }
                break;
            case 3:
                switch (x%6)
                {
                case 3:
                    yadj-=6;
                    break;
                case 2:
                case 4:
                    yadj-=4;
                    break;
                case 1:
                case 5:
                    yadj-=2;
                    break;
                }
                break;
            case 4:
                switch (x%5)
                {
                case 1:
                case 3:
                    yadj-=2;
                    break;
                }
                break;
            }
            if (yadj < ylimit) yadj=ylimit;
            if (yadj < BufferHt) SetPixel(x,yadj,color);
        }
    }
}
Esempio n. 15
0
LRESULT CALLBACK TranslateMessages( HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam )
{
  static POINT pts[4]=
  {
    {-5, -10}, {0, 5}, {5, -10}, {0, -190}
  }, pt;  
  INT x, y, Xc, Yc, i, j, M=500, N=500 / 2, R=100;
  DOUBLE theta, phi, z;
  HDC hDC;
  CREATESTRUCT *cs;
  PAINTSTRUCT ps;
  static INT WinW, WinH;
  static HDC hMemDCFrame, hMemDC;
  static HBITMAP hBmFrame, hBmBack, hBmAnd, hBmXor;
  RECT pRect;
  switch (Msg)
  {
  case WM_CREATE:
    cs = (CREATESTRUCT *)lParam;
    SetTimer(hWnd, 30, 10, NULL);  
    hDC = GetDC(hWnd);
    hMemDCFrame = CreateCompatibleDC(hDC);
    hMemDC = CreateCompatibleDC(hDC);
    ReleaseDC(hWnd, hDC);
    if (!LoadGlobe())
    {
      MessageBox(NULL, "Error loading globe texture", 0, MB_OK);
      exit(1);
    }
    return 0;
  case WM_SIZE:
    WinW = LOWORD(lParam);
    WinH = HIWORD(lParam);
    if (hBmFrame != NULL)
      DeleteObject(hBmFrame);    
    hDC = GetDC(hWnd);
    hBmFrame = CreateCompatibleBitmap(hDC, WinW, WinH);
    ReleaseDC(hWnd, hDC);    
    SelectObject(hMemDCFrame, hBmFrame);
    SendMessage(hWnd, WM_TIMER, 0, 0);
    return 0;    
  case WM_TIMER:  
    GetCursorPos(&pt);
    ScreenToClient(hWnd, &pt);

    GetWindowRect(hWnd, &pRect);
    Xc = (pRect.right - pRect.left) / 2;
    Yc = (pRect.bottom - pRect.top) / 2;

    SelectObject(hMemDCFrame, GetStockObject(DC_BRUSH));  
    SelectObject(hMemDCFrame, GetStockObject(NULL_PEN));
    SetDCBrushColor(hMemDCFrame, RGB(0, 0, 0));
    Rectangle(hMemDCFrame, 0, 0, WinW, WinH);

    for (i=0; i<=N; i++)
      for (j=0; j<=M; j++)
      {
        INT x1 = 0, y1 = 0;

        theta = (i * M_PI / N +  PhaseShift);
        phi = (j * 2 * M_PI / M + PhaseShift);
        R = (WinW > WinH ? WinH : WinW) / 2;
        x = (int)(sin(theta) * sin(phi) * R) + WinW / 2 ;
        y = -(int)(cos(theta) * R) + WinH / 2 ;
        z = sin(theta) * cos(phi) ;
        if (z > 0)
        {
          x1 = j * w / (M + 1);
          y1 = i * h / (N + 1);
          SetPixel(hMemDCFrame, x, y, RGB(mem[(y1 * w + x1) * 3 + 2], mem[(y1 * w + x1) * 3 + 1], mem[(y1 * w + x1) * 3]));                        
        }        
      } 
    PhaseShift  += 0.005f; 
    InvalidateRect(hWnd, NULL, FALSE);
    return 0;
  case WM_ERASEBKGND:
    return 0;
  case WM_PAINT: 
    hDC = BeginPaint(hWnd, &ps);
    BitBlt(hDC, 0, 0, WinW, WinH, hMemDCFrame, 0, 0, SRCCOPY);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_DESTROY:
    if (hBmFrame != NULL)
      DeleteObject(hBmFrame);
    if (hMemDCFrame != NULL)
      DeleteDC(hMemDCFrame);
    PostQuitMessage(30);
    KillTimer(hWnd, 30);
    return 0;
  } 
  return DefWindowProc(hWnd, Msg, wParam, lParam);
}
Esempio n. 16
0
void Xiq::Draw(Matrix const &/*matrix*/)
{
	float x0 = location.x;
	float y0 = location.y;

	Time t = GetRoot()->TimeNow();
	float r = colors[0](t);
	float g = colors[1](t);
	float b = colors[2](t);
	Color color = GetRoot()->MakeColor(r,g,b);

	int ra = radius;
	if (ra < 0)
		ra *= -1;

	int f = 1 - ra;
	int ddF_x = 1;
	int ddF_y = -2 * ra;
	int x = 0;
	int y = ra;

	SetPixel(x0, y0 + ra, color);
	SetPixel(x0, y0 - ra, color);
	SetPixel(x0 + ra, y0, color);
	SetPixel(x0 - ra, y0, color);

	while (x < y)
	{
		if (f >= 0)
		{
			y--;
			ddF_y += 2;
			f += ddF_y;
		}
		x++;
		ddF_x += 2;
		f += ddF_x;
		SetPixel(x0 + x, y0 + y, color);
		SetPixel(x0 - x, y0 + y, color);
		SetPixel(x0 + x, y0 - y, color);
		SetPixel(x0 - x, y0 - y, color);
		SetPixel(x0 + y, y0 + x, color);
		SetPixel(x0 - y, y0 + x, color);
		SetPixel(x0 + y, y0 - x, color);
		SetPixel(x0 - y, y0 - x, color);
	}
}
//
//  関数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的:  メイン ウィンドウのメッセージを処理します。
//
//  WM_COMMAND	- アプリケーション メニューの処理
//  WM_PAINT	- メイン ウィンドウの描画
//  WM_DESTROY	- 中止メッセージを表示して戻る
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 選択されたメニューの解析:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: 描画コードをここに追加してください...
				int x, y;

		// 画像の表示
		for (y = 0; y < IMG_HEIGHT; y++) {
			for (x = 0; x < IMG_WIDTH; x++) {
				SetPixel(hdc, x, y, RGB(r[y][x], g[y][x], b[y][x]));
			}
		}

#if 0
		// 課題1
		// 左右を反転して表示
		/*
		for (y = 0; y < IMG_HEIGHT; y++) {
			for (x = 0; x < IMG_WIDTH; x++) {
				SetPixel(hdc, IMG_WIDTH - x, y, RGB(r[y][x], g[y][x], b[y][x]));
			}
		}
		*/

		// 課題2
		// 画像を明るくする
		for (y = 0; y < IMG_HEIGHT; y++) {
			for (x = 0; x < IMG_WIDTH; x++) {
				if (r[y][x] * KADAI2_VAL > UCHAR_MAX
					|| g[y][x] * KADAI2_VAL > UCHAR_MAX
					|| b[y][x] * KADAI2_VAL > UCHAR_MAX) {
					SetPixel(hdc, x, y, RGB(255, 255, 255));
				} else {
					SetPixel(hdc, x, y, RGB(r[y][x], g[y][x], b[y][x]));
				}
			}
		}

		// 倍率を自動的に見つける
		{
			int max = 0; // 最大値
			double m;    // 倍率

			// RGBの最大値を求める
			for (y = 0; y < IMG_HEIGHT; y++) {
				for (x = 0; x < IMG_WIDTH; x++) {
					if (max < r[y][x]) max = r[y][x];
					if (max < g[y][x]) max = g[y][x];
					if (max < b[y][x]) max = b[y][x];
				}
			}
			// 倍率を求める
			m = (double)UCHAR_MAX / max;

			// 倍率だけRGBをそれぞれ値を増やして表示
			for (y = 0; y < IMG_HEIGHT; y++) {
				for (x = 0; x < IMG_WIDTH; x++) {
					SetPixel(hdc, x, y, RGB(
						(unsigned char)(r[y][x] * m),
						(unsigned char)(g[y][x] * m),
						(unsigned char)(b[y][x] * m)));
				}
			}
		}
#endif
		// 課題3
		// ブレンド
		for (y = 0; y < IMG_HEIGHT; y++) {
			for (x = 0; x < IMG_WIDTH; x++) {
				// RGBそれぞれの平均を表示
				SetPixel(hdc, x, y, RGB(
					(r[y][x] + r2[y][x]) / 2,
					(g[y][x] + g2[y][x]) / 2,
					(b[y][x] + b2[y][x]) / 2));
			}
		}

		// 課題4
		// モーフィングの基礎
		{
			double n; // ブレンドする割合

			// 1枚目の画像をブレンドする割合を増やしながら画像を表示
			// (1枚目の割合がnなら2枚目は(1-n))
			for (n = 0.0; n <= KADAI4_N_MAX; n += KADAI4_N_IVAL) {
				for (y = 0; y < IMG_HEIGHT; y++) {
					for (x = 0; x < IMG_WIDTH; x++) {
						SetPixel(hdc, x, y, RGB(
							r[y][x] * n + r2[y][x] * (KADAI4_N_MAX - n),
							g[y][x] * n + g2[y][x] * (KADAI4_N_MAX - n),
							b[y][x] * n + b2[y][x] * (KADAI4_N_MAX - n)));
					}
				}
			}
		}

		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Esempio n. 18
0
void OnMouseMove(HWND hWnd, int x, int y, UINT keyFlags)
{
    HDC hdc = GetDC(hWnd); 
    SetPixel(hdc, x, y, RGB(255,0,0)); 
    ReleaseDC(hWnd, hdc);
}
Esempio n. 19
0
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
  
	PAINTSTRUCT ps;
	HANDLE context;
	static DWORD color = 0;
	struct Node *iterator;
  
	switch( msg ) {
							/**************************************************************/
							/*    WM_CREATE:        (received on window creation)
							/**************************************************************/
		case WM_CREATE:       
			hDC = GetDC(hWnd);  
			break;   
							/**************************************************************/
							/*    WM_TIMER:         (received when our timer expires)
							/**************************************************************/
		case WM_TIMER:
			
							/* NOTE: replace code below for periodic update of the window */
							/*       e.g. draw a planet system)                           */
							/* NOTE: this is referred to as the 'graphics' thread in the lab spec. */
			EnterCriticalSection(&dbAccess);
			iterator = head;
			while (iterator != NULL)
			{
				SetPixel(hDC, iterator->data.sx, iterator->data.sy, (COLORREF)color);

				color += 12;

				iterator = iterator->next;
			}
			LeaveCriticalSection(&dbAccess);
			windowRefreshTimer (hWnd, UPDATE_FREQ);
			break;
							/****************************************************************\
							*     WM_PAINT: (received when the window needs to be repainted, *
							*               e.g. when maximizing the window)                 *
							\****************************************************************/

		case WM_PAINT:
							/* NOTE: The code for this message can be removed. It's just */
							/*       for showing something in the window.                */
			context = BeginPaint( hWnd, &ps ); /* (you can safely remove the following line of code) */
			//TextOut( context, 10, 10, "Hello, World!", 13 ); /* 13 is the string length */
			EndPaint( hWnd, &ps );
			break;
							/**************************************************************\
							*     WM_DESTROY: PostQuitMessage() is called                  *
							*     (received when the user presses the "quit" button in the *
							*      window)                                                 *
							\**************************************************************/
		case WM_DESTROY:
			PostQuitMessage( 0 );
							/* NOTE: Windows will automatically release most resources this */
     						/*       process is using, e.g. memory and mailslots.           */
     						/*       (So even though we don't free the memory which has been*/     
     						/*       allocated by us, there will not be memory leaks.)      */

			ReleaseDC(hWnd, hDC); /* Some housekeeping */
			break;

							/**************************************************************\
							*     Let the default window proc handle all other messages    *
							\**************************************************************/
		default:
			return( DefWindowProc( hWnd, msg, wParam, lParam )); 
   }
   return 0;
}
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    WCHAR text[80];
    HDC hdc;
    POINTS pt;
    PAINTSTRUCT ps;
    static HDC hdcOffScr;
    static HBITMAP hbmOffScr;
    static HWND hStc;

    switch(uMsg)
    {
    case WM_CREATE:
        hStc = CreateWindow(L"STATIC", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 5, 5, 70, 20, hWnd, NULL, NULL, NULL);
        CreateWindow(L"BUTTON", L"Red", WS_CHILD | WS_VISIBLE, 85, 5, 60, 20, hWnd, (HMENU) ID_RED, NULL, NULL);
        CreateWindow(L"BUTTON", L"Green", WS_CHILD | WS_VISIBLE, 150, 5, 60, 20, hWnd, (HMENU) ID_GREEN, NULL, NULL);
        CreateWindow(L"BUTTON", L"Blue", WS_CHILD | WS_VISIBLE, 215, 5, 60, 20, hWnd, (HMENU) ID_BLUE, NULL, NULL);
        CreateWindow(L"BUTTON", L"Clear", WS_CHILD | WS_VISIBLE, 285, 5, 60, 20, hWnd, (HMENU) ID_CLEAR, NULL, NULL);
        hdc = GetDC(hWnd);
        hdcOffScr = CreateCompatibleDC(hdc);
        hbmOffScr = CreateCompatibleBitmap(hdc, 400, 400);
        SelectObject(hdcOffScr, hbmOffScr);
        ReleaseDC(hWnd, hdc);
        PatBlt(hdcOffScr, 0, 0, 400, 400, PATCOPY);
        break;

    case WM_COMMAND:
        switch(wParam)
        {
        case ID_RED:
            g_clrPoint = RGB(255, 0, 0);
            break;

        case ID_GREEN:
            g_clrPoint = RGB(0, 255, 0);
            break;

        case ID_BLUE:
            g_clrPoint = RGB(0, 0, 255);
            break;

        case ID_CLEAR:
            PatBlt(hdcOffScr, 0, 0, 400, 400, PATCOPY);
            InvalidateRect(hWnd, NULL, TRUE);
            break;
        }
        break;

    case WM_MOUSEMOVE:
        pt = MAKEPOINTS(lParam);
        wsprintf(text, L"(%d, %d)", pt.x, pt.y);
        SetWindowText(hStc, text);
        if(lParam & MK_LBUTTON)
        {
            hdc = GetDC(hWnd);
            SetPixel(hdc, pt.x, pt.y, g_clrPoint);
            SetPixel(hdc, 400 - pt.x, pt.y, g_clrPoint);
            SetPixel(hdcOffScr, pt.x, pt.y, g_clrPoint);
            SetPixel(hdcOffScr, 400 - pt.x, pt.y, g_clrPoint);
            ReleaseDC(hWnd, hdc);
        }
        break;

    case WM_PAINT:
        BeginPaint(hWnd, &ps);
        BitBlt(ps.hdc, 0, 0, 400, 400, hdcOffScr, 0, 0, SRCCOPY);
        EndPaint(hWnd, &ps);
        break;

    case WM_CLOSE:
        DeleteDC(hdcOffScr);
        DeleteObject(hbmOffScr);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }

    return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Esempio n. 21
0
//----------------------------------------------------------------------------
void NURBSCurveExample::OnDisplay ()
{
    ClearScreen();

    ColorRGB curveColor(0,0,0);
    ColorRGB controlColor(128, 128, 128);

    int imax = 2048;
    int i, x, y;
    float t;
    Vector2f position;

    // Draw the spline.
    for (i = 0; i <= imax; ++i)
    {
        t = i/(float)imax;
        position = mSpline->GetPosition(t);
        x = (int)(position.X() + 0.5f);
        y = mSize - 1 - (int)(position.Y() + 0.5f);
        SetPixel(x, y, curveColor);
    }

    // Draw the circle.
    if (mCircle)
    {
        for (i = 0; i <= imax; ++i)
        {
            t = i/(float)imax;
            position = mCircle->GetPosition(t);
            x = (int)(position.X() + 0.5f);
            y = mSize - 1 - (int)(position.Y() + 0.5f);
            SetPixel(x, y, curveColor);
        }
    }

    // Draw the control points.
    if (mDrawControlPoints)
    {
        // Draw the spline control points.
        imax = mSpline->GetNumCtrlPoints();
        for (i = 0; i < imax; ++i)
        {
            const Vector2f& ctrl = mSpline->GetControlPoint(i);
            x = (int)(ctrl.X() + 0.5f);
            y = mSize - 1 -(int)(ctrl.Y() + 0.5f);
            SetThickPixel(x, y, 2, controlColor);
        }

        // Draw the circle control points.
        if (mCircle)
        {
            imax = mCircle->GetNumCtrlPoints();
            for (i = 0; i < imax; ++i)
            {
                const Vector2f& ctrl = mCircle->GetControlPoint(i);
                x = (int)(ctrl.X() + 0.5f);
                y = mSize - 1 - (int)(ctrl.Y() + 0.5f);
                SetThickPixel(x, y, 2, controlColor);
            }
        }
    }

    WindowApplication2::OnDisplay();
}
Esempio n. 22
0
void DrawPixels(HWND hwnd) {

	PAINTSTRUCT ps;
	RECT r;

	GetClientRect(hwnd, &r);

	if (r.bottom == 0)
	  return;

	HDC hdc = BeginPaint(hwnd, &ps);

	// pixels
	for (int i = 0; i < 1000; i++) {
	  int x = rand() % r.right;
	  int y = rand() % r.bottom;
	  SetPixel(hdc, x, y, RGB(rand() % 255, rand() % 255, rand() % 255));
	}
	
	// rectangle
	Rectangle(hdc, 30, 30, 240, 140);
	
	// pens and lines (stroke)
	HPEN hPen1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
	HPEN hPen2 = CreatePen(PS_DASH, 1, RGB(0, 0, 0));
	HPEN hPen3 = CreatePen(PS_DOT, 1, RGB(0, 0, 0));
	HPEN hPen4 = CreatePen(PS_DASHDOT, 1, RGB(0, 0, 0));
	HPEN hPen5 = CreatePen(PS_DASHDOTDOT, 1, RGB(0, 0, 0));

	HPEN holdPen = SelectObject(hdc, hPen1);
	MoveToEx(hdc, 50, 30, NULL);
	LineTo(hdc, 200, 30);

	SelectObject(hdc, hPen2);
	MoveToEx(hdc, 50, 50, NULL);
	LineTo(hdc, 200, 50);

	SelectObject(hdc, hPen2);
	MoveToEx(hdc, 50, 70, NULL);
	LineTo(hdc, 200, 70);

	SelectObject(hdc, hPen3);
	MoveToEx(hdc, 50, 90, NULL);
	LineTo(hdc, 200, 90);

	SelectObject(hdc, hPen4);
	MoveToEx(hdc, 50, 110, NULL);
	LineTo(hdc, 200, 110);

	SelectObject(hdc, holdPen);
	DeleteObject(hPen1);
	DeleteObject(hPen2);
	DeleteObject(hPen3);
	DeleteObject(hPen4);
	DeleteObject(hPen5);
	
	// brushes and fill
	HPEN hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
	holdPen = SelectObject(hdc, hPen);

	HBRUSH hBrush1 = CreateSolidBrush(RGB(121, 90, 0));
	HBRUSH hBrush2 = CreateSolidBrush(RGB(240, 63, 19));
	HBRUSH hBrush3 = CreateSolidBrush(RGB(240, 210, 18));
	HBRUSH hBrush4 = CreateSolidBrush(RGB(9, 189, 21));

	HBRUSH holdBrush = SelectObject(hdc, hBrush1);

	int top = 200;
	int size = 70;
	Rectangle(hdc, 30, top, 100, top+size);
	SelectObject(hdc, hBrush2);
	Rectangle(hdc, 110, top, 180, top+size);
	SelectObject(hdc, hBrush3);
	Rectangle(hdc, 30, top+70, 100, top+size+70);
	SelectObject(hdc, hBrush4);
	Rectangle(hdc, 110, top+70, 180, top+size+70);

	SelectObject(hdc, holdPen);
	SelectObject(hdc, holdBrush);

	DeleteObject(hPen);
	DeleteObject(hBrush1);
	DeleteObject(hBrush2);
	DeleteObject(hBrush3);
	DeleteObject(hBrush4);
	
	// draw shapes
	int left = 370;
	Ellipse(hdc, left, 30, left + 60, 90);
	RoundRect(hdc, left+80, 30, left+160, 90, 15, 20);
	Chord(hdc, 270, 30, 360, 90, 270, 45, 360, 45);
	const POINT polygon[10] = { left+30, 145, left+85, 165, left+105, 
      110, left+65, 125, left+30, 105 };
	const POINT bezier[4] = {280, 160, 320, 160, 
      325, 110, 350, 110};
	Polygon(hdc, polygon, 5);
	PolyBezier(hdc, bezier, 4);
	
	// draw text
	DWORD color;
	HFONT hFont, holdFont;
	static wchar_t *ver1 = L"Not marble, nor the gilded monuments";
	static wchar_t *ver2 = L"Of princes, shall outlive this powerful rhyme;";
	static wchar_t *ver3 = L"But you shall shine more bright in these contents";
	static wchar_t *ver4 = L"Than unswept stone, besmear'd with sluttish time.";
	static wchar_t *ver5 = L"When wasteful war shall statues overturn,";
	static wchar_t *ver6 = L"And broils root out the work of masonry,";
	static wchar_t *ver7 = L"Nor Mars his sword, nor war's quick fire shall burn";
	static wchar_t *ver8 = L"The living record of your memory.";
	static wchar_t *ver9 = L"'Gainst death, and all oblivious enmity";
	static wchar_t *ver10 = L"Shall you pace forth; your praise shall still find room";
	static wchar_t *ver11 = L"Even in the eyes of all posterity";
	static wchar_t *ver12 = L"That wear this world out to the ending doom.";
	static wchar_t *ver13 = L"So, till the judgment that yourself arise,";
	static wchar_t *ver14 = L"You live in this, and dwell in lovers' eyes.";

	color = GetSysColor(COLOR_BTNFACE);
	SetBkColor(hdc, color);

	hFont = CreateFontW(15, 0, 0, 0, FW_MEDIUM, 0, 0, 0, 0,
	  0, 0, 0, 0, L"Georgia");
	holdFont = SelectObject(hdc, hFont);

	left = 270;
	top = 160;
	TextOutW(hdc, left, top + 20,  ver1,  lstrlenW(ver1));
	TextOutW(hdc, left, top + 40,  ver2,  lstrlenW(ver2));
	TextOutW(hdc, left, top + 60,  ver3,  lstrlenW(ver3));
	TextOutW(hdc, left, top + 80,  ver4,  lstrlenW(ver4));
	TextOutW(hdc, left, top + 100, ver5,  lstrlenW(ver5));
	TextOutW(hdc, left, top + 120, ver6,  lstrlenW(ver6));
	TextOutW(hdc, left, top + 140, ver7,  lstrlenW(ver7));
	TextOutW(hdc, left, top + 160, ver8,  lstrlenW(ver8));
	TextOutW(hdc, left, top + 180, ver9,  lstrlenW(ver9));
	TextOutW(hdc, left, top + 200, ver10, lstrlenW(ver10));
	TextOutW(hdc, left, top + 220, ver11, lstrlenW(ver11));
	TextOutW(hdc, left, top + 240, ver12, lstrlenW(ver12));
	TextOutW(hdc, left, top + 260, ver13, lstrlenW(ver13));
	TextOutW(hdc, left, top + 280, ver14, lstrlenW(ver14));

	SelectObject(hdc, holdFont);
	DeleteObject(hFont);
	
	// draw bitmap
	BITMAP bitmap;
	HDC hdcMem;
	HGDIOBJ oldBitmap;
	
	hdcMem = CreateCompatibleDC(hdc);
	oldBitmap = SelectObject(hdcMem, hBitmap);

	GetObject(hBitmap, sizeof(bitmap), &bitmap);
	BitBlt(hdc, 550, 5, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);

	SelectObject(hdcMem, oldBitmap);
	DeleteDC(hdcMem);


	EndPaint(hwnd, &ps);
}
Esempio n. 23
0
// 10 <= HeightPct <= 100
void RgbEffects::RenderFire(int HeightPct)
{
    int x,y,i,r,v1,v2,v3,v4,n,new_index;
    if (state == 0)
    {
        for (i=0; i < FireBuffer.size(); i++)
        {
            FireBuffer[i]=0;
        }
    }
    // build fire
    for (x=0; x<BufferWi; x++)
    {
        r=x%2==0 ? 190+(rand() % 10) : 100+(rand() % 50);
        SetFireBuffer(x,0,r);
    }
    int step=255*100/BufferHt/HeightPct;
    int sum;
    for (y=1; y<BufferHt; y++)
    {
        for (x=0; x<BufferWi; x++)
        {
            v1=GetFireBuffer(x-1,y-1);
            v2=GetFireBuffer(x+1,y-1);
            v3=GetFireBuffer(x,y-1);
            v4=GetFireBuffer(x,y-1);
            n=0;
            sum=0;
            if(v1>=0)
            {
                sum+=v1;
                n++;
            }
            if(v2>=0)
            {
                sum+=v2;
                n++;
            }
            if(v3>=0)
            {
                sum+=v3;
                n++;
            }
            if(v4>=0)
            {
                sum+=v4;
                n++;
            }
            new_index=n > 0 ? sum / n : 0;
            if (new_index > 0)
            {
                new_index+=(rand() % 100 < 20) ? step : -step;
                if (new_index < 0) new_index=0;
                if (new_index >= FirePalette.size()) new_index = FirePalette.size()-1;
            }
            SetFireBuffer(x,y,new_index);
        }
    }
    for (y=0; y<BufferHt; y++)
    {
        for (x=0; x<BufferWi; x++)
        {
            //SetPixel(x,y,FirePalette[y]);
            SetPixel(x,y,FirePalette[GetFireBuffer(x,y)]);
        }
    }
}
Esempio n. 24
0
	void Draw :: setPixel(int x,int y,COLORREF selcolor){
		SetPixel ( ps.hdc , x , int(y) , selcolor ) ; 
	}
Esempio n. 25
0
void Graphics::SetPixel(const int x, const int y, const QColor color, QImage& image, const int alpha = 255)
{
    SetPixel(QPoint(x, y), color, image, alpha);
}
Esempio n. 26
0
HIMAGELIST
SdkCreateGrayImageList(
	IN HIMAGELIST himlNormal
	)
{
	int Count, i;
	int Width, Height;
	HIMAGELIST himlGray;
	HDC hdcDesktop;
	HDC hdcMem;
	RECT rc;
	COLORREF crMask;
	HPALETTE hpal;
	UINT index;
	HGDIOBJ hbm;
	HGDIOBJ hbmOld;
	COLORREF rgb;
	BYTE gray;
	HWND hWnd;
	int x, y;

	Count = ImageList_GetImageCount(himlNormal);
	if (Count == 0) {
		return NULL;
	}

	ImageList_GetIconSize(himlNormal, &Width, &Height);
	himlGray = ImageList_Create(Width, Height, ILC_COLOR24 | ILC_MASK, Count, 0);

	hdcDesktop = GetDC(NULL);
	hdcMem = CreateCompatibleDC(NULL);
	
	rc.top = rc.left = 0;
	rc.bottom = Height;
	rc.right = Width;
	crMask = RGB(200, 199, 200);

	if (GetDeviceCaps(hdcDesktop, BITSPIXEL) < 24) {
		hpal = (HPALETTE)GetCurrentObject(hdcDesktop, OBJ_PAL);
		index = GetNearestPaletteIndex(hpal, crMask);
		if (index != CLR_INVALID) { 
			crMask = PALETTEINDEX(index);
		}
	}

	for (i = 0 ; i < Count; ++i) {

		hbm = CreateCompatibleBitmap(hdcDesktop, Width, Height);
		hbmOld = SelectObject(hdcMem, hbm);

		SdkFillSolidRect(hdcMem, crMask, &rc);

		ImageList_SetBkColor(himlNormal, crMask);
		ImageList_Draw(himlNormal, i, hdcMem, 0, 0, ILD_NORMAL);

		for (x = 0 ; x < Width; ++x) {
			for (y = 0; y < Height; ++y) {
				rgb = GetPixel(hdcMem, x, y);
				if (rgb != crMask) { 
					gray = (BYTE) (95 + (GetRValue(rgb) * 3 + GetGValue(rgb) * 6 + GetBValue(rgb)) / 20);
					SetPixel(hdcMem, x, y, RGB(gray, gray, gray));
				}
			}
		}

		hbm = SelectObject(hdcMem, hbmOld);
		ImageList_AddMasked(himlGray, (HBITMAP)hbm, crMask);
		DeleteObject(hbm);
	}

	DeleteDC(hdcMem);
	hWnd = WindowFromDC(hdcDesktop);
	ReleaseDC(hWnd, hdcDesktop);

	return himlGray; 
}
Esempio n. 27
0
STDMETHODIMP CRandomEvent::put_Fire(long l)
{
    m_cs.Lock();
    foo pos;
    if (!m_mapPos.Lookup(l, pos))
    {
        m_mapPos[l] = foo();
    }
    COLORREF cr = RGB(255,255,255);
    switch (l)
    {
    case 0:
        cr = RGB(255,0,0);
        break;
    case 1:
        cr = RGB(0,255,0);
        break;
    case 2:
        cr = RGB(0,0,255);
        break;
    case 3:
        cr = RGB(255,255,0);
        break;
    case 4:
        cr = RGB(255,0,255);
        break;
    case 5:
        cr = RGB(0,255,255);
        break;
    case 6:
        cr = RGB(64,64,64);
        break;
    case 7:
        cr = RGB(128,128,128);
        break;
    case 8:
        cr = RGB(192,192,192);
        break;
    case 9:
        cr = RGB(0,0,0);
        break;
    }
    int nH = nHeight/nThreads;
    if (pos.nDir == 1)
        SetPixel(hDrawDC, m_nID, nH*l+pos.nPos, cr);
    else
        SetPixel(hDrawDC, m_nID, nH*l+pos.nPos, RGB(0,0,0));
    pos.nPos += pos.nDir;
    if (pos.nPos >= nH)
    {
        pos.nDir = -1;
        pos.nPos = nH-1;
    }
    if (pos.nPos <= -1)
    {
        pos.nDir = 1;
        pos.nPos = 0;
    }
    m_mapPos[l] = pos;
    m_cs.Unlock();
    GdiFlush();
    return S_OK;
}
Esempio n. 28
0
/*******************************************************************************
 Clear_Screen: ÇåLCDÏÔʾÆ÷ÆÁÄ»¡£
*******************************************************************************/
void ClrScrn(u16 Color)
{ u32 i;
  SetPosi(0, 0);
  for(i=0; i<240*LCD_ROW; i++) SetPixel(Color);
}
Esempio n. 29
0
void
startPaintingL(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
    start.x = x;
    start.y = y;
    last.x = x;
    last.y = y;
    switch (activeTool)
    {
        case TOOL_FREESEL:
            ShowWindow(hSelection, SW_HIDE);
            if (ptStack != NULL)
                HeapFree(GetProcessHeap(), 0, ptStack);
            ptStack = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(POINT) * 1024);
            ptSP = 0;
            ptStack[0].x = x;
            ptStack[0].y = y;
            break;
        case TOOL_TEXT:
        case TOOL_LINE:
        case TOOL_RECT:
        case TOOL_ELLIPSE:
        case TOOL_RRECT:
            newReversible();
            break;
        case TOOL_RECTSEL:
            newReversible();
            ShowWindow(hSelection, SW_HIDE);
            rectSel_src[2] = rectSel_src[3] = 0;
            break;
        case TOOL_RUBBER:
            newReversible();
            Erase(hdc, x, y, x, y, bg, rubberRadius);
            break;
        case TOOL_FILL:
            newReversible();
            Fill(hdc, x, y, fg);
            break;
        case TOOL_PEN:
            newReversible();
            SetPixel(hdc, x, y, fg);
            break;
        case TOOL_BRUSH:
            newReversible();
            Brush(hdc, x, y, x, y, fg, brushStyle);
            break;
        case TOOL_AIRBRUSH:
            newReversible();
            Airbrush(hdc, x, y, fg, airBrushWidth);
            break;
        case TOOL_BEZIER:
            pointStack[pointSP].x = x;
            pointStack[pointSP].y = y;
            if (pointSP == 0)
            {
                newReversible();
                pointSP++;
            }
            break;
        case TOOL_SHAPE:
            pointStack[pointSP].x = x;
            pointStack[pointSP].y = y;
            if (pointSP + 1 >= 2)
                Poly(hdc, pointStack, pointSP + 1, fg, bg, lineWidth, shapeStyle, FALSE);
            if (pointSP == 0)
            {
                newReversible();
                pointSP++;
            }
            break;
    }
}
Esempio n. 30
-1
void
endPaintingR(HDC hdc, LONG x, LONG y, COLORREF fg, COLORREF bg)
{
    switch (activeTool)
    {
        case TOOL_RUBBER:
            Replace(hdc, last.x, last.y, x, y, fg, bg, rubberRadius);
            break;
        case TOOL_PEN:
            Line(hdc, last.x, last.y, x, y, bg, 1);
            SetPixel(hdc, x, y, bg);
            break;
        case TOOL_LINE:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                roundTo8Directions(start.x, start.y, &x, &y);
            Line(hdc, start.x, start.y, x, y, bg, lineWidth);
            break;
        case TOOL_BEZIER:
            pointSP++;
            if (pointSP == 4)
                pointSP = 0;
            break;
        case TOOL_RECT:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            Rect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle);
            break;
        case TOOL_SHAPE:
            resetToU1();
            pointStack[pointSP].x = x;
            pointStack[pointSP].y = y;
            if ((pointSP > 0) && (GetAsyncKeyState(VK_SHIFT) < 0))
                roundTo8Directions(pointStack[pointSP - 1].x, pointStack[pointSP - 1].y,
                                   &pointStack[pointSP].x, &pointStack[pointSP].y);
            pointSP++;
            if (pointSP >= 2)
            {
                if ((pointStack[0].x - x) * (pointStack[0].x - x) +
                    (pointStack[0].y - y) * (pointStack[0].y - y) <= lineWidth * lineWidth + 1)
                {
                    Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, TRUE);
                    pointSP = 0;
                }
                else
                {
                    Poly(hdc, pointStack, pointSP, bg, fg, lineWidth, shapeStyle, FALSE);
                }
            }
            if (pointSP == 255)
                pointSP--;
            break;
        case TOOL_ELLIPSE:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            Ellp(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle);
            break;
        case TOOL_RRECT:
            resetToU1();
            if (GetAsyncKeyState(VK_SHIFT) < 0)
                regularize(start.x, start.y, &x, &y);
            RRect(hdc, start.x, start.y, x, y, bg, fg, lineWidth, shapeStyle);
            break;
    }
}