huge cleanup, support for SetSizeLimits, support for truncating strings, numerous decorator bug fixes, Layer does not draw when view color is B_TRANSPARENT_COLOR, cleaner dispatching of mouse events to the WinBorder in RootLayer, commented the char map selection in the font server, as it seems glyph lookup by unicode index works much better with the default map

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12945 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-06-03 19:50:30 +00:00
parent e4f0f510a9
commit 59345e264f
20 changed files with 2489 additions and 1717 deletions
@@ -0,0 +1,22 @@
/*
* Copyright 2005, Stephan Aßmus <[email protected]>. All rights reserved.
* Distributed under the terms of the MIT License.
*
* a helper function to truncate strings
*
*/
#ifndef TRUNCATE_STRING_H
#define TRUNCATE_STRING_H
#include <SupportDefs.h>
// truncated_string
void
truncate_string(const char* string,
uint32 mode, float width, char* result,
const float* escapementArray, float fontSize,
float ellipsisWidth, int32 length, int32 numChars);
#endif // STRING_TRUNCATION_H
+128 -83
View File
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@@ -21,119 +21,164 @@
//
// File Name: Decorator.h
// Author: DarkWyrm <[email protected]>
// Stephan Aßmus <[email protected]>
// Description: Base class for window decorators
//
//------------------------------------------------------------------------------
#ifndef _DECORATOR_H_
#define _DECORATOR_H_
#include <SupportDefs.h>
#include <Rect.h>
#include <Region.h>
#include <String.h>
#include <Window.h>
#include "LayerData.h"
#include "ColorSet.h"
#include "LayerData.h"
class DisplayDriver;
class ServerFont;
class BRegion;
typedef enum { DEC_NONE=0, DEC_ZOOM, DEC_CLOSE, DEC_MINIMIZE,
DEC_TAB, DEC_DRAG, DEC_MOVETOBACK, DEC_MOVETOFRONT, DEC_SLIDETAB,
typedef enum {
DEC_NONE = 0,
DEC_ZOOM,
DEC_CLOSE,
DEC_MINIMIZE,
DEC_TAB,
DEC_DRAG,
DEC_MOVETOBACK,
DEC_MOVETOFRONT,
DEC_SLIDETAB,
DEC_RESIZE, CLICK_RESIZE_L, CLICK_RESIZE_T,
CLICK_RESIZE_R, CLICK_RESIZE_B, CLICK_RESIZE_LT, CLICK_RESIZE_RT,
CLICK_RESIZE_LB, CLICK_RESIZE_RB } click_type;
DEC_RESIZE,
CLICK_RESIZE_L,
CLICK_RESIZE_T,
CLICK_RESIZE_R,
CLICK_RESIZE_B,
CLICK_RESIZE_LT,
CLICK_RESIZE_RT,
CLICK_RESIZE_LB,
CLICK_RESIZE_RB
} click_type;
class Decorator
{
public:
Decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags);
virtual ~Decorator(void);
class Decorator {
public:
Decorator(BRect rect,
int32 wlook,
int32 wfeel,
int32 wflags);
virtual ~Decorator();
void SetColors(const ColorSet &cset);
void SetDriver(DisplayDriver *driver);
void SetFlags(int32 wflags);
void SetFeel(int32 wfeel);
void SetFont(ServerFont *font);
void SetLook(int32 wlook);
void SetColors(const ColorSet &cset);
void SetDriver(DisplayDriver *driver);
void SetFlags(int32 wflags);
void SetFeel(int32 wfeel);
void SetFont(ServerFont *font);
void SetLook(int32 wlook);
void SetClose(bool is_down);
void SetMinimize(bool is_down);
void SetZoom(bool is_down);
virtual void SetTitle(const char *string);
int32 GetLook() const;
int32 GetFeel() const;
int32 GetFlags() const;
const char* GetTitle() const;
// we need to know its border(frame). WinBorder's _frame rect
// must expand to include Decorator borders. Otherwise we can't
// draw the border. We also add GetTabRect because I feel we'll need it
BRect GetBorderRect() const;
BRect GetTabRect() const;
bool GetClose();
bool GetMinimize();
bool GetZoom();
virtual void GetSizeLimits(float* minWidth, float* minHeight,
float* maxWidth, float* maxHeight) const;
void SetFocus(bool is_active);
bool GetFocus()
{ return fIsFocused; };
ColorSet GetColors()
{ return (_colors) ? *_colors : ColorSet(); }
void SetClose(bool is_down);
void SetMinimize(bool is_down);
void SetZoom(bool is_down);
virtual void SetTitle(const char *string);
virtual void GetFootprint(BRegion *region);
virtual click_type Clicked(BPoint pt, int32 buttons,
int32 modifiers);
int32 GetLook(void);
int32 GetFeel(void);
int32 GetFlags(void);
const char *GetTitle(void);
// we need to know its border(frame). WinBorder's _frame rect
// must expand to include Decorator borders. Otherwise we can't
// draw the border. We also add GetTabRect because I feel we'll need it
BRect GetBorderRect(void);
BRect GetTabRect(void);
virtual void MoveBy(float x, float y);
virtual void MoveBy(BPoint pt);
virtual BRect SlideTab(float dx, float dy = 0);
virtual void ResizeBy(float x, float y);
virtual void ResizeBy(BPoint pt);
bool GetClose(void);
bool GetMinimize(void);
bool GetZoom(void);
void SetFocus(bool is_active);
bool GetFocus(void) { return _has_focus; };
ColorSet GetColors(void) { return (_colors)?*_colors:ColorSet(); }
virtual void Draw(BRect r);
virtual void Draw();
virtual void DrawClose();
virtual void DrawFrame();
virtual void DrawMinimize();
virtual void DrawTab();
virtual void DrawTitle();
virtual void DrawZoom();
virtual BRect SlideTab(float dx, float dy=0);
virtual void GetFootprint(BRegion *region);
virtual click_type Clicked(BPoint pt, int32 buttons, int32 modifiers);
virtual void MoveBy(float x, float y);
virtual void MoveBy(BPoint pt);
virtual void ResizeBy(float x, float y);
virtual void ResizeBy(BPoint pt);
virtual void Draw(BRect r);
virtual void Draw(void);
virtual void DrawClose(void);
virtual void DrawFrame(void);
virtual void DrawMinimize(void);
virtual void DrawTab(void);
virtual void DrawTitle(void);
virtual void DrawZoom(void);
protected:
int32 _ClipTitle(float width);
protected:
int32 _ClipTitle(float width);
/*!
\brief Returns the number of characters in the title
\return The title character count
*/
int32 _TitleWidth(void) { return (_title_string)?_title_string->CountChars():0; }
virtual void _DrawClose(BRect r);
virtual void _DrawFrame(BRect r);
virtual void _DrawMinimize(BRect r);
virtual void _DrawTab(BRect r);
virtual void _DrawTitle(BRect r);
virtual void _DrawZoom(BRect r);
virtual void _SetFocus(void);
virtual void _DoLayout(void);
virtual void _SetColors(void);
ColorSet *_colors;
DisplayDriver *_driver;
DrawData _drawdata;
int32 _look, _feel, _flags;
BRect _zoomrect,_closerect,_minimizerect,_tabrect,_frame,
_resizerect,_borderrect;
int32 _TitleWidth() const
{ return fTitle.CountChars(); }
private:
bool _close_state, _zoom_state, _minimize_state;
bool _has_focus;
BString *_title_string;
virtual void _DoLayout();
virtual void _DrawFrame(BRect r);
virtual void _DrawTab(BRect r);
virtual void _DrawClose(BRect r);
virtual void _DrawTitle(BRect r);
virtual void _DrawZoom(BRect r);
virtual void _DrawMinimize(BRect r);
virtual void _SetFocus();
virtual void _SetColors();
ColorSet* _colors;
DisplayDriver* _driver;
DrawData _drawdata;
int32 _look;
int32 _feel;
int32 _flags;
BRect _zoomrect;
BRect _closerect;
BRect _minimizerect;
BRect _tabrect;
BRect _frame;
BRect _resizerect;
BRect _borderrect;
private:
bool fClosePressed;
bool fZoomPressed;
bool fMinimizePressed;
bool fIsFocused;
BString fTitle;
};
// add-on stuff
typedef float get_version(void);
typedef Decorator *create_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags);
typedef Decorator* create_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags);
#endif
+1 -1
View File
@@ -48,7 +48,7 @@ class FontServer
public:
FontServer(void);
~FontServer(void);
void Lock(void);
bool Lock(void);
void Unlock(void);
/*!
+2
View File
@@ -108,10 +108,12 @@ class DrawData {
inline const ServerFont& Font() const
{ return fFont; }
// TODO: remove (is contained in SeverFont::Flags())
void SetFontAntiAliasing(bool antiAliasing);
inline bool FontAntiAliasing() const
{ return fFontAntiAliasing; }
// TODO: remove (should be part of DisplayDriver::DrawString() as in BView)
void SetEscapementDelta(escapement_delta delta);
inline escapement_delta EscapementDelta() const
{ return fEscapementDelta; }
+33 -19
View File
@@ -27,10 +27,14 @@
#ifndef SERVERFONT_H_
#define SERVERFONT_H_
#include <Rect.h>
#include <Font.h>
#include <Rect.h>
#include "FontFamily.h"
class BShape;
class BString;
class ServerFont {
public:
ServerFont();
@@ -48,6 +52,9 @@ class ServerFont {
{ return fStyle ? B_OK : B_NO_INIT; }
ServerFont &operator=(const ServerFont& font);
font_direction Direction() const
{ return fDirection; }
uint32 Encoding() const
@@ -70,11 +77,24 @@ class ServerFont {
{ return fStyle->GlyphCount(); }
int32 CountTuned();
font_file_format FileFormat();
const char* GetStyle() const;
const char* GetFamily() const;
const char* GetPath() const
{ return fStyle->GetPath(); }
status_t SetFamilyAndStyle(const uint16& familyID,
const uint16& styleID);
status_t SetFamilyAndStyle(const uint32& fontID);
status_t SetFamilyAndStyle(uint16 familyID,
uint16 styleID);
status_t SetFamilyAndStyle(uint32 fontID);
uint16 StyleID() const
{ return fStyle->GetID(); }
uint16 FamilyID() const
{ return fStyle->Family()->GetID(); }
uint32 GetFamilyAndStyle() const;
void SetDirection(const font_direction& dir)
{ fDirection = dir; }
@@ -109,6 +129,7 @@ class ServerFont {
{ return fStyle->GlyphCount(); }
uint16 CharMapCount() const
{ return fStyle->CharMapCount(); }
BShape** GetGlyphShapes(const char charArray[],
int32 numChars) const;
@@ -125,24 +146,17 @@ class ServerFont {
FT_Face GetFTFace() const
{ return fStyle->GetFTFace(); };
const char* GetStyle() const;
const char* GetFamily() const;
const char* GetPath() const
{ return fStyle->GetPath(); }
uint16 StyleID() const
{ return fStyle->GetID(); }
uint16 FamilyID() const
{ return fStyle->Family()->GetID(); }
uint32 GetFamilyAndStyle() const;
BRect BoundingBox();
void Height(font_height* fh);
void Height(font_height* fh) const;
void TruncateString(BString* inOut,
uint32 mode,
float width) const;
ServerFont &operator=(const ServerFont& font);
protected:
friend class FontStyle;
void _SetStyle(FontStyle* style);
FontStyle* fStyle;
edge_info fEdges;
@@ -152,8 +166,8 @@ protected:
BRect fBounds;
uint32 fFlags;
uint32 fSpacing;
uint16 fFace;
font_direction fDirection;
uint16 fFace;
uint32 fEncoding;
};