示例#1
0
void terminal_initialize()
{
	terminal_row = 0;
	terminal_column = 0;
	terminal_color = make_color(COLOR_LIGHT_GREEN, COLOR_BLACK);
	terminal_buffer = (uint16_t*) 0xB8000;
	for ( size_t y = 0; y < VGA_HEIGHT; y++ )
		for ( size_t x = 0; x < VGA_WIDTH; x++ )
		{
			const size_t index = y * VGA_WIDTH + x;
			terminal_buffer[index] = make_vgaentry(' ', terminal_color);
		}
}
示例#2
0
void
LeafView::Draw(BRect updateRect)
{
	float scale = Bounds().Width() / kLeafWidth;
	BAffineTransform transform;
	transform.ScaleBy(scale);

	// BGradientRadial gradient(BPoint(kLeafWidth * 0.75, kLeafHeight * 1.5),
	//	kLeafWidth * 2);
	BGradientLinear gradient(B_ORIGIN,
		transform.Apply(BPoint(kLeafWidth, kLeafHeight)));
	rgb_color lightBlue = make_color(6, 169, 255);
	rgb_color darkBlue = make_color(0, 50, 126);
	gradient.AddColor(darkBlue, 0.0);
	gradient.AddColor(lightBlue, 255.0);

	// build leaf shape
	BShape leafShape;
	leafShape.MoveTo(transform.Apply(kLeafBegin));
	for (int i = 0; i < kNumLeafCurves; ++i) {
		BPoint controlPoints[3];
		for (int j = 0; j < 3; ++j)
			controlPoints[j] = transform.Apply(kLeafCurves[i][j]);
		leafShape.BezierTo(controlPoints);
	}
	leafShape.Close();

	PushState();
	SetDrawingMode(B_OP_ALPHA);
	SetHighColor(0, 0, 0, 50);
	for (int i = 2; i >= 0; --i) {
		SetOrigin(i * 0.1, i * 0.3);
		SetPenSize(i * 2);
		StrokeShape(&leafShape);
	}
	PopState();

	FillShape(&leafShape, gradient);
}
static SkColorFilter* make_color_filter() {
    SkColorFilter* colorFilter;
    switch (R(6)) {
        case 0: {
            SkScalar array[20];
            for (int i = 0; i < 20; ++i) {
                array[i] = make_scalar();
            }
            colorFilter = SkColorMatrixFilter::Create(array);
            break;
        }
        case 1:
            colorFilter = SkLumaColorFilter::Create();
            break;
        case 2: {
            uint8_t tableA[256];
            uint8_t tableR[256];
            uint8_t tableG[256];
            uint8_t tableB[256];
            rand_color_table(tableA);
            rand_color_table(tableR);
            rand_color_table(tableG);
            rand_color_table(tableB);
            colorFilter = SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
            break;
        }
        case 3:
            colorFilter = SkColorFilter::CreateModeFilter(make_color(), make_xfermode());
            break;
        case 4:
            colorFilter = SkColorMatrixFilter::CreateLightingFilter(make_color(), make_color());
            break;
        case 5:
        default:
            colorFilter = nullptr;
            break;
    }
    return colorFilter;
}
示例#4
0
static SkColor make_fill() {
#if 0
  int sel;

  if (quick == true) sel = 0; else sel = R(6);

  switch (sel) {

    case 0:
    case 1:
    case 2:
      return make_color();
      break;

    case 3:
      var r = ctx.createLinearGradient(make_number(),make_number(),make_number(),make_number());
      for (i=0;i<4;i++)
        r.addColorStop(make_number(),make_color());
      return r;
      break;

    case 4:
      var r = ctx.createRadialGradient(make_number(),make_number(),make_number(),make_number(),make_number(),make_number());
      for (i=0;i<4;i++)
        r.addColorStop(make_number(),make_color());
      return r;
      break;

    case 5:
      var r = ctx.createPattern(imgObj,"repeat");
      if (R(6) == 0)
        r.addColorStop(make_number(),make_color());
      return r;
      break;
  }
#else
    return make_color();
#endif
}
示例#5
0
void
ColorGradientView::Draw(BRect updateRect)
{
	BRect rect(Bounds());

	BGradientLinear gradient(rect.LeftTop(), rect.RightBottom());
	rgb_color white = make_color(255, 255, 255);
	gradient.AddColor(white, 0.0);
	gradient.AddColor(fColor, 255.0);

	FillRect(rect, gradient);
	StrokeRect(rect);
}
示例#6
0
static sk_sp<SkColorFilter> make_color_filter() {
    uint8_t s;
    fuzz->nextRange(&s, 0, 5);
    switch (s) {
        case 0: {
            SkScalar array[20];
            fuzz->nextN(array, 20);
            return SkColorFilter::MakeMatrixFilterRowMajor255(array);
        }
        case 1:
            return SkLumaColorFilter::Make();
        case 2: {
            uint8_t tableA[256];
            uint8_t tableR[256];
            uint8_t tableG[256];
            uint8_t tableB[256];
            fuzz->nextN(tableA, 256);
            fuzz->nextN(tableR, 256);
            fuzz->nextN(tableG, 256);
            fuzz->nextN(tableB, 256);
            return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
        }
        case 3: {
            SkColor c = make_color();
            SkBlendMode mode = make_blendmode();
            return SkColorFilter::MakeModeFilter(c, mode);
        }
        case 4: {
            SkColor a = make_color();
            SkColor b = make_color();
            return SkColorMatrixFilter::MakeLightingFilter(a, b);
        }
        case 5:
        default:
            break;
    }
    return nullptr;
}
示例#7
0
文件: texredefine.c 项目: RAOF/piglit
/** Render the given texture level into the given cell and verify the resulting color*/
static int cell(int cellnr, int lvl, GLuint basew, GLuint baseh, int colornr,
	const char* testnamefmt, ...)
{
	float color[4];
	float *readback;
	float tcx = (float)CellSize / basew * (1 << lvl);
	float tcy = (float)CellSize / baseh * (1 << lvl);
	int cellx, celly;
	int x, y;

	make_color(colornr, color);
	cell_coords(cellnr, &cellx, &celly);

	glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2f(cellx, celly);
		glTexCoord2f(tcx, 0);
		glVertex2f(cellx+CellSize, celly);
		glTexCoord2f(tcx, tcy);
		glVertex2f(cellx+CellSize, celly+CellSize);
		glTexCoord2f(0, tcy);
		glVertex2f(cellx, celly+CellSize);
	glEnd();

	readback = (float*)malloc(CellSize*CellSize*4*sizeof(float));
	glReadPixels(cellx, celly, CellSize, CellSize, GL_RGBA, GL_FLOAT, readback);
	for(y = 0; y < CellSize; ++y) {
		for(x = 0; x < CellSize; ++x) {
			float *read = readback + 4*(y*CellSize + x);
			float eps = 0.01;
			if (fabs(read[0] - color[0]) > eps ||
			    fabs(read[1] - color[1]) > eps ||
			    fabs(read[2] - color[2]) > eps ||
			    fabs(read[3] - color[3]) > eps) {
				va_list args;
				va_start(args, testnamefmt);
				fprintf(stderr, "Test #%i failed: ", cellnr+1);
				vfprintf(stderr, testnamefmt, args);
				fprintf(stderr, "\n  First failing pixel %i,%i in cell at %d,%d\n", x, y, cellx, celly);
				fprintf(stderr, "  Expected: %f %f %f %f\n", color[0], color[1], color[2], color[3]);
				fprintf(stderr, "  Readback: %f %f %f %f\n", read[0], read[1], read[2], read[3]);
				va_end(args);
				free(readback);
				return 0;
			}
		}
	}
	free(readback);
	return 1;
}
示例#8
0
static SkPaint make_paint() {
    SkPaint paint;
    paint.setHinting(make_paint_hinting());
    paint.setAntiAlias(make_bool());
    paint.setDither(make_bool());
    paint.setLinearText(make_bool());
    paint.setSubpixelText(make_bool());
    paint.setLCDRenderText(make_bool());
    paint.setEmbeddedBitmapText(make_bool());
    paint.setAutohinted(make_bool());
    paint.setVerticalText(make_bool());
    paint.setUnderlineText(make_bool());
    paint.setStrikeThruText(make_bool());
    paint.setFakeBoldText(make_bool());
    paint.setDevKernText(make_bool());
    paint.setFilterQuality(make_filter_quality());
    paint.setStyle(make_paint_style());
    paint.setColor(make_color());
    paint.setStrokeWidth(make_scalar());
    paint.setStrokeMiter(make_scalar());
    paint.setStrokeCap(make_paint_cap());
    paint.setStrokeJoin(make_paint_join());
    paint.setColorFilter(make_color_filter());
    paint.setXfermodeMode(make_xfermode());
    paint.setPathEffect(make_path_effect());
    paint.setMaskFilter(make_mask_filter());

    if (false) {
        // our validating buffer does not support typefaces yet, so skip this for now
        SkAutoTUnref<SkTypeface> typeface(
                      SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style()));
        paint.setTypeface(typeface);
    }

    SkLayerRasterizer::Builder rasterizerBuilder;
    SkPaint paintForRasterizer;
    if (R(2) == 1) {
        paintForRasterizer = make_paint();
    }
    rasterizerBuilder.addLayer(paintForRasterizer);
    paint.setRasterizer(rasterizerBuilder.detach());
    paint.setImageFilter(make_image_filter());
    sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
    paint.setTextAlign(make_paint_align());
    paint.setTextSize(make_scalar());
    paint.setTextScaleX(make_scalar());
    paint.setTextSkewX(make_scalar());
    paint.setTextEncoding(make_paint_text_encoding());
    return paint;
}
示例#9
0
void terminal_get_char(uint8_t ch) {
    console_color = make_color(COLOR_LIGHT_GREY, COLOR_BLACK);

    if (ch == 0x08) { // backspace \b
        if (terminal_buf_count > 0) {
            terminal_buf_count--;
            terminal_buffer[terminal_buf_count] = ' ';

            console_putchar(' ');
            console_column--;

            console_column--;

            console_putchar(CURSOR); // input cursor
            console_column--;

        }

    }
//    else if (ch == 0x0A) { // line feed \n
//
//        // TODO: push content to user process waiting for input
//    }
    else { // normal char
        if (terminal_buf_count < MAX_BUFF) {
            terminal_buffer[terminal_buf_count] = ch;
            terminal_buf_count++;

            //judge whether or not to local_echo user input
            if (user_input == 1) {
                if (ch == '\n') {
                    console_putchar(' ');
                }

                console_putchar(ch);

                console_putchar(CURSOR); // input cursor ¦
                console_column--;

            }
            //dprintf("char is %c, buffer count is %d\n", ch, terminal_buf_count);
        } else {
            printf("Terminal buffer is full!! And will be cleared !\n");
            memset(terminal_buffer, 0, MAX_BUFF);
            terminal_buf_count = 0;
            // __asm__ __volatile("hlt");
        }
    }
    //terminal_local_echo();
}
示例#10
0
void
APRView::Revert()
{
	_SetUIColors(fPrevColors);
	_UpdatePreviews(fPrevColors);

	rgb_color color = fPrevColors.GetColor(ui_color_name(fWhich),
		make_color(255, 0, 255));
	fPicker->SetValue(color);
	fColorPreview->SetColor(color);
	fColorPreview->Invalidate();

	Window()->PostMessage(kMsgUpdate);
}
示例#11
0
文件: tty.c 项目: rtpg/junkcode
void terminal_initialize(void)
{
	terminal_row = 0;
	terminal_column = 0;
	terminal_color = make_color(COLOR_LIGHT_GREY, COLOR_BLACK);
	terminal_buffer = VGA_MEMORY;
	for ( size_t y = 0; y < VGA_HEIGHT; y++ )
	{
		for ( size_t x = 0; x < VGA_WIDTH; x++ )
		{
			const size_t index = y * VGA_WIDTH + x;
			terminal_buffer[index] = make_vgaentry(' ', terminal_color);
		}
	}
}
示例#12
0
文件: vga.c 项目: dzeban/os
void terminal_initialize()
{
	uint16_t vga_entry;

    terminal_row = 0;
    terminal_column = 0;
	move_csr();

    terminal_color = make_color(COLOR_WHITE, COLOR_BLACK);
    terminal_buffer = (uint16_t *) VGA_BUFFER;

	vga_entry = make_vgaentry(FILLCHAR, terminal_color);
	memset16(terminal_buffer, vga_entry, VGA_WIDTH * VGA_HEIGHT);

    VGA_BUFFER_SIZE = VGA_WIDTH * VGA_HEIGHT;
}
示例#13
0
void
APRView::_UpdatePreviews(const BMessage& colors)
{
	rgb_color color;
	for (int32 i = color_description_count() - 1; i >= 0; i--) {
		ColorWhichItem* item = static_cast<ColorWhichItem*>(fAttrList->ItemAt(i));
		if (item == NULL)
			continue;

		color = colors.GetColor(ui_color_name(get_color_description(i)->which),
			make_color(255, 0, 255));

		item->SetColor(color);
		fAttrList->InvalidateItem(i);
	}
}
示例#14
0
void
APRView::SetDefaults()
{
	_SetUIColors(fDefaultColors);
	_UpdatePreviews(fDefaultColors);

	// Use a default color that stands out to show errors clearly
	rgb_color color = fDefaultColors.GetColor(ui_color_name(fWhich),
		make_color(255, 0, 255));

	fPicker->SetValue(color);
	fColorPreview->SetColor(color);
	fColorPreview->Invalidate();

	Window()->PostMessage(kMsgUpdate);
}
示例#15
0
文件: texredefine.c 项目: RAOF/piglit
/** Load a texture image with a constant color generated by \ref make_color */
static void teximage2d(GLuint lvl, GLuint w, GLuint h, int colornum)
{
	float color[4];
	float* tex;
	int i;

	make_color(colornum, color);
	tex = (float*)malloc(w*h*4*sizeof(float));
	for(i = 0; i < w*h; ++i) {
		tex[4*i] = color[0];
		tex[4*i + 1] = color[1];
		tex[4*i + 2] = color[2];
		tex[4*i + 3] = color[3];
	}
	glTexImage2D(GL_TEXTURE_2D, lvl, GL_RGBA, w, h, 0, GL_RGBA, GL_FLOAT, tex);
	free(tex);
}
示例#16
0
文件: printf_loop.c 项目: HARM67/Fdf
int			printf_loop(const char *fmt, char **str, va_list *list)
{
	int		l;

	l = 0;
	while (*fmt != 0)
	{
		if (*fmt == '%' && *(fmt + 1) != '%')
			recup_arg(&fmt, list, str, &l);
		else if (*fmt == '%' && *(fmt + 1) == '%')
			print_pourcent(&fmt, str, &l);
		else if (*fmt == '{')
			make_color(&fmt, str, &l);
		else
			print_character(&fmt, str, &l);
	}
	return (l);
}
示例#17
0
文件: kernel.c 项目: luk2010/APrOS
void kernel_main()
{
	terminal_cls(COLOR_LIGHT_BLUE);
	terminal_setcolor(make_color(COLOR_WHITE, COLOR_LIGHT_BLUE));
	/* Since there is no support for newlines in terminal_putchar yet, \n will
	   produce some VGA specific character instead. This is normal. */
	terminal_writestring("Hello, kernel World!\n");

	terminal_printf("This is the base string terminal system !\n");

	if(apros_setup_gdt() > 0)
		terminal_printf("GDT correctly setted !\n");
	if(apros_setup_idt())
		terminal_printf("IDT correctly setted ! \n");

	for(;;)
		continue;
}
示例#18
0
void clear_vga_textmode(void)
{
    term_zero();
    for(unsigned i = 0; i < video_driver_width; i++)
    {
        for(unsigned j = 0; j < video_driver_height; j++)
        {
            const size_t index = (vga_driver.video_row * 80 + vga_driver.video_column);
            uint16_t* VideoMemory = (uint16_t*) 0xB8000;
            uint8_t terminal_color = make_color(vga_driver.fg, vga_driver.bg);

            VideoMemory[index] = (VideoMemory[index] & 0xFF00) | (char) 0;
            VideoMemory[index + 1] = make_vgaentry(' ', terminal_color);

            vga_driver.video_column++;
        }
    }
    term_zero();
}
status_t
SoundplayThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage uisettings;
	status_t err;
	rgb_color panelcol;
	int32 wincnt = 1;
	
	err = theme.FindMessage(Z_THEME_UI_SETTINGS, &uisettings);
	if (err)
		return err;
	
	if (FindRGBColor(uisettings, B_UI_PANEL_BACKGROUND_COLOR, 0, &panelcol) < B_OK)
		panelcol = make_color(216,216,216,255);
	
	if (flags & UI_THEME_SETTINGS_SAVE && AddonFlags() & Z_THEME_ADDON_DO_SAVE) {
		// WRITEME
	}

	if (flags & UI_THEME_SETTINGS_APPLY && AddonFlags() & Z_THEME_ADDON_DO_APPLY) {
		BMessenger msgr(kSoundPlaySig);
		BMessage command(B_COUNT_PROPERTIES);
		BMessage answer;
		command.AddSpecifier("Window");
		err = msgr.SendMessage(&command, &answer,2000000LL,2000000LL);
		if(B_OK == err) {
			if (answer.FindInt32("result", &wincnt) != B_OK)
				wincnt = 1;
		}
		BMessage msg(B_PASTE);
		AddRGBColor(msg, "RGBColor", panelcol);
		msg.AddPoint("_drop_point_", BPoint(0,0));
		// send to every window (the Playlist window needs it too)
		for (int32 i = 0; i < wincnt; i++) {
			BMessage wmsg(msg);
			wmsg.AddSpecifier("Window", i);
			msgr.SendMessage(&wmsg, (BHandler *)NULL, 2000000LL);
		}
	}
	
	return B_OK;
}
示例#20
0
status_t
TerminalThemesAddon::ApplyDefaultTheme(uint32 flags)
{
	BMessage theme;
	BMessage termpref;
	// XXX: add font and stuff...
	AddRGBColor(termpref, "term:c:bg",make_color(255,255,255,0));
	AddRGBColor(termpref, "term:c:fg",make_color(0,0,0,0));
	AddRGBColor(termpref, "term:c:curbg",make_color(0,0,0,0));
	AddRGBColor(termpref, "term:c:curfg",make_color(255,255,255,0));
	AddRGBColor(termpref, "term:c:selbg",make_color(0,0,0,0));
	AddRGBColor(termpref, "term:c:selfg",make_color(255,255,255,0));
	theme.AddMessage(Z_THEME_TERMINAL_SETTINGS, &termpref);
	return ApplyTheme(theme, flags);
}
示例#21
0
void init_terminal(void) {
    terminal_row = 0;
    terminal_column = 0;
    terminal_color = make_color(COLOR_WHITE, COLOR_BLUE);

    //setup display
    screen = VGA_MEMORY;

    //setup terminal character buffer    
    for (size_t y = 0; y < VGA_HEIGHT; y++) {
        for (size_t x = 0; x < VGA_WIDTH; x++) {
            size_t index = buffer_index(x, y);
            //create initial terminal character
            buffer[index].t = ' ';
            buffer[index].colour = terminal_color;
        }
    }

    //flush
    terminal_flush();
}
示例#22
0
int write_image( const Image& image, const char *filename )
{
    if(std::string(filename).rfind(".png") == std::string::npos && std::string(filename).rfind(".PNG") == std::string::npos )
    {
        printf("writing color image '%s'... failed, not a PNG image.\n", filename);
        return -1;
    }
    
    // flip de l'image : Y inverse entre GL et BMP
    Image flip= create_image(image.width, image.height, 4, make_color(0, 0, 0));
    for(int y= 0; y < image.height; y++)
    for(int x= 0; x < image.width; x++)
        image_set_pixel(flip, x, image.height - y -1, image_pixel(image, x, y));

    SDL_Surface *bmp= SDL_CreateRGBSurfaceFrom((void *) &flip.data.front(),
        image.width, image.height,
        32, image.width * 4,
#if 0
        0xFF000000,
        0x00FF0000,
        0x0000FF00,
        0x000000FF
#else
        0x000000FF,
        0x0000FF00,
        0x00FF0000,
        0xFF000000
#endif
    );

    int code= IMG_SavePNG(bmp, filename);
    SDL_FreeSurface(bmp);
    release_image(flip);
    
    if(code < 0)
        printf("writing color image '%s'... failed\n%s\n", filename, SDL_GetError());
    else
        printf("writing color image '%s'...\n", filename);
    return code;
}
static SkPaint make_paint() {
    SkPaint paint;
    paint.setHinting(make_paint_hinting());
    paint.setAntiAlias(make_bool());
    paint.setDither(make_bool());
    paint.setLinearText(make_bool());
    paint.setSubpixelText(make_bool());
    paint.setLCDRenderText(make_bool());
    paint.setEmbeddedBitmapText(make_bool());
    paint.setAutohinted(make_bool());
    paint.setVerticalText(make_bool());
    paint.setFakeBoldText(make_bool());
    paint.setDevKernText(make_bool());
    paint.setFilterQuality(make_filter_quality());
    paint.setStyle(make_paint_style());
    paint.setColor(make_color());
    paint.setStrokeWidth(make_scalar());
    paint.setStrokeMiter(make_scalar());
    paint.setStrokeCap(make_paint_cap());
    paint.setStrokeJoin(make_paint_join());
    paint.setColorFilter(make_color_filter());
    paint.setBlendMode(make_xfermode());
    paint.setPathEffect(make_path_effect());
    paint.setMaskFilter(make_mask_filter());

    if (false) {
        // our validating buffer does not support typefaces yet, so skip this for now
        paint.setTypeface(SkTypeface::MakeFromName(make_font_name().c_str(),
                                                   make_typeface_style()));
    }

    paint.setImageFilter(make_image_filter());
    sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
    paint.setTextAlign(make_paint_align());
    paint.setTextSize(make_scalar());
    paint.setTextScaleX(make_scalar());
    paint.setTextSkewX(make_scalar());
    paint.setTextEncoding(make_paint_text_encoding());
    return paint;
}
示例#24
0
bool is_in_range(guint8 * pixel, color l, color h, COLOR_SPACE space) {
    color c = make_color(pixel[0], pixel[1], pixel[2]);
    switch (space) {
    case COLOR_SPACE::HSL:
        c = RGB2HSL(c);
        break;
    case COLOR_SPACE::HSI:
        c = RGB2HSI(c);
        break;
    case COLOR_SPACE::HSV:
        c = RGB2HSV(c);
        break;
    case COLOR_SPACE::RGB:
        //we're good
        break;
    default:
        //invalid - throw exception?
        return false;
    };
    return
    (
        ( //hue
            ((l[0] < h[0]) && ( //low < high
                (c[0] >= l[0]) && (c[0] <= h[0])
            ))
            ||
            ((l[0] >= h[0]) && ( //low > high
                (c[0] >= l[0]) || (c[0] <= h[0])
            ))
        )
        &&
        ( //saturation
            (c[1] >= l[1]) && (c[1] <= h[1])
        )
        &&
        ( //value
            (c[2] >= l[2]) && (c[2] <= h[2])
        )
    );
}
示例#25
0
int main() {
    printf("Color values for magenta: \n");
    printf("Red: %d\n", magenta.red);
    printf("Green: %d\n", magenta.green);
    printf("Blue: %d\n", magenta.blue);
    
    struct color color2;
    printf("Please enter color values: \n");
    scanf("%d%d%d", &color2.red, &color2.green, &color2.blue);
    
    printf("Red: %d\n", color2.red);
    printf("Green: %d\n", color2.green);
    printf("Blue: %d\n", color2.blue);
    
    printf("Next color:\n");
    struct color color3;
    color3 = make_color(256,-1,275);
    printf("%d, %d, %d\n", color3.red, color3.green, color3.blue);
    
    
    return 0;
}
示例#26
0
    inline Color convertFromRGB(const Color& color) const
    {
        const float cmax = color_max(color);
        const float cmin = color_min(color);
        const float chroma = cmax - cmin;

        float hue = 0.0f;
        if (chroma == 0.0f)
            hue = 0.0f;
        else if (cmax == color_r(color))
            hue = (color_g(color) - color_b(color)) / chroma;
        else if (cmax == color_g(color))
            hue = (color_b(color) - color_r(color)) / chroma + 2.0f;
        else
            hue = (color_r(color) - color_g(color)) / chroma + 4.0f;

        hue *= 1.0f / 6.0f;
        if (hue < 0.0f)
            hue += 1.0f;

        const float lightness = (cmax + cmin) * 0.5f;
        const float saturation = chroma == 0.0f ? 0.0f : chroma / (1.0f - fabsf(2.0f * lightness - 1.0f));
        return make_color(hue, saturation, lightness);
    }
