Ejemplo n.º 1
0
void
Canvas::fill_screen()
{
    color16_t saved = set_pen_color(get_canvas_color());
    fill_rect(0, 0, WIDTH, HEIGHT);
    set_pen_color(saved);
}
Ejemplo n.º 2
0
void
Canvas::draw_char(uint8_t x, uint8_t y, char c)
{
    uint8_t scale = get_text_scale();
    color16_t saved = set_pen_color(get_text_color());
    Font* font = get_text_font();
    font->draw(this, c, x, y, scale);
    set_cursor(x + scale * (font->get_width(c)), y);
    set_pen_color(saved);
}
Ejemplo n.º 3
0
void ppu_vt03_device::set_new_pen(int i)
{
	if((i < 0x20) && ((i & 0x3) == 0)) {
		set_pen_color(i & 0x7f, rgb_t(0, 0, 0));
	} else {
		if(m_pal_mode == PAL_MODE_NEW_RGB) {
			uint16_t rgbval = (m_newpal[i&0x7f] & 0xff) | ((m_newpal[(i&0x7f)+0x80] & 0xff)<<8);
			uint8_t blue = (rgbval & 0x001f) << 3;
			uint8_t green = (rgbval & 0x3e0) >> 2;
			uint8_t red  = (rgbval & 0x7C00) >> 7;
			set_pen_color(i & 0x7f, rgb_t(red, green, blue));
		} else if(m_pal_mode == PAL_MODE_NEW_RGB12) {
Ejemplo n.º 4
0
void device_palette_interface::interface_post_load()
{
	// reset the pen and brightness for each entry
	int numcolors = m_palette->num_colors();
	for (int index = 0; index < numcolors; index++)
	{
		set_pen_color(index, m_save_pen[index]);
		set_pen_contrast(index, m_save_contrast[index]);
	}
}
Ejemplo n.º 5
0
void ppu2c0x_rgb_device::init_palette()
{
	/* Loop through the emphasis modes (8 total) */
	int entry = 0;
	for (int color_emphasis = 0; color_emphasis < 8; color_emphasis++)
	{
		for (int color_num = 0; color_num < 64; color_num++)
			{
				int R = ((color_emphasis & 1) ? 7 : m_palette_data[color_num * 3]);
				int G = ((color_emphasis & 2) ? 7 : m_palette_data[color_num * 3 + 1]);
				int B = ((color_emphasis & 4) ? 7 : m_palette_data[color_num * 3 + 2]);

				set_pen_color(entry++, pal3bit(R), pal3bit(G), pal3bit(B));
			}
	}

	/* color tables are modified at run-time, and are initialized on 'ppu2c0x_reset' */
}
Ejemplo n.º 6
0
void ppu2c0x_device::init_palette(bool indirect)
{
	/* This routine builds a palette using a transformation from */
	/* the YUV (Y, B-Y, R-Y) to the RGB color space */

	/* The NES has a 64 color palette                        */
	/* 16 colors, with 4 luminance levels for each color     */
	/* The 16 colors circle around the YUV color space,      */

	const double tint = 0.22; /* adjust to taste */
	const double hue = 287.0;

	const double Kr = 0.2989;
	const double Kb = 0.1145;
	const double Ku = 2.029;
	const double Kv = 1.140;

	static const double brightness[3][4] =
	{
		{ 0.50, 0.75, 1.0, 1.0 },
		{ 0.29, 0.45, 0.73, 0.9 },
		{ 0, 0.24, 0.47, 0.77 }
	};

	int entry = 0;

	/* Loop through the emphasis modes (8 total) */
	for (int color_emphasis = 0; color_emphasis < 8; color_emphasis++)
	{
		/*
		double r_mod = 0.0;
		double g_mod = 0.0;
		double b_mod = 0.0;

		switch (color_emphasis)
		{
		    case 0: r_mod = 1.0;  g_mod = 1.0;  b_mod = 1.0;  break;
		    case 1: r_mod = 1.24; g_mod = .915; b_mod = .743; break;
		    case 2: r_mod = .794; g_mod = 1.09; b_mod = .882; break;
		    case 3: r_mod = .905; g_mod = 1.03; b_mod = 1.28; break;
		    case 4: r_mod = .741; g_mod = .987; b_mod = 1.0;  break;
		    case 5: r_mod = 1.02; g_mod = .908; b_mod = .979; break;
		    case 6: r_mod = 1.02; g_mod = .98;  b_mod = .653; break;
		    case 7: r_mod = .75;  g_mod = .75;  b_mod = .75;  break;
		}
		*/

		/* loop through the 4 intensities */
		for (int color_intensity = 0; color_intensity < 4; color_intensity++)
		{
			/* loop through the 16 colors */
			for (int color_num = 0; color_num < 16; color_num++)
			{
				double sat;
				double y, u, v;
				double rad;

				switch (color_num)
				{
				case 0:
					sat = 0; rad = 0;
					y = brightness[0][color_intensity];
					break;

				case 13:
					sat = 0; rad = 0;
					y = brightness[2][color_intensity];
					break;

				case 14:
				case 15:
					sat = 0; rad = 0; y = 0;
					break;

				default:
					sat = tint;
					rad = M_PI * ((color_num * 30 + hue) / 180.0);
					y = brightness[1][color_intensity];
					break;
				}

				u = sat * cos(rad);
				v = sat * sin(rad);

				/* Transform to RGB */
				double R = (y + Kv * v) * 255.0;
				double G = (y - (Kb * Ku * u + Kr * Kv * v) / (1 - Kb - Kr)) * 255.0;
				double B = (y + Ku * u) * 255.0;

				/* Clipping, in case of saturation */
				if (R < 0)
					R = 0;
				if (R > 255)
					R = 255;
				if (G < 0)
					G = 0;
				if (G > 255)
					G = 255;
				if (B < 0)
					B = 0;
				if (B > 255)
					B = 255;

				/* Round, and set the value */
				if (indirect)
					set_indirect_color(entry++, rgb_t(floor(R + .5), floor(G + .5), floor(B + .5)));
				else
					set_pen_color(entry++, floor(R + .5), floor(G + .5), floor(B + .5));
			}
		}
	}

	/* color tables are modified at run-time, and are initialized on 'ppu2c0x_reset' */
}
Ejemplo n.º 7
0
 NODE *lshowturtle(NODE *args) {
-    prepare_to_draw;
+    prepare_to_draw2(UNBOUND);
     if (!turtle_shown) {
 	turtle_shown = TRUE;
 	draw_turtle();
@@ -545,7 +545,7 @@ NODE *lshowturtle(NODE *args) {
 }
 
 NODE *lhideturtle(NODE *args) {
-    prepare_to_draw;
+    prepare_to_draw2(UNBOUND);
     if (turtle_shown) {
 	draw_turtle();
 	turtle_shown = FALSE;
@@ -874,7 +874,7 @@ NODE *llabel(NODE *arg) {
     *print_stringptr = '\0';
 	
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	draw_turtle();
 	theLength = strlen(textbuf);
 #ifdef mac
@@ -983,7 +983,7 @@ NODE *lsetpencolor(NODE *arg) {
     NODE *val = pos_int_arg(arg);
 
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	set_pen_color(getint(val));
 	save_color();
 	done_drawing;
@@ -995,7 +995,7 @@ NODE *lsetbackground(NODE *arg) {
     NODE *val = pos_int_arg(arg);
 
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	set_back_ground(getint(val));
 	done_drawing;
     }
@@ -1008,7 +1008,7 @@ NODE *lsetpalette(NODE *args) {
 	int slotnum = (int)getint(slot);
 
 	if (NOT_THROWING && (slotnum > 7)) {
-		prepare_to_draw;
+		prepare_to_draw2(UNBOUND);
 		set_palette(slotnum,
 			    (unsigned int)getint(car(arg)),
 			    (unsigned int)getint(cadr(arg)),
@@ -1057,7 +1057,7 @@ NODE *lsetpensize(NODE *args) {
     NODE *arg = pos_int_vector_arg(args);
 
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	set_pen_width((int)getint(car(arg)));
 	set_pen_height((int)getint(cadr(arg)));
 	save_size();
@@ -1074,7 +1074,7 @@ NODE *lsetpenpattern(NODE *args) {    
 	arg = err_logo(BAD_DATA, arg);
 	
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	set_list_pen_pattern(arg);
 	save_pattern();
 	done_drawing;
@@ -1090,7 +1090,7 @@ NODE *lsetscrunch(NODE *args) {
     ynode = numeric_arg(cdr(args));
 
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	draw_turtle();
 	x_scale = (nodetype(xnode) == FLOATT) ? getfloat(xnode) :
 			       (FLONUM)getint(xnode);
@@ -1227,7 +1227,7 @@ NODE *larc(NODE *arg) {
 	else
 	    radius = getfloat(val2);
 
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	draw_turtle();
 
 	/* save and force turtle state */
@@ -1582,7 +1582,7 @@ NODE *lloadpict(NODE *args) {
     lopenread(args);
 #endif
     if (NOT_THROWING) {
-	prepare_to_draw;
+	prepare_to_draw2(UNBOUND);
 	fp = (FILE *)file_list->n_obj;
 	restore_palette(fp);
 	fread(&record_index, sizeof(FIXNUM), 1, fp);
Ejemplo n.º 8
0
void
Canvas::run(uint8_t ix, const void_P* tab, uint8_t max)
{
    if (ix >= max) return;
    const uint8_t* ip = (const uint8_t*) pgm_read_word(tab + ix);
    uint8_t x, y, r, g, b, w, h, s;
    int8_t dx, dy;
    char c;
    while (1) {
        switch (pgm_read_byte(ip++)) {
        case END_SCRIPT:
            return;
        case CALL_SCRIPT:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            run(ix, tab, max);
            break;
        case SET_CANVAS_COLOR:
            r = pgm_read_byte(ip++);
            g = pgm_read_byte(ip++);
            b = pgm_read_byte(ip++);
            set_canvas_color(color(r, b, g));
            break;
        case SET_PEN_COLOR:
            r = pgm_read_byte(ip++);
            g = pgm_read_byte(ip++);
            b = pgm_read_byte(ip++);
            set_pen_color(color(r, g, b));
            break;
        case SET_TEXT_COLOR:
            r = pgm_read_byte(ip++);
            g = pgm_read_byte(ip++);
            b = pgm_read_byte(ip++);
            set_text_color(color(r, g, b));
            break;
        case SET_TEXT_SCALE:
            set_text_scale(pgm_read_byte(ip++));
            break;
        case SET_TEXT_FONT:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            set_text_font((Font*) pgm_read_word(tab + ix));
            break;
        case SET_CURSOR:
            x = pgm_read_byte(ip++);
            y = pgm_read_byte(ip++);
            set_cursor(x, y);
            break;
        case MOVE_CURSOR:
            dx = pgm_read_byte(ip++);
            dy = pgm_read_byte(ip++);
            move_cursor(dx, dy);
            break;
        case DRAW_BITMAP:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            w = pgm_read_byte(ip++);
            h = pgm_read_byte(ip++);
            s = pgm_read_byte(ip++);
            draw_bitmap((const uint8_t*) pgm_read_word(tab + ix), w, h, s);
            break;
        case DRAW_ICON:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            s = pgm_read_byte(ip++);
            draw_icon((const uint8_t*) pgm_read_word(tab + ix), s);
            break;
        case DRAW_PIXEL:
            draw_pixel();
            break;
        case DRAW_LINE:
            x = pgm_read_byte(ip++);
            y = pgm_read_byte(ip++);
            draw_line(x, y);
            break;
        case DRAW_POLY:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            s = pgm_read_byte(ip++);
            draw_poly_P((const int8_t*) pgm_read_word(tab + ix), s);
            break;
        case DRAW_STROKE:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            s = pgm_read_byte(ip++);
            draw_stroke_P((const int8_t*) pgm_read_word(tab + ix), s);
            break;
        case DRAW_RECT:
            w = pgm_read_byte(ip++);
            h = pgm_read_byte(ip++);
            draw_rect(w, h);
            break;
        case FILL_RECT:
            w = pgm_read_byte(ip++);
            h = pgm_read_byte(ip++);
            fill_rect(w, h);
            break;
        case DRAW_ROUNDRECT:
            w = pgm_read_byte(ip++);
            h = pgm_read_byte(ip++);
            r = pgm_read_byte(ip++);
            draw_roundrect(w, h, r);
            break;
        case FILL_ROUNDRECT:
            w = pgm_read_byte(ip++);
            h = pgm_read_byte(ip++);
            r = pgm_read_byte(ip++);
            fill_roundrect(w, h, r);
            break;
        case DRAW_CIRCLE:
            r = pgm_read_byte(ip++);
            draw_circle(r);
            break;
        case FILL_CIRCLE:
            r = pgm_read_byte(ip++);
            fill_circle(r);
            break;
        case DRAW_CHAR:
            c = pgm_read_byte(ip++);
            draw_char(c);
            break;
        case DRAW_STRING:
            ix = pgm_read_byte(ip++);
            if (ix >= max) return;
            draw_string_P((const char*) pgm_read_word(tab + ix));
            break;
        case FILL_SCREEN:
            fill_screen();
            break;
        default:
            return;
        }
    }
}
Ejemplo n.º 9
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    // Setup this MainWindow with the parameters mainwindow.ui:
    // Definition of size, creation of widgets inside etc..
    ui->setupUi(this);

    // Retrieve pointers of widgets already created by the up operation
    // Those who will be used again outside the creator are saved at class variables
    QMenuBar * menuBar = ui->menuBar;
    QSlider *slider_color = ui->verticalSlider;
    QSlider *slider_style = ui->verticalSlider_2;
    QToolBar * toolbar = ui->toolBar;
    mydrawzone = ui->widget;

    // Declaration of menus and adition inside menubar
    QMenu * openMenu = menuBar->addMenu( tr("&Open"));
    QMenu * saveMenu = menuBar->addMenu( tr("&Save"));
    QMenu * quitMenu = menuBar->addMenu( tr("&Quit"));
    QMenu * penMenu = menuBar->addMenu( tr("&Pen Settings"));
    QMenu * colorMenu = menuBar->addMenu( tr("&Color Settings"));
    QMenu * styleMenu = menuBar->addMenu( tr("&Style Settings"));
    QMenu * formMenu = menuBar->addMenu( tr("&Form Settings"));

    // Declaration of principal actions
    // Those that will be shown at the toolbar
    QAction * openAction = new QAction( QIcon(":/icons/open.png"), tr("&Open"), this);
    QAction * saveAction = new QAction( QIcon(":/icons/save.png"), tr("&Save"), this);
    QAction * quitAction = new QAction( QIcon(":/icons/quit.png"), tr("&Quit"), this);
    QAction * paintAction = new QAction( QIcon(":/icons/paint.png"), tr("&Paint"), this);
    QAction * editAction = new QAction( QIcon(":/icons/edit.png"), tr("&Edit"), this);
    QAction * moveAction = new QAction( QIcon(":/icons/move.png"), tr("&Edit"), this);

    // Declaration of some other actions
    // Those that will have shortcuts as well but wont be shown in the toolbar
    QAction *set_pen_color =new QAction(tr("Alternate Color Pen"), this);
    QAction *set_pen_width_larger =new QAction(tr("&Pen Width +"), this);
    QAction *set_pen_width_shorter =new QAction(tr("&Pen Width -"), this);
    QAction *set_pen_style =new QAction(tr("&Alternate Style Pen"), this);
    QAction *set_figure_form =new QAction(tr("&Alternate Figure Form"), this);
    QAction *undo =new QAction(tr("&Undo"), this);

    // Declaration of action groups
    // The pointers for the actions are saved inside class variables
    // to be used outside the class creator
    QActionGroup *action_group_color = new QActionGroup(this);
    color0 = action_group_color->addAction(tr("Black Pen"));
    color1 = action_group_color->addAction(tr("White Pen"));
    color2 = action_group_color->addAction(tr("Dark Gray Pen"));
    color3 = action_group_color->addAction(tr("Gray Pen"));
    color4 = action_group_color->addAction(tr("Light Gray Pen"));
    color5 = action_group_color->addAction(tr("Red Pen"));
    color6 = action_group_color->addAction(tr("Green Pen"));
    color7 = action_group_color->addAction(tr("Blue Pen"));
    color8 = action_group_color->addAction(tr("Cyan Pen"));
    color9 = action_group_color->addAction(tr("Magenta Pen"));
    color10 = action_group_color->addAction(tr("Yellow Pen"));
    color11 = action_group_color->addAction(tr("Dark Red Pen"));
    color12 = action_group_color->addAction(tr("Dark Green Pen"));
    color13 = action_group_color->addAction(tr("Dark Blue Pen"));
    color14 = action_group_color->addAction(tr("Dark Cyan Pen"));
    color15 = action_group_color->addAction(tr("Dark Magenta Pen"));
    color16 = action_group_color->addAction(tr("Dark Yellow Pen"));
    color17 = action_group_color->addAction(tr("Transparent"));

    QActionGroup *action_group_style = new QActionGroup(this);
    style0 = action_group_style->addAction(tr("Solid Pen"));
    style1 = action_group_style->addAction(tr("Dash Line Pen"));
    style2 = action_group_style->addAction(tr("Dot Line Pen"));
    style3 = action_group_style->addAction(tr("Dash dot Line Pen"));
    style4 = action_group_style->addAction(tr("Dash Dot Dot Line Pen"));
    style5 = action_group_style->addAction(tr("Custom Dash Line Pen"));

    QActionGroup *action_group_form = new QActionGroup(this);
    form0 = action_group_form->addAction(tr("Line Form"));
    form1 = action_group_form->addAction(tr("Rectangle Form"));
    form2 = action_group_form->addAction(tr("Elipse Form"));

    // Adition of shortcuts for principal actions
    openAction->setShortcut( tr("Ctrl+O"));
    saveAction->setShortcut( tr("Ctrl+S"));
    quitAction->setShortcut( tr("Ctrl+Q"));
    paintAction->setShortcut( tr("Ctrl+P"));
    editAction->setShortcut( tr("Ctrl+E"));
    moveAction->setShortcut( tr("Ctrl+M"));

    // Adition of shortcuts for those other actions
    set_pen_color->setShortcut( tr("Ctrl+C"));
    set_pen_style->setShortcut( tr("Ctrl+Space"));
    set_pen_width_larger->setShortcut( tr("Ctrl++"));
    set_pen_width_shorter->setShortcut( tr("Ctrl+-"));
    set_figure_form->setShortcut( tr("Ctrl+F"));
    undo->setShortcut(tr ("Ctrl+Z"));

    // Adition of tool tips for principal actions
    openAction->setToolTip( tr("Open file"));
    saveAction->setToolTip( tr("Save file"));
    quitAction->setToolTip( tr("Quit file"));

    // Adition of status tips for principal actions
    openAction->setStatusTip( tr("Open file"));
    saveAction->setStatusTip( tr("Save file"));
    quitAction->setStatusTip( tr("Quit file"));

    // Adition of actions to menus
    openMenu->addAction(openAction);
    saveMenu->addAction(saveAction);
    quitMenu->addAction(quitAction);

    penMenu->addAction(set_pen_width_larger);
    penMenu->addAction(set_pen_width_shorter);
    penMenu->addAction(undo);

    colorMenu->addAction(set_pen_color);
    colorMenu->addActions(action_group_color->actions());

    styleMenu->addAction(set_pen_style);
    styleMenu->addActions(action_group_style->actions());

    formMenu->addAction(set_figure_form);
    formMenu->addActions(action_group_form->actions());

    // Adition of principal actions to toolbar
    toolbar->addAction(openAction);
    toolbar->addAction(saveAction);
    toolbar->addAction(quitAction);
    toolbar->addAction(paintAction);
    toolbar->addAction(editAction);
    toolbar->addAction(moveAction);

    // Set some parameters to the sliders
    slider_color->setTickPosition(QSlider::TicksBothSides);
    slider_color->setMinimum(0);
    slider_color->setMaximum(17);
    slider_color->setSingleStep(1);

    slider_style->setTickPosition(QSlider::TicksBothSides);
    slider_style->setMinimum(0);
    slider_style->setMaximum(5);
    slider_style->setSingleStep(1);

    // Link actions and signals to slots
    connect(openAction, SIGNAL(triggered( )), this, SLOT(openFile()));
    connect(saveAction, SIGNAL(triggered( )), this, SLOT(saveFile()));
    connect(quitAction, SIGNAL(triggered( )), this, SLOT(quitApp()));

    connect(paintAction, SIGNAL(triggered( )), mydrawzone, SLOT(set_draw_mode_paint()));
    connect(editAction, SIGNAL(triggered( )), mydrawzone, SLOT(set_draw_mode_edit()));
    connect(moveAction, SIGNAL(triggered( )), mydrawzone, SLOT(set_draw_mode_move()));
    connect(set_pen_width_larger, SIGNAL(triggered( )), mydrawzone, SLOT(set_pen_width_larger()));
    connect(set_pen_width_shorter, SIGNAL(triggered( )), mydrawzone, SLOT(set_pen_width_shorter()));
    connect(undo, SIGNAL(triggered( )), mydrawzone, SLOT(undo()));

    connect(set_pen_color, SIGNAL(triggered( )), mydrawzone, SLOT(set_pen_color()));
    connect(action_group_color, SIGNAL(triggered(QAction *)), this, SLOT(doIt(QAction *)));
    connect(this, SIGNAL(color_pen_changed(int)), mydrawzone, SLOT(set_pen_color(int)));

    connect(set_pen_style, SIGNAL(triggered( )), mydrawzone, SLOT(set_pen_style()));
    connect(action_group_style, SIGNAL(triggered(QAction *)), this, SLOT(doIt2(QAction *)));
    connect(this, SIGNAL(style_pen_changed(int)), mydrawzone, SLOT(set_pen_style(int)));

    connect(set_figure_form, SIGNAL(triggered( )), mydrawzone, SLOT(set_figure_form()));
    connect(action_group_form, SIGNAL(triggered(QAction *)), this, SLOT(doIt3(QAction *)));
    connect(this, SIGNAL(form_painter_changed(int)), mydrawzone, SLOT(set_figure_form(int)));

    connect(slider_color, SIGNAL(valueChanged(int)), this, SLOT(slide_color_pen_changed(int)));
    connect(slider_style, SIGNAL(valueChanged(int)), this, SLOT(slide_style_pen_changed(int)));
}