Remove DrawingTidbits.h and .cpp as per TODO comment, replacing code that relies on it. (Please try - I don't have any CD devices wired to audio. BTW, its sometimes schizoid value changing was present before these changes.)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32357 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström 2009-08-14 14:18:14 +00:00
parent 8fb1f94f42
commit 007e852a81
6 changed files with 26 additions and 515 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Author:
@ -190,7 +190,7 @@ CDPlayer::BuildGUI()
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "prev_down"),
new BMessage(M_PREV_TRACK), 0, B_WILL_DRAW);
fPrevTrack->ResizeToPreferred();
fPrevTrack->MoveTo(fPlay->Frame().right + 20, stopTop);
fPrevTrack->MoveTo(fPlay->Frame().right + 40, stopTop);
AddChild(fPrevTrack);
fNextTrack = new DrawButton(BRect(0, 0, 1, 1), "NextTrack",
@ -206,7 +206,7 @@ CDPlayer::BuildGUI()
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "rew_down"),
new BMessage(M_REWIND), 0, B_WILL_DRAW);
fRewind->ResizeToPreferred();
fRewind->MoveTo(fNextTrack->Frame().right + 20, stopTop);
fRewind->MoveTo(fNextTrack->Frame().right + 40, stopTop);
AddChild(fRewind);
fFastFwd = new DoubleShotDrawButton(BRect(0, 0, 1, 1), "FastFwd",
@ -223,7 +223,6 @@ CDPlayer::BuildGUI()
r.bottom = r.top + kVolumeSliderBitmapHeight - 1.0;
fVolumeSlider = new VolumeSlider(r, "VolumeSlider",
0, 255, new BMessage(M_SET_VOLUME), this);
fVolumeSlider->ResizeToPreferred();
AddChild(fVolumeSlider);
fRepeat = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Repeat",
@ -662,3 +661,4 @@ main(int, char **argv)
return 0;
}

View File

