[haiku-commits] haiku: hrev50148 - src/kits/interface docs/user/interface headers/os/interface

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 13 Mar 2016 04:53:14 +0100 (CET)

hrev50148 adds 5 changesets to branch 'master'
old head: 3108c9bed0e9bc7a27bf54a8acfdf6a0f319830e
new head: 53f75ce5d67c29708ee6d6da932045200a693566
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=53f75ce5d67c+%5E3108c9bed0e9

----------------------------------------------------------------------------

8db20d05cb0b: BColorControl: Standardize on useOffscreen
  
  ...instead of doubleBuffered for the flag that specifies whether or not to
  draw using an offscreen buffer.
  
  Also remove the (not currently used) text from the docs since the parameter
  is being used.

c5fe2948bac1: BColorControl docs: pointer style
  
  (really minor change that doesn't affect output)

0e3b3f92ef69: BColorControl: Awesome style fixes

76b9d53bd097: BColorControl: Rebuild control after mode switch
  
  App Server sends each window a message that the screen has changed:
  https://www.haiku-os.org/legacy-docs/bebook/BWindow.html#BWindow_ScreenChanged
  Propegate B_SCREEN_CHANGED message to all child views first
  
  Tell BColorControl to read the B_SCREEN_CHANGED message and reinitialize 
itself.
  
  * Only reinit if switching to or from B_CMAP8
  * Initialize all pointers to NULL in constructor
  * Don't destroy and rebuild offscreen view (and text views) on reinit
  * Reinitialize offscreen view on reinit.
  
  Fixes #8035
  
  Also initialzing the pointers to NULL in constructor fixes #12673

53f75ce5d67c: BColorControl: Remove fOffscreenView pointer
  
  ...and rename fBitmap to fOffscreenBitmap to make it more clear what it is.
  
  We don't need to save a pointer to both the offscreen bitmap and
  the offscreen view, just the bitmap. We can access the view by calling
  fOffscreenBitmap->ChildAt((int32)0). This gives us back a _reserved private
  variable slot.
  
  In the (unlikely) case that _InitData() is called with offscreen = false but
  the fOffscreenBitmap is not NULL, delete fOffscreenBitmap before
  setting it to NULL so that memory is not leaked.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 113 insertions(+), 32 deletions(-)
docs/user/interface/ColorControl.dox |   7 +-
headers/os/interface/ColorControl.h  |   5 +-
src/kits/interface/ColorControl.cpp  | 110 ++++++++++++++++++++++++-------
src/kits/interface/View.cpp          |  12 ++++
src/kits/interface/Window.cpp        |  11 +++-

############################################################################

Commit:      8db20d05cb0b8025d8c88cab606a9a74e5fb6a4a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8db20d05cb0b
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sun Mar 13 02:59:14 2016 UTC

BColorControl: Standardize on useOffscreen

...instead of doubleBuffered for the flag that specifies whether or not to
draw using an offscreen buffer.

Also remove the (not currently used) text from the docs since the parameter
is being used.

----------------------------------------------------------------------------

diff --git a/docs/user/interface/ColorControl.dox 
b/docs/user/interface/ColorControl.dox
index 8352db1..0d7281f 100644
--- a/docs/user/interface/ColorControl.dox
+++ b/docs/user/interface/ColorControl.dox
@@ -119,7 +119,7 @@ colorControl->SetValue(0x336698);
 /*!
        \fn BColorControl::BColorControl(BPoint leftTop,
                color_control_layout layout, float cellSize, const char *name,
-               BMessage *message = NULL, bool bufferedDrawing = false)
+               BMessage *message = NULL, bool useOffscreen = false)
        \brief Constructs a new color control object.
 
        \param leftTop location of the left top corner of the frame rectangle
@@ -136,10 +136,9 @@ colorControl->SetValue(0x336698);
        \param name The name of the color control.
        \param message The optional \a message to send to a target in response
                to a change in color value.
-       \param bufferedDrawing If \c true, all on-screen changes are first
+       \param useOffscreen If \c true, all on-screen changes are first
                made to an off-screen bitmap and then copied to the screen
-               making the drawing smoother, but requiring more memory
-               (currently unused).
+               making the drawing smoother, but requiring more memory.
 
        \since BeOS R3
 */
diff --git a/src/kits/interface/ColorControl.cpp 
b/src/kits/interface/ColorControl.cpp
index 0379cd5..59d4cee 100644
--- a/src/kits/interface/ColorControl.cpp
+++ b/src/kits/interface/ColorControl.cpp
@@ -49,12 +49,12 @@ static const uint32 kRampCount = 4;
 
 
 BColorControl::BColorControl(BPoint leftTop, color_control_layout layout,
-       float cellSize, const char* name, BMessage* message, bool 
bufferedDrawing)
+       float cellSize, const char* name, BMessage* message, bool useOffscreen)
        :
        BControl(BRect(leftTop, leftTop), name, NULL, message,
                B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
 {
-       _InitData(layout, cellSize, bufferedDrawing, NULL);
+       _InitData(layout, cellSize, useOffscreen, NULL);
 }
 
 

############################################################################

Commit:      c5fe2948bac140152522b072003dd99853c485f8
URL:         http://cgit.haiku-os.org/haiku/commit/?id=c5fe2948bac1
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sun Mar 13 03:03:54 2016 UTC

BColorControl docs: pointer style

(really minor change that doesn't affect output)

----------------------------------------------------------------------------

diff --git a/docs/user/interface/ColorControl.dox 
b/docs/user/interface/ColorControl.dox
index 0d7281f..312ff03 100644
--- a/docs/user/interface/ColorControl.dox
+++ b/docs/user/interface/ColorControl.dox
@@ -119,7 +119,7 @@ colorControl->SetValue(0x336698);
 /*!
        \fn BColorControl::BColorControl(BPoint leftTop,
                color_control_layout layout, float cellSize, const char *name,
-               BMessage *message = NULL, bool useOffscreen = false)
+               BMessage* message = NULL, bool useOffscreen = false)
        \brief Constructs a new color control object.
 
        \param leftTop location of the left top corner of the frame rectangle

############################################################################

Commit:      0e3b3f92ef691ddea3e2c644fd46bc6ee5cfe51c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0e3b3f92ef69
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sun Mar 13 01:31:06 2016 UTC

BColorControl: Awesome style fixes

----------------------------------------------------------------------------

diff --git a/src/kits/interface/ColorControl.cpp 
b/src/kits/interface/ColorControl.cpp
index 59d4cee..62c6b98 100644
--- a/src/kits/interface/ColorControl.cpp
+++ b/src/kits/interface/ColorControl.cpp
@@ -269,7 +269,8 @@ BColorControl::SetValue(int32 value)
 
        if (fPaletteMode) {
                //workaround when two indexes have the same color
-               rgb_color c = 
BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex);
+               rgb_color c
+                       = 
BScreen(Window()).ColorForIndex(fSelectedPaletteColorIndex);
                c.alpha = 255;
                if (fSelectedPaletteColorIndex == -1 || c != c2) {
                                //here SetValue hasn't been called by mouse 
tracking
@@ -341,7 +342,7 @@ BColorControl::AttachedToWindow()
        fGreenText->SetTarget(this);
        fBlueText->SetTarget(this);
 
-       if (fBitmap)
+       if (fBitmap != NULL)
                _InitOffscreen();
 }
 
@@ -491,7 +492,8 @@ BColorControl::_DrawSelectors(BView* target)
        if (fPaletteMode) {
                if (fSelectedPaletteColorIndex != -1) {
                        target->SetHighColor(lightenmax);
-                       
target->StrokeRect(_PaletteSelectorFrame(fSelectedPaletteColorIndex));
+                       target->StrokeRect(
+                               
_PaletteSelectorFrame(fSelectedPaletteColorIndex));
                }
        } else {
                rgb_color color = ValueAsColor();
@@ -666,18 +668,22 @@ BColorControl::SetLayout(color_control_layout layout)
                        fColumns = 4;
                        fRows = 64;
                        break;
+
                case B_CELLS_8x32:
                        fColumns = 8;
                        fRows = 32;
                        break;
+
                case B_CELLS_16x16:
                        fColumns = 16;
                        fRows = 16;
                        break;
+
                case B_CELLS_32x8:
                        fColumns = 32;
                        fRows = 8;
                        break;
+
                case B_CELLS_64x4:
                        fColumns = 64;
                        fRows = 4;
@@ -694,12 +700,16 @@ BColorControl::Layout() const
 {
        if (fColumns == 4 && fRows == 64)
                return B_CELLS_4x64;
+
        if (fColumns == 8 && fRows == 32)
                return B_CELLS_8x32;
+
        if (fColumns == 16 && fRows == 16)
                return B_CELLS_16x16;
+
        if (fColumns == 32 && fRows == 8)
                return B_CELLS_32x8;
+
        if (fColumns == 64 && fRows == 4)
                return B_CELLS_64x4;
 
@@ -1029,22 +1039,27 @@ BColorControl::Perform(perform_code code, void* _data)
                        ((perform_data_min_size*)_data)->return_value
                                = BColorControl::MinSize();
                        return B_OK;
+
                case PERFORM_CODE_MAX_SIZE:
                        ((perform_data_max_size*)_data)->return_value
                                = BColorControl::MaxSize();
                        return B_OK;
+
                case PERFORM_CODE_PREFERRED_SIZE:
                        ((perform_data_preferred_size*)_data)->return_value
                                = BColorControl::PreferredSize();
                        return B_OK;
+
                case PERFORM_CODE_LAYOUT_ALIGNMENT:
                        ((perform_data_layout_alignment*)_data)->return_value
                                = BColorControl::LayoutAlignment();
                        return B_OK;
+
                case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
                        
((perform_data_has_height_for_width*)_data)->return_value
                                = BColorControl::HasHeightForWidth();
                        return B_OK;
+
                case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
                {
                        perform_data_get_height_for_width* data
@@ -1053,12 +1068,14 @@ BColorControl::Perform(perform_code code, void* _data)
                                &data->max, &data->preferred);
                        return B_OK;
                }
+
                case PERFORM_CODE_SET_LAYOUT:
                {
                        perform_data_set_layout* data = 
(perform_data_set_layout*)_data;
                        BColorControl::SetLayout(data->layout);
                        return B_OK;
                }
+
                case PERFORM_CODE_LAYOUT_INVALIDATED:
                {
                        perform_data_layout_invalidated* data
@@ -1066,11 +1083,13 @@ BColorControl::Perform(perform_code code, void* _data)
                        BColorControl::LayoutInvalidated(data->descendants);
                        return B_OK;
                }
+
                case PERFORM_CODE_DO_LAYOUT:
                {
                        BColorControl::DoLayout();
                        return B_OK;
                }
+
                case PERFORM_CODE_SET_ICON:
                {
                        perform_data_set_icon* data = 
(perform_data_set_icon*)_data;

############################################################################

Commit:      76b9d53bd09719bdea88316d6b9e552436d03357
URL:         http://cgit.haiku-os.org/haiku/commit/?id=76b9d53bd097
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Wed Mar  9 00:13:38 2016 UTC

Ticket:      https://dev.haiku-os.org/ticket/8035
Ticket:      https://dev.haiku-os.org/ticket/12673

BColorControl: Rebuild control after mode switch

App Server sends each window a message that the screen has changed:
https://www.haiku-os.org/legacy-docs/bebook/BWindow.html#BWindow_ScreenChanged
Propegate B_SCREEN_CHANGED message to all child views first

Tell BColorControl to read the B_SCREEN_CHANGED message and reinitialize itself.

* Only reinit if switching to or from B_CMAP8
* Initialize all pointers to NULL in constructor
* Don't destroy and rebuild offscreen view (and text views) on reinit
* Reinitialize offscreen view on reinit.

Fixes #8035

Also initialzing the pointers to NULL in constructor fixes #12673

----------------------------------------------------------------------------

diff --git a/src/kits/interface/ColorControl.cpp 
b/src/kits/interface/ColorControl.cpp
index 62c6b98..2b33067 100644
--- a/src/kits/interface/ColorControl.cpp
+++ b/src/kits/interface/ColorControl.cpp
@@ -52,7 +52,12 @@ BColorControl::BColorControl(BPoint leftTop, 
color_control_layout layout,
        float cellSize, const char* name, BMessage* message, bool useOffscreen)
        :
        BControl(BRect(leftTop, leftTop), name, NULL, message,
-               B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
+               B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE),
+       fRedText(NULL),
+       fGreenText(NULL),
+       fBlueText(NULL),
+       fBitmap(NULL),
+       fOffscreenView(NULL)
 {
        _InitData(layout, cellSize, useOffscreen, NULL);
 }
@@ -60,7 +65,12 @@ BColorControl::BColorControl(BPoint leftTop, 
color_control_layout layout,
 
 BColorControl::BColorControl(BMessage* data)
        :
-       BControl(data)
+       BControl(data),
+       fRedText(NULL),
+       fGreenText(NULL),
+       fBlueText(NULL),
+       fBitmap(NULL),
+       fOffscreenView(NULL)
 {
        int32 layout;
        float cellSize;
@@ -174,13 +184,15 @@ BColorControl::_InitData(color_control_layout layout, 
float size,
        ResizeToPreferred();
 
        if (useOffscreen) {
-               BRect bounds = _PaletteFrame();
-               fBitmap = new BBitmap(bounds, B_RGB32, true, false);
-               fOffscreenView = new BView(bounds, "off_view", 0, 0);
-
-               fBitmap->Lock();
-               fBitmap->AddChild(fOffscreenView);
-               fBitmap->Unlock();
+               if (fOffscreenView != NULL) {
+                       BRect bounds = _PaletteFrame();
+                       fBitmap = new BBitmap(bounds, B_RGB32, true, false);
+                       fOffscreenView = new BView(bounds, "off_view", 0, 0);
+
+                       fBitmap->Lock();
+                       fBitmap->AddChild(fOffscreenView);
+                       fBitmap->Unlock();
+               }
        } else {
                fBitmap = NULL;
                fOffscreenView = NULL;
@@ -363,6 +375,36 @@ BColorControl::MessageReceived(BMessage* message)
                        Invoke();
                        break;
                }
+
+               case B_SCREEN_CHANGED:
+               {
+                       BRect frame;
+                       uint32 mode;
+                       if (message->FindRect("frame", &frame) == B_OK
+                               && message->FindInt32("mode", (int32*)&mode) == 
B_OK) {
+                               if ((fPaletteMode && mode == B_CMAP8)
+                                       || (!fPaletteMode && mode != B_CMAP8)) {
+                                       // not switching to or from B_CMAP8, 
break
+                                       break;
+                               }
+
+                               // fake an archive message (so we don't rebuild 
views)
+                               BMessage* data = new BMessage();
+                               data->AddInt32("_val", Value());
+
+                               // reinititialize
+                               bool useOffscreen = fOffscreenView != NULL;
+                               _InitData((color_control_layout)fColumns, 
fCellSize,
+                                       useOffscreen, data);
+                               if (useOffscreen)
+                                       _InitOffscreen();
+
+                               // cleanup
+                               delete data;
+                       }
+                       break;
+               }
+
                default:
                        BControl::MessageReceived(message);
        }
diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp
index cf03b8f..004d877 100644
--- a/src/kits/interface/View.cpp
+++ b/src/kits/interface/View.cpp
@@ -4955,6 +4955,18 @@ BView::MessageReceived(BMessage* message)
                        case B_FONTS_UPDATED:
                                break;
 
+                       case B_SCREEN_CHANGED:
+                       {
+                               // propegate message to child views
+                               int32 childCount = CountChildren();
+                               for (int32 i = 0; i < childCount; i++) {
+                                       BView* view = ChildAt(i);
+                                       if (view != NULL)
+                                               view->MessageReceived(message);
+                               }
+                               break;
+                       }
+
                        default:
                                BHandler::MessageReceived(message);
                                break;
diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp
index 7a6b203..d847f3d 100644
--- a/src/kits/interface/Window.cpp
+++ b/src/kits/interface/Window.cpp
@@ -1111,8 +1111,17 @@ FrameMoved(origin);
                                BRect frame;
                                uint32 mode;
                                if (message->FindRect("frame", &frame) == B_OK
-                                       && message->FindInt32("mode", 
(int32*)&mode) == B_OK)
+                                       && message->FindInt32("mode", 
(int32*)&mode) == B_OK) {
+                                       // propegate message to child views
+                                       int32 childCount = CountChildren();
+                                       for (int32 i = 0; i < childCount; i++) {
+                                               BView* view = ChildAt(i);
+                                               if (view != NULL)
+                                                       
view->MessageReceived(message);
+                                       }
+                                       // call hook method
                                        ScreenChanged(frame, (color_space)mode);
+                               }
                        } else
                                target->MessageReceived(message);
                        break;

############################################################################

Revision:    hrev50148
Commit:      53f75ce5d67c29708ee6d6da932045200a693566
URL:         http://cgit.haiku-os.org/haiku/commit/?id=53f75ce5d67c
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Sun Mar 13 01:20:02 2016 UTC

BColorControl: Remove fOffscreenView pointer

...and rename fBitmap to fOffscreenBitmap to make it more clear what it is.

We don't need to save a pointer to both the offscreen bitmap and
the offscreen view, just the bitmap. We can access the view by calling
fOffscreenBitmap->ChildAt((int32)0). This gives us back a _reserved private
variable slot.

In the (unlikely) case that _InitData() is called with offscreen = false but
the fOffscreenBitmap is not NULL, delete fOffscreenBitmap before
setting it to NULL so that memory is not leaked.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/ColorControl.h 
b/headers/os/interface/ColorControl.h
index 2bcf0a0..6d6ccb9 100644
--- a/headers/os/interface/ColorControl.h
+++ b/headers/os/interface/ColorControl.h
@@ -125,12 +125,11 @@ private:
                        BTextControl*           fGreenText;
                        BTextControl*           fBlueText;
 
-                       BBitmap*                        fBitmap;
-                       BView*                          fOffscreenView;
+                       BBitmap*                        fOffscreenBitmap;
 
                        int16                           fFocusedRamp;
                        int16                           fClickedRamp;
-                       uint32                          _reserved[2];
+                       uint32                          _reserved[3];
 };
 
 inline void
diff --git a/src/kits/interface/ColorControl.cpp 
b/src/kits/interface/ColorControl.cpp
index 2b33067..61301c4 100644
--- a/src/kits/interface/ColorControl.cpp
+++ b/src/kits/interface/ColorControl.cpp
@@ -56,8 +56,7 @@ BColorControl::BColorControl(BPoint leftTop, 
color_control_layout layout,
        fRedText(NULL),
        fGreenText(NULL),
        fBlueText(NULL),
-       fBitmap(NULL),
-       fOffscreenView(NULL)
+       fOffscreenBitmap(NULL)
 {
        _InitData(layout, cellSize, useOffscreen, NULL);
 }
@@ -69,8 +68,7 @@ BColorControl::BColorControl(BMessage* data)
        fRedText(NULL),
        fGreenText(NULL),
        fBlueText(NULL),
-       fBitmap(NULL),
-       fOffscreenView(NULL)
+       fOffscreenBitmap(NULL)
 {
        int32 layout;
        float cellSize;
@@ -86,7 +84,7 @@ BColorControl::BColorControl(BMessage* data)
 
 BColorControl::~BColorControl()
 {
-       delete fBitmap;
+       delete fOffscreenBitmap;
 }
 
 
@@ -184,18 +182,18 @@ BColorControl::_InitData(color_control_layout layout, 
float size,
        ResizeToPreferred();
 
        if (useOffscreen) {
-               if (fOffscreenView != NULL) {
+               if (fOffscreenBitmap != NULL) {
                        BRect bounds = _PaletteFrame();
-                       fBitmap = new BBitmap(bounds, B_RGB32, true, false);
-                       fOffscreenView = new BView(bounds, "off_view", 0, 0);
+                       fOffscreenBitmap = new BBitmap(bounds, B_RGB32, true, 
false);
+                       BView* offscreenView = new BView(bounds, "off_view", 0, 
0);
 
-                       fBitmap->Lock();
-                       fBitmap->AddChild(fOffscreenView);
-                       fBitmap->Unlock();
+                       fOffscreenBitmap->Lock();
+                       fOffscreenBitmap->AddChild(offscreenView);
+                       fOffscreenBitmap->Unlock();
                }
        } else {
-               fBitmap = NULL;
-               fOffscreenView = NULL;
+               delete fOffscreenBitmap;
+               fOffscreenBitmap = NULL;
        }
 }
 
@@ -254,7 +252,7 @@ BColorControl::Archive(BMessage* data, bool deep) const
                status = data->AddFloat("_csize", fCellSize);
 
        if (status == B_OK)
-               status = data->AddBool("_use_off", fOffscreenView != NULL);
+               status = data->AddBool("_use_off", fOffscreenBitmap != NULL);
 
        return status;
 }
@@ -354,7 +352,7 @@ BColorControl::AttachedToWindow()
        fGreenText->SetTarget(this);
        fBlueText->SetTarget(this);
 
-       if (fBitmap != NULL)
+       if (fOffscreenBitmap != NULL)
                _InitOffscreen();
 }
 
@@ -393,7 +391,7 @@ BColorControl::MessageReceived(BMessage* message)
                                data->AddInt32("_val", Value());
 
                                // reinititialize
-                               bool useOffscreen = fOffscreenView != NULL;
+                               bool useOffscreen = fOffscreenBitmap != NULL;
                                _InitData((color_control_layout)fColumns, 
fCellSize,
                                        useOffscreen, data);
                                if (useOffscreen)
@@ -414,8 +412,8 @@ BColorControl::MessageReceived(BMessage* message)
 void
 BColorControl::Draw(BRect updateRect)
 {
-       if (fBitmap != NULL)
-               DrawBitmap(fBitmap, B_ORIGIN);
+       if (fOffscreenBitmap != NULL)
+               DrawBitmap(fOffscreenBitmap, B_ORIGIN);
        else
                _DrawColorArea(this, updateRect);
 
@@ -657,10 +655,13 @@ BColorControl::_PaletteSelectorFrame(uint8 colorIndex) 
const
 void
 BColorControl::_InitOffscreen()
 {
-       if (fBitmap->Lock()) {
-               _DrawColorArea(fOffscreenView, _PaletteFrame());
-               fOffscreenView->Sync();
-               fBitmap->Unlock();
+       if (fOffscreenBitmap->Lock()) {
+               BView* offscreenView = fOffscreenBitmap->ChildAt((int32)0);
+               if (offscreenView != NULL) {
+                       _DrawColorArea(offscreenView, _PaletteFrame());
+                       offscreenView->Sync();
+               }
+               fOffscreenBitmap->Unlock();
        }
 }
 


Other related posts:

  • » [haiku-commits] haiku: hrev50148 - src/kits/interface docs/user/interface headers/os/interface - jscipione