示例#27
0
void
ToolBar::SetFontSize(int const& fontSize)
{
	fFontSize = fontSize;
	
	BFont font;
    GetFont(&font);
    font.SetSize(fFontSize);
    font.SetFlags(Flags() | B_FORCE_ANTIALIASING);
    font.SetFace(B_CONDENSED_FACE /*| B_BOLD_FACE*/);
    SetFont(&font);
    GetFontHeight(&fFontHeight);

    fMargin.Set(5, 3, 5, 0);
    fButtonMargin.Set(5, 0, 5, 2);

    float height = ceilf(fFontHeight.ascent + 2 * fFontHeight.descent +
        fMargin.top + fMargin.bottom + fButtonMargin.top + fButtonMargin.bottom);

    fIconWidth = height - fMargin.top - fMargin.bottom - fButtonMargin.top -
        fButtonMargin.bottom - fFontHeight.descent - 2;

    SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, height));
    SetExplicitMinSize(BSize(0, height));

    fGradient.SetStart(0, 0);
    fGradient.SetEnd(0, height);
    fGradient.AddColor(make_color(230, 230, 255, 255), 0);
    fGradient.AddColor(make_color(180, 180, 255, 255), 255);

    fGradientHighlight.SetStart(0, 0);
    fGradientHighlight.SetEnd(0, height);
    fGradientHighlight.AddColor(make_color(210, 210, 255, 255), 0);
    fGradientHighlight.AddColor(make_color(150, 150, 255, 255), 255);

    fGradientPressed.SetStart(0, 0);
    fGradientPressed.SetEnd(0, height);
    fGradientPressed.AddColor(make_color(180, 180, 255, 255), 0);
    fGradientPressed.AddColor(make_color(130, 130, 255, 255), 255);

    Invalidate();
}
示例#28
0
Color::operator rgb_color() const
{
    return make_color(red(), green(), blue(), alpha());
}
示例#29
0
void
MemoryView::Draw(BRect rect)
{
	rect = Bounds();

	float divider = (fTargetAddressSize + 1) * fCharWidth;
	StrokeLine(BPoint(divider, rect.top),
				BPoint(divider, rect.bottom));

	if (fTargetBlock == NULL)
		return;

	uint32 hexBlockSize = _GetHexDigitsPerBlock() + 1;
	uint32 blockByteSize = hexBlockSize / 2;
	if (fHexMode != HexModeNone && fTextMode != TextModeNone) {
		divider += (fHexBlocksPerLine * hexBlockSize + 1) * fCharWidth;
		StrokeLine(BPoint(divider, rect.top),
					BPoint(divider, rect.bottom));
	}

	char buffer[32];
	char textbuffer[512];

	int32 startLine = int32(rect.top / fLineHeight);
	const char* currentAddress = (const char*)(fTargetBlock->Data()
		+ fHexBlocksPerLine * blockByteSize * startLine);
	const char* maxAddress = (const char*)(fTargetBlock->Data()
		+ fTargetBlock->Size());
	const char* targetAddress = (const char *)fTargetBlock->Data()
		+ fTargetAddress - fTargetBlock->BaseAddress();
	BPoint drawPoint(1.0, (startLine + 1) * fLineHeight);
	int32 currentBlocksPerLine = fHexBlocksPerLine;
	int32 currentCharsPerLine = fTextCharsPerLine;
	rgb_color addressColor = tint_color(HighColor(), B_LIGHTEN_1_TINT);
	rgb_color dataColor = HighColor();
	font_height fh;
	GetFontHeight(&fh);
	target_addr_t lineAddress = fTargetBlock->BaseAddress() + startLine
		* currentCharsPerLine;
	for (; currentAddress < maxAddress && drawPoint.y < rect.bottom
		+ fLineHeight; drawPoint.y += fLineHeight) {
		drawPoint.x = 1.0;
		snprintf(buffer, sizeof(buffer), "%0*" B_PRIx64,
			(int)fTargetAddressSize, lineAddress);
		PushState();
		SetHighColor(tint_color(HighColor(), B_LIGHTEN_1_TINT));
		DrawString(buffer, drawPoint);
		drawPoint.x += fCharWidth * (fTargetAddressSize + 2);
		PopState();
		if (fHexMode != HexModeNone) {
			if (currentAddress + (currentBlocksPerLine * blockByteSize)
				> maxAddress) {
				currentCharsPerLine = maxAddress - currentAddress;
				currentBlocksPerLine = currentCharsPerLine
					/ blockByteSize;
			}

			for (int32 j = 0; j < currentBlocksPerLine; j++) {
				const char* blockAddress = currentAddress + (j
					* blockByteSize);
				_GetNextHexBlock(buffer, sizeof(buffer), blockAddress);
				if (targetAddress >= blockAddress && targetAddress <
						blockAddress + blockByteSize) {
					PushState();
					SetHighColor(make_color(216,0,0));
					DrawString(buffer, drawPoint);
					PopState();
				} else
					DrawString(buffer, drawPoint);

				drawPoint.x += fCharWidth * hexBlockSize;
			}

			if (currentBlocksPerLine < fHexBlocksPerLine)
				drawPoint.x += fCharWidth * hexBlockSize
					* (fHexBlocksPerLine - currentBlocksPerLine);
		}

		if (fTextMode != TextModeNone) {
			drawPoint.x += fCharWidth;
			for (int32 j = 0; j < currentCharsPerLine; j++) {
				// filter non-printable characters
				textbuffer[j] = currentAddress[j] > 32 ? currentAddress[j]
					: '.';
			}
			textbuffer[fTextCharsPerLine] = '\0';
			DrawString(textbuffer, drawPoint);
			if (targetAddress >= currentAddress && targetAddress
				< currentAddress + currentCharsPerLine) {
				PushState();
				SetHighColor(B_TRANSPARENT_COLOR);
				SetDrawingMode(B_OP_INVERT);
				uint32 blockAddress = uint32(targetAddress - currentAddress);
				if (fHexMode != HexModeNone)
					blockAddress &= ~(blockByteSize - 1);
				float startX = drawPoint.x + fCharWidth * blockAddress;
				float endX = startX;
				if (fHexMode != HexModeNone)
					endX += fCharWidth * ((hexBlockSize - 1) / 2);
				else
					endX += fCharWidth;
				FillRect(BRect(startX, drawPoint.y - fh.ascent, endX,
					drawPoint.y + fh.descent));
				PopState();
			}
		}
		if (currentBlocksPerLine > 0) {
			currentAddress += currentBlocksPerLine * blockByteSize;
			lineAddress += currentBlocksPerLine * blockByteSize;
		} else {
			currentAddress += fTextCharsPerLine;
			lineAddress += fTextCharsPerLine;
		}
	}

	if (fSelectionStart != fSelectionEnd) {
		PushState();
		BRegion selectionRegion;
		_GetSelectionRegion(selectionRegion);
		SetDrawingMode(B_OP_INVERT);
		FillRegion(&selectionRegion, B_SOLID_HIGH);
		PopState();
	}
}
示例#30
0
// See the License for the specific language governing permissions and
// limitations under the License.

#include <kernel/vga.hpp>
#include <cstring>
#include <x86intrin.h>
#include <memstream>

static inline uint16_t
make_vgaentry(const char c, const uint8_t color) noexcept {
  uint16_t c16     = c;
  uint16_t color16 = color;
  return c16 | color16 << 8;
}
const uint16_t ConsoleVGA::DEFAULT_ENTRY = 
    make_vgaentry(32, make_color(COLOR_LIGHT_GREY, COLOR_BLACK));

ConsoleVGA::ConsoleVGA() noexcept:
row{0}, column{0}
{
  this->color  = make_color(COLOR_WHITE, COLOR_BLACK);
  this->buffer = reinterpret_cast<uint16_t*>(0xB8000);
  clear();
}

uint16_t ConsoleVGA::get(uint8_t x, uint8_t y)
{
  const size_t index = y * VGA_WIDTH + x;
  return this->buffer[index];
}