コード例 #1
0
ファイル: DiskProbe.cpp プロジェクト: looncraz/haiku
Settings::Settings()
	:
	fMessage(kMsgDiskProbeSettings),
	fUpdated(false)
{
	float fontSize = be_plain_font->Size();
	int32 windowWidth = DataView::WidthForFontSize(fontSize) + 20;
		// TODO: make scrollbar width variable

	BScreen screen;
	fMessage.AddRect("window_frame", BLayoutUtils::AlignInFrame(screen.Frame(),
		BSize(windowWidth, windowWidth),
		BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)));
	fMessage.AddInt32("base_type", kHexBase);
	fMessage.AddFloat("font_size", fontSize);
	fMessage.AddBool("case_sensitive", true);
	fMessage.AddInt8("find_mode", kAsciiMode);

	BFile file;
	if (Open(&file, B_READ_ONLY) != B_OK)
		return;

	// TODO: load/save settings as flattened BMessage - but not yet,
	//		since that will break compatibility with R5's DiskProbe

	disk_probe_settings settings;
	if (file.Read(&settings, sizeof(settings)) == sizeof(settings)) {
#if B_HOST_IS_BENDIAN
		// settings are saved in little endian
		settings.window_frame.left = B_LENDIAN_TO_HOST_FLOAT(
			settings.window_frame.left);
		settings.window_frame.top = B_LENDIAN_TO_HOST_FLOAT(
			settings.window_frame.top);
		settings.window_frame.right = B_LENDIAN_TO_HOST_FLOAT(
			settings.window_frame.right);
		settings.window_frame.bottom = B_LENDIAN_TO_HOST_FLOAT(
			settings.window_frame.bottom);
#endif
		// check if the window frame is on screen at all
		BScreen screen;
		if (screen.Frame().Contains(settings.window_frame.LeftTop())
			&& settings.window_frame.Width() < screen.Frame().Width()
			&& settings.window_frame.Height() < screen.Frame().Height())
			fMessage.ReplaceRect("window_frame", settings.window_frame);

		if (settings.base_type == kHexBase
			|| settings.base_type == kDecimalBase)
			fMessage.ReplaceInt32("base_type",
				B_LENDIAN_TO_HOST_INT32(settings.base_type));
		if (settings.font_size >= 0 && settings.font_size <= 72)
			fMessage.ReplaceFloat("font_size",
				float(B_LENDIAN_TO_HOST_INT32(settings.font_size)));

		fMessage.ReplaceBool("case_sensitive",
			settings.flags & kCaseSensitive);
		fMessage.ReplaceInt8("find_mode",
			settings.flags & kHexFindMode ? kHexMode : kAsciiMode);
	}
}
コード例 #2
0
ファイル: Layer.cpp プロジェクト: puckipedia/ArtPaint
Layer*
Layer::readLayer(BFile& file, ImageView* imageView, int32 new_id,
                 bool is_little_endian, int32 compression_method)
{
    // This is the new way of reading the layers.
    int32 marker;
    if (file.Read(&marker,sizeof(int32)) != sizeof(int32))
        return NULL;

    if (is_little_endian)
        marker = B_LENDIAN_TO_HOST_INT32(marker);
    else
        marker = B_BENDIAN_TO_HOST_INT32(marker);

    if (marker != PROJECT_FILE_LAYER_START_MARKER)
        return NULL;

    int32 width;
    int32 height;
    layer_type layerType;
    int32 layer_visibility;
    int64 length;
    if (file.Read(&width,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&height,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&layerType,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&layer_visibility,sizeof(int32)) != sizeof(int32))
        return NULL;
    if (file.Read(&length,sizeof(int64)) != sizeof(int64))
        return NULL;

    if (is_little_endian) {
        width = B_LENDIAN_TO_HOST_INT32(width);
        height = B_LENDIAN_TO_HOST_INT32(height);
        layerType = layer_type(B_LENDIAN_TO_HOST_INT32(layerType));
        length = B_LENDIAN_TO_HOST_INT64(length);
    }
    else {
        width = B_BENDIAN_TO_HOST_INT32(width);
        height = B_BENDIAN_TO_HOST_INT32(height);
        layerType = layer_type(B_BENDIAN_TO_HOST_INT32(layerType));
        length = B_BENDIAN_TO_HOST_INT64(length);
    }

    Layer* layer = new Layer(BRect(0, 0, width - 1, height - 1), new_id,
                             imageView, layerType);
    layer->SetVisibility((uint32(layer_visibility) == 0xFFFFFFFF));
    int8* bits = (int8*)layer->Bitmap()->Bits();
    if (file.Read(bits,length) != length) {
        delete layer;
        return NULL;
    }

    // Read the end-marker.
    if (file.Read(&marker,sizeof(int32)) != sizeof(int32)) {
        delete layer;
        return NULL;
    }
    if (is_little_endian)
        marker = B_LENDIAN_TO_HOST_INT32(marker);
    else
        marker = B_BENDIAN_TO_HOST_INT32(marker);

    if (marker != PROJECT_FILE_LAYER_END_MARKER) {
        delete layer;
        return NULL;
    }

    // Here try to read the extra-data block.
    if (file.Read(&marker,sizeof(int32)) == sizeof(int32)) {
        if (is_little_endian)
            marker = B_LENDIAN_TO_HOST_INT32(marker);
        else
            marker = B_BENDIAN_TO_HOST_INT32(marker);

        if (marker == PROJECT_FILE_LAYER_EXTRA_DATA_START_MARKER) {
            // Read the length of this section
            int32 length;
            if (file.Read(&length,sizeof(int32)) != sizeof(int32)) {
                delete layer;
                return NULL;
            }

            if (is_little_endian)
                length = B_LENDIAN_TO_HOST_INT32(length);
            else
                length = B_BENDIAN_TO_HOST_INT32(length);

            // Read the transparency coefficient
            float coeff;
            if (file.Read(&coeff,sizeof(float)) != sizeof(float)) {
                delete layer;
                return NULL;
            }
            if (is_little_endian)
                coeff = B_LENDIAN_TO_HOST_FLOAT(coeff);
            else
                coeff = B_BENDIAN_TO_HOST_FLOAT(coeff);

            layer->SetTransparency(coeff);
            length -= sizeof(float);

            // Skip the extra data that we do not recognize.
            file.Seek(length,SEEK_CUR);

            // Here we should get the end-marker for layer's extra data
            if (file.Read(&marker,sizeof(int32)) != sizeof(int32)) {
                delete layer;
                return NULL;
            }
            if (is_little_endian)
                marker = B_LENDIAN_TO_HOST_INT32(marker);
            else
                marker = B_BENDIAN_TO_HOST_INT32(marker);

            if (marker != PROJECT_FILE_LAYER_EXTRA_DATA_END_MARKER) {
                delete layer;
                return NULL;
            }

        }
        else {
            // Somehow -sizeof(int32) does not seem to work????
            file.Seek(-4,SEEK_CUR);
        }
    }

    // Before returning calculate the layer's miniature image.
    layer->calc_mini_image();

    return layer;
}