@ -1,143 +0,0 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
// TODO: remove this file again.... It originates from Be Sample code,
// but was added to the VLC Media Player BeOS interface, I added some stuff
// during my work on VLC, but I am not sure anymore if this file still
// contains work done by Tony Castley, which would be GPL!
#include "DrawingTidbits.h"
#include <Bitmap.h>
#include <Debug.h>
#include <Screen.h>
#include <math.h>
#include <string.h>
// clip_float
inline uint8
clip_float(float value)
{
if (value < 0)
value = 0;
if (value > 255)
value = 255;
return (uint8)value;
}
// dim_bitmap
status_t
dim_bitmap(BBitmap* bitmap, rgb_color center, float dimLevel)
{
status_t status = B_BAD_VALUE;
if (bitmap && bitmap->IsValid())
{
switch (bitmap->ColorSpace())
{
case B_CMAP8:
{
BScreen screen(B_MAIN_SCREEN_ID);
if (screen.IsValid())
{
// iterate over each pixel, get the respective
// color from the screen object, find the distance
// to the "center" color and shorten the distance
// by "dimLevel"
int32 length = bitmap->BitsLength();
uint8* bits = (uint8*)bitmap->Bits();
for (int32 i = 0; i < length; i++)
{
// preserve transparent pixels
if (bits[i] != B_TRANSPARENT_MAGIC_CMAP8)
{
// get color for this index
rgb_color c = screen.ColorForIndex(bits[i]);
// red
float dist = (c.red - center.red) * dimLevel;
c.red = clip_float(center.red + dist);
// green
dist = (c.green - center.green) * dimLevel;
c.green = clip_float(center.green + dist);
// blue
dist = (c.blue - center.blue) * dimLevel;
c.blue = clip_float(center.blue + dist);
// write correct index of the dimmed color
// back into bitmap (and hope the match is close...)
bits[i] = screen.IndexForColor(c);
}
}
status = B_OK;
}
break;
}
case B_RGB32:
case B_RGBA32:
{
// iterate over each color component, find the distance
// to the "center" color and shorten the distance
// by "dimLevel"
uint8* bits = (uint8*)bitmap->Bits();
int32 bpr = bitmap->BytesPerRow();
int32 pixels = bitmap->Bounds().IntegerWidth() + 1;
int32 lines = bitmap->Bounds().IntegerHeight() + 1;
// iterate over color components
for (int32 y = 0; y < lines; y++) {
for (int32 x = 0; x < pixels; x++) {
int32 offset = 4 * x; // four bytes per pixel
// blue
float dist = (bits[offset + 0] - center.blue) * dimLevel;
bits[offset + 0] = clip_float(center.blue + dist);
// green
dist = (bits[offset + 1] - center.green) * dimLevel;
bits[offset + 1] = clip_float(center.green + dist);
// red
dist = (bits[offset + 2] - center.red) * dimLevel;
bits[offset + 2] = clip_float(center.red + dist);
// ignore alpha channel
}
// next line
bits += bpr;
}
status = B_OK;
break;
}
default:
status = B_ERROR;
break;
}
}
return status;
}
// dimmed_color_cmap8
rgb_color
dimmed_color_cmap8(rgb_color color, rgb_color center, float dimLevel)
{
BScreen screen(B_MAIN_SCREEN_ID);
if (screen.IsValid())
{
// red
float dist = (color.red - center.red) * dimLevel;
color.red = clip_float(center.red + dist);
// green
dist = (color.green - center.green) * dimLevel;
color.green = clip_float(center.green + dist);
// blue
dist = (color.blue - center.blue) * dimLevel;
color.blue = clip_float(center.blue + dist);
// get color index for dimmed color
int32 index = screen.IndexForColor(color);
// put color at index (closest match in palette
// to dimmed result) into returned color
color = screen.ColorForIndex(index);
}
return color;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
// TODO: remove this file again.... It originates from Be Sample code,
// but was added to the VLC Media Player BeOS interface, I added some stuff
// during my work on VLC, but I am not sure anymore if this file still
// contains work done by Tony Castley, which would be GPL!
#ifndef __DRAWING_TIBITS__
#define __DRAWING_TIBITS__
#include <GraphicsDefs.h>
class BBitmap;
const rgb_color kBlack = { 0, 0, 0, 255 };
// dims bitmap (in place) by finding the distance of
// the color at each pixel to the provided "center" color
// and shortens that distance by dimLevel
// (dimLevel < 1 -> less contrast)
// (dimLevel > 1 -> more contrast)
// (dimLevel < 0 -> inverted colors)
// currently supported colorspaces:
// B_RGB32
// B_RGBA32
// B_CMAP8
status_t dim_bitmap(BBitmap* bitmap, rgb_color center,
float dimLevel);
rgb_color dimmed_color_cmap8(rgb_color color, rgb_color center,
float dimLevel);
#endif // __DRAWING_TIBITS__

View File

@ -8,7 +8,6 @@ Application CDPlayer :
CDPlayer.cpp
DoubleShotDrawButton.cpp
DrawButton.cpp
DrawingTidbits.cpp
PlayList.cpp
TwoStateDrawButton.cpp
VolumeSlider.cpp

View File

@ -1,317 +1,37 @@
/*
* Copyright 2006, Haiku.
* Copyright 2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Stephan Aßmus, superstippi@gmx.de
* Jonas Sundström, jonas@kirilla.com
*/
// NOTE: Based on my code in the BeOS interface for the VLC media player
// that I did during the VLC 0.4.3 - 0.4.6 times. Code not done by me
// removed. -Stephan Aßmus
#include "VolumeSlider.h"
#include "ButtonBitmaps.h"
#include "DrawingTidbits.h"
#include <Bitmap.h>
#include <Screen.h>
#include <stdio.h>
#include <string.h>
// slider colors are hardcoded here, because that's just
// what they currently are within those bitmaps
const rgb_color kGreen = (rgb_color){ 152, 203, 152, 255 };
const rgb_color kGreenShadow = (rgb_color){ 102, 152, 102, 255 };
const rgb_color kBackground = (rgb_color){ 216, 216, 216, 255 };
const rgb_color kSeekGreen = (rgb_color){ 171, 221, 161, 255 };
const rgb_color kSeekGreenShadow = (rgb_color){ 144, 186, 136, 255 };
const rgb_color kSeekRed = (rgb_color){ 255, 0, 0, 255 };
const rgb_color kSeekRedLight = (rgb_color){ 255, 152, 152, 255 };
const rgb_color kSeekRedShadow = (rgb_color){ 178, 0, 0, 255 };
#define DIM_LEVEL 0.4
// constructor
VolumeSlider::VolumeSlider(BRect frame, const char* name,
int32 minValue, int32 maxValue,
BMessage* message, BHandler* target)
: BControl(frame, name, NULL, message, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fLeftSideBits(NULL),
fRightSideBits(NULL),
fKnobBits(NULL),
fTracking(false),
fMuted(false),
fMinValue(minValue),
fMaxValue(maxValue)
VolumeSlider::VolumeSlider(BRect frame, const char* name, int32 minValue,
int32 maxValue, BMessage* message, BHandler* target)
:
BSlider(frame, name, NULL, message, minValue, maxValue)
{
SetTarget(target);
// create bitmaps
BRect r(0.0, 0.0,
kVolumeSliderBitmapWidth - 1, kVolumeSliderBitmapHeight - 1);
fLeftSideBits = new BBitmap(r, B_CMAP8);
fRightSideBits = new BBitmap(r, B_CMAP8);
r.Set(0.0, 0.0,
kVolumeSliderKnobWidth - 1, kVolumeSliderKnobHeight - 1);
fKnobBits = new BBitmap(r, B_CMAP8);
_MakeBitmaps();
}
// destructor
VolumeSlider::~VolumeSlider()
{
delete fLeftSideBits;
delete fRightSideBits;
delete fKnobBits;
}
// AttachedToWindow
void
VolumeSlider::AttachedToWindow()
{
BControl::AttachedToWindow();
SetViewColor(B_TRANSPARENT_COLOR);
}
// SetValue
void
VolumeSlider::SetValue(int32 value)
{
if (value == Value())
return;
BControl::SetValue(value);
BSlider::SetValue(value);
Invoke();
}
// SetEnabled
void
VolumeSlider::SetEnabled(bool enable)
{
if (enable == IsEnabled())
return;
BControl::SetEnabled(enable);
_MakeBitmaps();
Invalidate();
}
// Draw
void
VolumeSlider::Draw(BRect updateRect)
{
if (!IsValid()) {
fprintf(stderr, "VolumeSlider::Draw() - Error: no valid bitmaps!");
SetHighColor(255, 0, 0);
FillRect(updateRect);
return;
}
BRect r(Bounds());
float sliderSideWidth = kVolumeSliderBitmapWidth;
float sliderStart = (r.left + sliderSideWidth);
float sliderEnd = (r.right - sliderSideWidth);
float knobPos = sliderStart
+ (sliderEnd - sliderStart - 1.0) * (Value() - fMinValue)
/ (fMaxValue - fMinValue);
// draw both sides (the original from Be doesn't seem
// to make a difference for enabled/disabled state)
DrawBitmapAsync(fLeftSideBits, r.LeftTop());
DrawBitmapAsync(fRightSideBits, BPoint(sliderEnd + 1.0, r.top));
// colors for the slider area between the two bitmaps
rgb_color background = kBackground;//ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
rgb_color softShadow = tint_color(background, B_DARKEN_1_TINT);
rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT);
rgb_color midShadow = tint_color(background, B_DARKEN_3_TINT);
rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
rgb_color softLight = tint_color(background, B_LIGHTEN_1_TINT);
rgb_color green = kGreen;
rgb_color greenShadow = kGreenShadow;
rgb_color black = kBlack;
rgb_color dotGrey = midShadow;
rgb_color dotGreen = greenShadow;
// make dimmed version of colors if we're disabled
if (!IsEnabled()) {
shadow = (rgb_color){ 200, 200, 200, 255 };
softShadow = dimmed_color_cmap8(softShadow, background, DIM_LEVEL);
darkShadow = dimmed_color_cmap8(darkShadow, background, DIM_LEVEL);
midShadow = shadow;
light = dimmed_color_cmap8(light, background, DIM_LEVEL);
softLight = dimmed_color_cmap8(softLight, background, DIM_LEVEL);
green = dimmed_color_cmap8(green, background, DIM_LEVEL);
greenShadow = dimmed_color_cmap8(greenShadow, background, DIM_LEVEL);
black = dimmed_color_cmap8(black, background, DIM_LEVEL);
dotGreen = dotGrey;
} else if (fMuted) {
green = tint_color(kBackground, B_DARKEN_3_TINT);
greenShadow = tint_color(kBackground, B_DARKEN_4_TINT);
dotGreen = greenShadow;
}
// draw slider edges between bitmaps
BeginLineArray(7);
AddLine(BPoint(sliderStart, r.top),
BPoint(sliderEnd, r.top), softShadow);
AddLine(BPoint(sliderStart, r.bottom),
BPoint(sliderEnd, r.bottom), softLight);
r.InsetBy(0.0, 1.0);
AddLine(BPoint(sliderStart, r.top),
BPoint(sliderEnd, r.top), black);
AddLine(BPoint(sliderStart, r.bottom),
BPoint(sliderEnd, r.bottom), light);
r.top++;
AddLine(BPoint(sliderStart, r.top),
BPoint(knobPos, r.top), greenShadow);
AddLine(BPoint(knobPos, r.top),
BPoint(sliderEnd, r.top), midShadow);
r.top++;
AddLine(BPoint(sliderStart, r.top),
BPoint(knobPos, r.top), greenShadow);
EndLineArray();
// fill rest inside of slider
r.InsetBy(0.0, 1.0);
r.left = sliderStart;
r.right = knobPos;
SetHighColor(green);
FillRect(r, B_SOLID_HIGH);
r.left = knobPos + 1.0;
r.right = sliderEnd;
r.top -= 1.0;
SetHighColor(shadow);
FillRect(r, B_SOLID_HIGH);
// draw little dots inside
int32 dotCount = (int32)((sliderEnd - sliderStart) / 5.0);
BPoint dotPos;
dotPos.y = r.top + 4.0;
for (int32 i = 0; i < dotCount; i++) {
dotPos.x = sliderStart + i * 5.0 + 4.0;
SetHighColor(dotPos.x < knobPos ? dotGreen : dotGrey);
StrokeLine(dotPos, BPoint(dotPos.x, dotPos.y + 1.0));
}
// draw knob
r.top -= 1.0;
SetDrawingMode(B_OP_OVER); // part of knob is transparent
DrawBitmapAsync(fKnobBits, BPoint(knobPos - kVolumeSliderKnobWidth / 2, r.top));
}
// MouseDown
void
VolumeSlider::MouseDown(BPoint where)
{
if (Bounds().Contains(where) && IsEnabled()) {
fTracking = true;
SetValue(_ValueFor(where.x));
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
}
}
// MouseMoved
void
VolumeSlider::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
{
if (fTracking)
SetValue(_ValueFor(where.x));
}
// MouseUp
void
VolumeSlider::MouseUp(BPoint where)
{
fTracking = false;
}
// IsValid
bool
VolumeSlider::IsValid() const
{
return (fLeftSideBits && fLeftSideBits->IsValid()
&& fRightSideBits && fRightSideBits->IsValid()
&& fKnobBits && fKnobBits->IsValid());
}
// SetMuted
void
VolumeSlider::SetMuted(bool mute)
{
if (mute == fMuted)
return;
fMuted = mute;
_MakeBitmaps();
Invalidate();
}
// _MakeBitmaps
void
VolumeSlider::_MakeBitmaps()
{
if (!IsValid())
return;
// left side of slider
memcpy(fLeftSideBits->Bits(), kVolumeSliderLeftBitmapBits,
fLeftSideBits->BitsLength());
// right side of slider
memcpy(fRightSideBits->Bits(), kVolumeSliderRightBits,
fRightSideBits->BitsLength());
// slider knob
int32 length = fKnobBits->BitsLength();
memcpy(fKnobBits->Bits(), kVolumeSliderKnobBits, length);
uint8* bits = (uint8*)fKnobBits->Bits();
// black was used in the knob to represent transparency
// use screen to get index for the "transarent" color used in the bitmap
BScreen screen(B_MAIN_SCREEN_ID);
uint8 blackIndex = screen.IndexForColor(kBlack);
// replace black index with transparent index
for (int32 i = 0; i < length; i++)
if (bits[i] == blackIndex)
bits[i] = B_TRANSPARENT_MAGIC_CMAP8;
if (!IsEnabled()) {
// make ghosted versions of the bitmaps
dim_bitmap(fLeftSideBits, kBackground, DIM_LEVEL);
dim_bitmap(fRightSideBits, kBackground, DIM_LEVEL);
dim_bitmap(fKnobBits, kBackground, DIM_LEVEL);
} else if (fMuted) {
// replace green color (and shadow) in left slider side
bits = (uint8*)fLeftSideBits->Bits();
length = fLeftSideBits->BitsLength();
uint8 greenIndex = screen.IndexForColor(kGreen);
uint8 greenShadowIndex = screen.IndexForColor(kGreenShadow);
rgb_color shadow = tint_color(kBackground, B_DARKEN_3_TINT);
rgb_color midShadow = tint_color(kBackground, B_DARKEN_4_TINT);
uint8 replaceIndex = screen.IndexForColor(shadow);
uint8 replaceShadowIndex = screen.IndexForColor(midShadow);
for (int32 i = 0; i < length; i++) {
if (bits[i] == greenIndex)
bits[i] = replaceIndex;
else if (bits[i] == greenShadowIndex)
bits[i] = replaceShadowIndex;
}
}
}
// _ValueFor
int32
VolumeSlider::_ValueFor(float xPos) const
{
BRect r(Bounds());
float sliderStart = (r.left + kVolumeSliderBitmapWidth);
float sliderEnd = (r.right - kVolumeSliderBitmapWidth);
int32 value = fMinValue + (int32)(((xPos - sliderStart)
* (fMaxValue - fMinValue))
/ (sliderEnd - sliderStart - 1.0));
if (value < fMinValue)
value = fMinValue;
if (value > fMaxValue)
value = fMaxValue;
return value;
}

View File

@ -1,55 +1,29 @@
/*
* Copyright 2006, Haiku.
* Copyright 2009, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Stephan Aßmus, superstippi@gmx.de
* Jonas Sundström, jonas@kirilla.com
*/
#ifndef VOLUME_SLIDER_H
#define VOLUME_SLIDER_H
#include <Control.h>
class VolumeSlider : public BControl {
public:
VolumeSlider(BRect frame,
const char* name,
int32 minValue,
int32 maxValue,
BMessage* message = NULL,
BHandler* target = NULL);
#include <Slider.h>
virtual ~VolumeSlider();
// BControl
virtual void AttachedToWindow();
virtual void SetValue(int32 value);
virtual void SetEnabled(bool enable);
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage);
virtual void MouseUp(BPoint where);
class VolumeSlider : public BSlider {
public:
VolumeSlider(BRect frame, const char* name,
int32 minValue, int32 maxValue,
BMessage* message = NULL,
BHandler* target = NULL);
// VolumeSlider
bool IsValid() const;
void SetMuted(bool mute);
bool IsMuted() const
{ return fMuted; }
virtual ~VolumeSlider();
virtual void SetValue(int32 value);
private:
void _MakeBitmaps();
void _DimBitmap(BBitmap* bitmap);
int32 _ValueFor(float xPos) const;
BBitmap* fLeftSideBits;
BBitmap* fRightSideBits;
BBitmap* fKnobBits;
bool fTracking;
bool fMuted;
int32 fMinValue;
int32 fMaxValue;
};
#endif // VOLUME_SLIDER_H