示例#1
0
文件: timer.c 项目: jetlive/xynth
int main (int argc, char *argv[])
{
	int x = 60;
	int y = 60;
	int w = 400;
	int h = 300;
	int mw = 1000;
	int mh = 1000;
	char *box;
	s_timer_t *timer;
	s_handler_t *hndl;
	s_window_t *window;

	s_window_init(&window);

	s_window_new(window, WINDOW_TYPE_MAIN, NULL);
	mw = window->surface->width;
	mh = window->surface->height;
	box = (char *) s_malloc(sizeof(char) * (mw / 4) * (mh / 4) * window->surface->bytesperpixel);

	s_window_set_title(window, "Demo - %s", argv[0]);
	s_window_set_coor(window, 0, x, y, w, h);

	s_fillbox(window->surface, mw/4, mh/4, mw/4, mh/4, s_rgbcolor(window->surface, 255, 0, 0));
	s_fillbox(window->surface, mw/2, mh/4, mw/4, mh/4, s_rgbcolor(window->surface, 0, 255, 0));
	s_fillbox(window->surface, mw/4, mh/2, mw/4, mh/4, s_rgbcolor(window->surface, 0, 0, 255));
	s_fillbox(window->surface, mw/2, mh/2, mw/4, mh/4, s_rgbcolor(window->surface, 255, 255, 255));

	s_getbox(window->surface, mw/4, mh/4, mw/4, mh/4, box);
	s_putbox(window->surface, 0, 0, mw/4, mh/4, box);
	s_free(box);

	s_fillbox(window->surface, 0, 0, 20, 20, s_rgbcolor(window->surface, 222, 222, 222));
	s_fillbox(window->surface, 2, 2, 16, 16, s_rgbcolor(window->surface, 0, 0, 0));
	s_handler_init(&hndl);
	hndl->type = MOUSE_HANDLER;
	hndl->mouse.x = 2;
	hndl->mouse.y = 2;
	hndl->mouse.w = 16;
	hndl->mouse.h = 16;
	hndl->mouse.p = timer_handler_p;
	hndl->mouse.button = MOUSE_BUTTON_LEFT;
	s_handler_add(window, hndl);

	s_timer_init(&timer);
	timer->timeval = 2000;
	timer->cb = timer0_cb;
	s_timer_add(window, timer);

	s_timer_init(&timer);
	timer->timeval = 2500;
	timer->cb = timer1_cb;
	s_timer_add(window, timer);

	s_window_show(window);
	s_window_main(window);

	return 0;
}
示例#2
0
文件: taskbar.c 项目: jetlive/xynth
void taskbar_start_menu_icon (s_window_t *window)
{
        s_surface_t *srf;
        tbar_data_t *tbar_data;
        tbar_smenu_t *tbar_smenu;

        tbar_data = (tbar_data_t *) window->data;
        tbar_smenu = (tbar_smenu_t *) tbar_data->tbar_smenu;

        if (s_surface_create(&srf, tbar_smenu->img->w, tbar_smenu->img->h, window->surface->bitsperpixel)) {
        	return;
        }
        s_getbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->img->w, tbar_smenu->img->h, srf->vbuf);
        s_putboxrgba(srf, 0, 0, tbar_smenu->img->w, tbar_smenu->img->h, tbar_smenu->img->rgba);
        s_putbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->img->w, tbar_smenu->img->h, srf->vbuf);
        s_surface_destroy(srf);
}
示例#3
0
文件: taskbar.c 项目: jetlive/xynth
void taskbar_start_menu_handler_p (s_window_t *window, s_event_t *event, s_handler_t *handler)
{
        char *box;
        tbar_data_t *tbar_data;
        tbar_smenu_t *tbar_smenu;

        tbar_data = (tbar_data_t *) window->data;
        tbar_smenu = (tbar_smenu_t *) tbar_data->tbar_smenu;

        while (tbar_data->tbar_smenu->running) {
		usleep(20000);
	}

	box = (char *) s_malloc(tbar_smenu->rect.w * tbar_smenu->rect.h * window->surface->bytesperpixel);
	s_getbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->rect.w, tbar_smenu->rect.h, box);
	s_fillbox(window->surface, tbar_smenu->rect.x, tbar_smenu->rect.y, tbar_smenu->rect.w + 2, tbar_smenu->rect.h + 2, s_rgbcolor(window->surface, 115, 117, 115));
	s_fillbox(window->surface, tbar_smenu->rect.x + 1, tbar_smenu->rect.y + 1, tbar_smenu->rect.w + 1, tbar_smenu->rect.h + 1, s_rgbcolor(window->surface, 255, 255, 255));
	s_putbox(window->surface, tbar_smenu->rect.x + 1, tbar_smenu->rect.y + 1, tbar_smenu->rect.w, tbar_smenu->rect.h, box);
	s_free(box);
	start_menu_start(window, tbar_data->tbar_smenu->progs, window->surface->buf->x, window->surface->buf->y);
}
示例#4
0
文件: server.c 项目: jetlive/xynth
void s_video_gdi_server_surface_update (s_rect_t *coor)
{
	char *ptr;
	char *tmp;
	BITMAP bm;
	HDC memoryDC;
	HBITMAP hBtmp;
	HDC mainwindow;
	s_rect_t inter;
	
	s_rect_t clip = {0, 0, xynth_server->window->surface->width, xynth_server->window->surface->height};
	s_video_gdi_data_t *priv = (s_video_gdi_data_t *) xynth_server->driver->driver_data;

        if (priv->bpp_windows == 0) {
                return;
        }
	if (s_region_rect_intersect(&clip, coor, &inter)) {
		return;
	}

	ptr = (char *) s_malloc(inter.w * inter.h * xynth_server->window->surface->bytesperpixel);
	s_getbox(xynth_server->window->surface, inter.x, inter.y, inter.w, inter.h, ptr);

	mainwindow = GetDC(priv->hwndMain);
	if (mainwindow == NULL) {
		debugf(DSER, "GetDC(priv->hwndMain) == NULL");
		goto err0;
	}
	if (priv->bpp_windows != xynth_server->window->surface->bitsperpixel) {
                s_copybuffer(ptr, xynth_server->window->surface->bitsperpixel, &tmp, priv->bpp_windows, inter.w, inter.h);
	} else {
		tmp = ptr;
        }
	
	hBtmp = CreateBitmap(inter.w, inter.h, 1, priv->bpp_windows, tmp);
	if (hBtmp == NULL) {
		debugf(DSER, "CreateBitmap(inter.w, inter.h, 1, priv->bpp_windows, tmp) == NULL");
		goto err1;
	}
	memoryDC = CreateCompatibleDC(mainwindow);
	if (memoryDC == NULL) {
		debugf(DSER, "CreateCompatibleDC(mainwindow) == NULL");
		goto err2;
        }
	if (GetObject(hBtmp, sizeof(BITMAP), (LPVOID) &bm) == 0) {
		debugf(DSER, "GetObject(hBtmp, sizeof(BITMAP), (LPVOID) &bm) == 0");
		goto err3;
	}
	if (SelectObject(memoryDC, hBtmp) == NULL) {
		debugf(DSER, "SelectObject(memoryDC, hBtmp) == NULL");
		goto err4;
	}
	BitBlt(mainwindow, inter.x, inter.y, inter.w, inter.h, memoryDC, 0, 0, SRCCOPY);
	DeleteDC(memoryDC);
	DeleteObject(hBtmp);
	ReleaseDC(priv->hwndMain, mainwindow);

	s_free(ptr);
	if (priv->bpp_windows != xynth_server->window->surface->bitsperpixel) {
		s_free(tmp);
        }
        return;

err4:
err3:   DeleteDC(memoryDC);
err2:	DeleteObject(hBtmp);
err1:	ReleaseDC(priv->hwndMain, mainwindow);
       	if (priv->bpp_windows != xynth_server->window->surface->bitsperpixel) {
		s_free(tmp);
        }
err0:   free(ptr);
}
示例#5
0
文件: mines.cpp 项目: d33tah/whitix
void MButton::objectDraw (void)
{
        int x;
        int y;
        int w;
        int h;
        int x_;
        int y_;
	int c[3];
        char *vbuf;
	char text[3];
        s_surface_t s;
	s_font_t *font;
	unsigned int *mat;
	
	if (buttonMines->minesMatrix_[buttonR][buttonC] == 1) {
		this->frameSetStyle((this->frameStyle & SFrame::MShape) | SFrame::Sunken);
	}
	
	SButton::objectDraw();

	if (buttonMines->minesMatrix_[buttonR][buttonC] == 1) {
		if (buttonMines->minesMatrix[buttonR][buttonC] == 0) {
			/* top */
			buttonDrawEmpty(buttonR - 1, buttonC);
			/* top right */
			buttonDrawEmpty(buttonR - 1, buttonC + 1);
			/* right */
			buttonDrawEmpty(buttonR, buttonC + 1);
			/* bottom right */
			buttonDrawEmpty(buttonR + 1, buttonC + 1);
			/* bottom */
			buttonDrawEmpty(buttonR + 1, buttonC);
			/* bottom left */
			buttonDrawEmpty(buttonR + 1, buttonC - 1);
			/* left */
			buttonDrawEmpty(buttonR, buttonC - 1);
			/* top left */
			buttonDrawEmpty(buttonR - 1, buttonC - 1);
		} else if (buttonMines->minesMatrix[buttonR][buttonC] > 0) {
			if ((objectRectContents.rectH - 2) < 0) {
				return;
			}
			s_font_init(&font, "arial.ttf");
			sprintf(text, "%d", (int) (buttonMines->minesMatrix[buttonR][buttonC]));
			s_font_set_str(font, text);
			s_font_set_size(font, objectRectContents.rectH - 2);
			s_font_get_glyph(font);
			s_image_get_handler(font->img);

			switch (buttonMines->minesMatrix[buttonR][buttonC]) {
				case 1: c[0] = 0;	c[1] = 0;	c[2] = 255;	break;
				case 2: c[0] = 0;	c[1] = 136;	c[2] = 0;	break;
				case 3: c[0] = 136;	c[1] = 136;	c[2] = 0;	break;
				case 4: c[0] = 136;	c[1] = 0;	c[2] = 136;	break;
				case 5: c[0] = 255;	c[1] = 0;	c[2] = 0;	break;
				case 6: c[0] = 136;	c[1] = 0;	c[2] = 0;	break;
				case 7: c[0] = 0;	c[1] = 0;	c[2] = 0;	break;
				default:
				case 8: c[0] = 0;	c[1] = 0;	c[2] = 0;	break;
			}

			x_ = objectRectContents.rectX + ((((objectRectContents.rectW - font->img->w) / 2) < 0) ? 0 : ((objectRectContents.rectW - font->img->w) / 2));
			y_ = objectRectContents.rectY + ((((objectRectContents.rectH - font->yMax) / 2) < 0) ? 0 : ((objectRectContents.rectH - font->yMax) / 2));
			w = (objectRectContents.rectW < font->img->w) ? objectRectContents.rectW : font->img->w;
			h = (objectRectContents.rectH < font->img->h) ? objectRectContents.rectH : font->img->h;

		        vbuf = (char *) s_malloc(objectWindow->surface->bytesperpixel * font->img->w * font->img->h + 1);
		        s_getsurfacevirtual(&s, font->img->w, font->img->h, objectWindow->surface->bitsperpixel, vbuf);
		        s_getbox(objectWindow->surface, x_, y_, font->img->w, font->img->h, s.vbuf);

		        mat = font->img->rgba;
			for (y = 0; y < h; y++) {
				for (x = 0; x < w; x++) {
					if (~*mat & 0xff) {
						s_setpixelrgba(&s, x, y, c[0], c[1], c[2], *mat & 0xff);
					}
					mat++;
				}
				mat += font->img->w - w;
			}

			s_putbox(objectWindow->surface, x_, y_, font->img->w, font->img->h, s.vbuf);
        		s_free(vbuf);
        		s_font_uninit(font);
		} else if (buttonMines->minesMatrix[buttonR][buttonC] < 0) {
			x = objectRectContents.rectX + ((((objectRectContents.rectW - buttonMines->minesMine->w) / 2) < 0) ? 0 : ((objectRectContents.rectW - buttonMines->minesMine->w) / 2));
			y = objectRectContents.rectY + ((((objectRectContents.rectH - buttonMines->minesMine->h) / 2) < 0) ? 0 : ((objectRectContents.rectH - buttonMines->minesMine->h) / 2));
			w = (objectRectContents.rectW < buttonMines->minesMine->w) ? objectRectContents.rectW : buttonMines->minesMine->w;
			h = (objectRectContents.rectH < buttonMines->minesMine->h) ? objectRectContents.rectH : buttonMines->minesMine->h;
			s_putboxpartmask(objectWindow->surface, x, y, w, h, buttonMines->minesMine->w, buttonMines->minesMine->h, buttonMines->minesMine->buf, buttonMines->minesMine->mat, 0, 0);
		}
	} else 	if (buttonMines->minesMatrix_[buttonR][buttonC] == 2) {
		x = objectRectContents.rectX + ((((objectRectContents.rectW - buttonMines->minesFlag->w) / 2) < 0) ? 0 : ((objectRectContents.rectW - buttonMines->minesFlag->w) / 2));
		y = objectRectContents.rectY + ((((objectRectContents.rectH - buttonMines->minesFlag->h) / 2) < 0) ? 0 : ((objectRectContents.rectH - buttonMines->minesFlag->h) / 2));
		w = (objectRectContents.rectW < buttonMines->minesFlag->w) ? objectRectContents.rectW : buttonMines->minesFlag->w;
		h = (objectRectContents.rectH < buttonMines->minesFlag->h) ? objectRectContents.rectH : buttonMines->minesFlag->h;
		s_putboxpartmask(objectWindow->surface, x, y, w, h, buttonMines->minesFlag->w, buttonMines->minesFlag->h, buttonMines->minesFlag->buf, buttonMines->minesFlag->mat, 0, 0);
	} else 	if (buttonMines->minesMatrix_[buttonR][buttonC] == 3) {
		if ((objectRectContents.rectH - 2) < 0) {
			return;
		}
		s_font_init(&font, "arial.ttf");
		sprintf(text, "%s", "?");
		s_font_set_str(font, text);
		s_font_set_size(font, objectRectContents.rectH - 2);
		s_font_get_glyph(font);
		s_image_get_handler(font->img);

		x_ = objectRectContents.rectX + ((((objectRectContents.rectW - font->img->w) / 2) < 0) ? 0 : ((objectRectContents.rectW - font->img->w) / 2));
		y_ = objectRectContents.rectY + ((((objectRectContents.rectH - font->yMax) / 2) < 0) ? 0 : ((objectRectContents.rectH - font->yMax) / 2));
		w = (objectRectContents.rectW < font->img->w) ? objectRectContents.rectW : font->img->w;
		h = (objectRectContents.rectH < font->img->h) ? objectRectContents.rectH : font->img->h;
                
		vbuf = (char *) s_malloc(objectWindow->surface->bytesperpixel * font->img->w * font->img->h + 1);
		s_getsurfacevirtual(&s, font->img->w, font->img->h, objectWindow->surface->bitsperpixel, vbuf);
		s_getbox(objectWindow->surface, x_, y_, font->img->w, font->img->h, s.vbuf);

                mat = font->img->rgba;
		for (y = 0; y < h; y++) {
			for (x = 0; x < w; x++) {
				if (~*mat & 0xff) {
					s_setpixelrgba(&s, x, y, 0, 0, 0, *mat & 0xff);
				}
				mat++;
			}
			mat += font->img->w - w;
		}

		s_putbox(objectWindow->surface, x_, y_, font->img->w, font->img->h, s.vbuf);
        	s_free(vbuf);
		s_font_uninit(font);
	}
}