@@ -120,7 +120,7 @@ HexStringToUInt32(BString hexColor, uint32& color_word)
120
120
ColorPaletteWindow::ColorPaletteWindow (BRect frame, int32 mode)
121
121
:
122
122
BWindow(frame, B_TRANSLATE(" Colors" ), B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
123
- B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FRONT
123
+ B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FRONT
124
124
| B_AUTO_UPDATE_SIZE_LIMITS),
125
125
open_panel(NULL ),
126
126
save_panel(NULL )
@@ -156,6 +156,11 @@ ColorPaletteWindow::ColorPaletteWindow(BRect frame, int32 mode)
156
156
color_container->SetDraggingEnabled (TRUE );
157
157
158
158
BFont font;
159
+ font_height fontHt;
160
+ font.GetHeight (&fontHt);
161
+
162
+ color_container->SetExplicitMinSize (BSize (B_SIZE_UNSET,
163
+ (fontHt.ascent + fontHt.descent + fontHt.leading ) * 6 ));
159
164
160
165
// Here add the buttons that control the color-set.
161
166
previous_set = new BButton (" \xe2\xaf\x87 " , new BMessage (HS_PREVIOUS_PALETTE));
@@ -172,13 +177,14 @@ ColorPaletteWindow::ColorPaletteWindow(BRect frame, int32 mode)
172
177
next_set->SetToolTip (B_TRANSLATE_COMMENT (" Next color set" , " In Color Palette window" ));
173
178
next_set->SetEnabled (FALSE );
174
179
175
- BGridLayout* colorSetGrid = BLayoutBuilder::Grid<>(container_box, 2 , B_USE_SMALL_SPACING)
176
- .Add (color_container, 0 , 0 , 1 , 3 )
177
- .Add (previous_set, 1 , 0 )
178
- .Add (next_set, 1 , 2 )
179
- .SetInsets (3 , 3 , 8 , 3 );
180
+ colorSetName = new BTextControl (" " , " color-set-name" , new BMessage (HS_SET_NAME_CHANGED));
180
181
181
- colorSetGrid->SetMinColumnWidth (0 , font.StringWidth (" PALETTEPALETTE" ));
182
+ BGridLayout* colorSetGrid = BLayoutBuilder::Grid<>(container_box, 2 , B_USE_SMALL_SPACING)
183
+ .Add (previous_set, 0 , 0 )
184
+ .Add (colorSetName, 1 , 0 )
185
+ .Add (next_set, 2 , 0 )
186
+ .Add (color_container, 0 , 1 , 3 , 1 )
187
+ .SetInsets (3 , 3 , 3 , 3 );
182
188
183
189
BMessage* message = new BMessage (HS_RGB_CONTROL_INVOKED);
184
190
message->AddInt32 (" buttons" , 0 );
@@ -207,11 +213,11 @@ ColorPaletteWindow::ColorPaletteWindow(BRect frame, int32 mode)
207
213
.Add (hsvSlider)
208
214
.Add (color_control);
209
215
210
- rgbSlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDER " ), B_SIZE_UNSET));
211
- cmySlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDER " ), B_SIZE_UNSET));
212
- labSlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDER " ), B_SIZE_UNSET));
213
- hsvSlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDER " ), B_SIZE_UNSET));
214
- color_control->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDER " ), B_SIZE_UNSET));
216
+ rgbSlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDERSLI " ), B_SIZE_UNSET));
217
+ cmySlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDERSLI " ), B_SIZE_UNSET));
218
+ labSlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDERSLI " ), B_SIZE_UNSET));
219
+ hsvSlider->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDERSLI " ), B_SIZE_UNSET));
220
+ color_control->SetExplicitMinSize (BSize (font.StringWidth (" XX12345SLIDERSLIDERSLI " ), B_SIZE_UNSET));
215
221
216
222
colorPreview = new ColorChip (" chippy" );
217
223
colorPreview->SetColor (RGBColorToBGRA (c));
@@ -247,16 +253,15 @@ ColorPaletteWindow::ColorPaletteWindow(BRect frame, int32 mode)
247
253
hexColorField->SetTarget (this );
248
254
249
255
BGridLayout* colorLayout = BLayoutBuilder::Grid<>(5 , 3 )
250
- .Add (container_box, 0 , 0 )
251
- .Add (sliderLayout, 1 , 0 )
252
- .AddGroup (B_VERTICAL, B_USE_SMALL_SPACING, 2 , 0 )
256
+ .Add (sliderLayout, 0 , 0 )
257
+ .AddGroup (B_VERTICAL, B_USE_SMALL_SPACING, 1 , 0 )
253
258
.Add (colorPreview)
254
259
.Add (hexColorField)
255
260
.End ()
256
261
.SetInsets (5 , 5 , 5 , 5 );
257
262
258
263
BGroupLayout* mainLayout
259
- = BLayoutBuilder::Group<>(this , B_VERTICAL, 0 ).Add (menu_bar).Add (colorLayout);
264
+ = BLayoutBuilder::Group<>(this , B_VERTICAL, 0 ).Add (menu_bar).Add (colorLayout). Add (container_box) ;
260
265
261
266
// call some function that initializes the views depending on the mode
262
267
openControlViews (mode);
@@ -265,6 +270,8 @@ ColorPaletteWindow::ColorPaletteWindow(BRect frame, int32 mode)
265
270
if (ColorSet::currentSetIndex () > 0 )
266
271
previous_set->SetEnabled (TRUE );
267
272
273
+ colorSetName->SetText (ColorSet::currentSet ()->getName ());
274
+
268
275
Show ();
269
276
270
277
if (Lock ()) {
@@ -425,6 +432,8 @@ ColorPaletteWindow::MessageReceived(BMessage* message)
425
432
}
426
433
ColorSet::moveToSet (numSets - 1 );
427
434
next_set->SetEnabled (FALSE );
435
+
436
+ colorSetName->SetText (ColorSet::currentSet ()->getName ());
428
437
} break ;
429
438
// this comes from the menubar->"Set"->"Delete Current Set" and indicates that the current
430
439
// set should be deleted
@@ -446,6 +455,9 @@ ColorPaletteWindow::MessageReceived(BMessage* message)
446
455
(new BAlert (" " , B_TRANSLATE (" Cannot delete the only color set." ),
447
456
B_TRANSLATE (" OK" )))->Go ();
448
457
}
458
+
459
+ colorSetName->SetText (ColorSet::currentSet ()->getName ());
460
+ colorSetName->MakeFocus (false );
449
461
} break ;
450
462
// this comes from a button that is named "next set button", the button is in this window
451
463
// the message indicates that we should change the colorcontainers to display next color set
@@ -462,6 +474,15 @@ ColorPaletteWindow::MessageReceived(BMessage* message)
462
474
463
475
if (ColorSet::numberOfSets () > 1 )
464
476
previous_set->SetEnabled (TRUE );
477
+
478
+ colorSetName->SetText (ColorSet::currentSet ()->getName ());
479
+ colorSetName->MakeFocus (false );
480
+
481
+ SelectedColorsView::sendMessageToAll (new BMessage (HS_COLOR_CHANGED));
482
+
483
+ // give the window the information that selection has changed
484
+ rgb_color c = ColorSet::currentSet ()->currentColor ();
485
+ ColorPaletteWindow::ChangePaletteColor (c);
465
486
} break ;
466
487
// this comes from a button that is named "previous set button", the button is in this
467
488
// window the message indicates that we should change the colorcontainers to display
@@ -481,6 +502,13 @@ ColorPaletteWindow::MessageReceived(BMessage* message)
481
502
next_set->SetEnabled (TRUE );
482
503
else
483
504
next_set->SetEnabled (FALSE );
505
+ colorSetName->SetText (ColorSet::currentSet ()->getName ());
506
+ colorSetName->MakeFocus (false );
507
+ SelectedColorsView::sendMessageToAll (new BMessage (HS_COLOR_CHANGED));
508
+
509
+ // give the window the information that selection has changed
510
+ rgb_color c = ColorSet::currentSet ()->currentColor ();
511
+ ColorPaletteWindow::ChangePaletteColor (c);
484
512
} break ;
485
513
// this is sent from ColorContainer::MouseDown and it's purpose is to
486
514
// let us change the corresponding color to the color-controller also
@@ -580,6 +608,15 @@ ColorPaletteWindow::MessageReceived(BMessage* message)
580
608
{
581
609
handlePaletteSave (message);
582
610
} break ;
611
+ case HS_SET_NAME_CHANGED:
612
+ {
613
+ if (colorSetName->TextLength () > 0 )
614
+ ColorSet::currentSet ()->setName (colorSetName->Text ());
615
+ else
616
+ colorSetName->SetText (ColorSet::currentSet ()->getName ());
617
+
618
+ colorSetName->MakeFocus (false );
619
+ } break ;
583
620
// this comes from the menubar->"Mode"->"RGB-Mode" and indicates that
584
621
// the color selector should be changed to a RGBControl, this is used
585
622
// also for other purposes than just a message-constant
@@ -1172,7 +1209,7 @@ BList* ColorContainer::container_list = new BList();
1172
1209
ColorContainer::ColorContainer (
1173
1210
BRect frame, int32 amount_of_colors, uint32 resizingMode, bool highlight, bool add_arrows)
1174
1211
:
1175
- BView(" color container" , B_FRAME_EVENTS | B_WILL_DRAW)
1212
+ BView(" color container" , B_FRAME_EVENTS | B_WILL_DRAW | B_NAVIGABLE )
1176
1213
{
1177
1214
// here initialize the important variables
1178
1215
highlight_selected = highlight;
@@ -1218,8 +1255,6 @@ ColorContainer::Draw(BRect drawRect)
1218
1255
// every instance of this class should also draw whenever
1219
1256
// a palette entry changes, how should we achieve that ????
1220
1257
1221
- FillRect (drawRect);
1222
-
1223
1258
BRect rect;
1224
1259
1225
1260
for (int32 i = 0 ; i < color_count; i++) {
@@ -1245,6 +1280,7 @@ ColorContainer::MouseDown(BPoint point)
1245
1280
uint32 buttons = 0 ;
1246
1281
uint32 original_button;
1247
1282
1283
+ MakeFocus (true );
1248
1284
GetMouse (&point, &buttons, true );
1249
1285
int32 index, prev_index = ColorSet::currentSet ()->currentColorIndex ();
1250
1286
@@ -1483,6 +1519,90 @@ ColorContainer::MessageReceived(BMessage* message)
1483
1519
}
1484
1520
1485
1521
1522
+ void
1523
+ ColorContainer::KeyDown (const char * bytes, int32 numBytes)
1524
+ {
1525
+ switch (bytes[0 ]) {
1526
+ case B_PAGE_UP:
1527
+ {
1528
+ Window ()->PostMessage (new BMessage (HS_PREVIOUS_PALETTE));
1529
+ } break ;
1530
+ case B_PAGE_DOWN:
1531
+ {
1532
+ Window ()->PostMessage (new BMessage (HS_NEXT_PALETTE));
1533
+ } break ;
1534
+ case B_LEFT_ARROW:
1535
+ {
1536
+ int32 colorIdx = ColorSet::currentSet ()->currentColorIndex ();
1537
+ colorIdx = max_c (0 , colorIdx - 1 );
1538
+ ColorSet::currentSet ()->setCurrentColorIndex (colorIdx);
1539
+ BMessage a_message (HS_PALETTE_SELECTION_CHANGED);
1540
+ a_message.AddInt32 (" index" , colorIdx);
1541
+ ColorContainer::sendMessageToAllContainers (&a_message);
1542
+ SelectedColorsView::sendMessageToAll (new BMessage (HS_COLOR_CHANGED));
1543
+
1544
+ // give the window the information that selection has changed
1545
+ rgb_color c = ColorSet::currentSet ()->currentColor ();
1546
+ ColorPaletteWindow::ChangePaletteColor (c);
1547
+ Window ()->PostMessage (HS_PALETTE_SELECTION_CHANGED, Window ());
1548
+ } break ;
1549
+ case B_RIGHT_ARROW:
1550
+ {
1551
+ int32 colorIdx = ColorSet::currentSet ()->currentColorIndex ();
1552
+ colorIdx = min_c (ColorSet::currentSet ()->sizeOfSet () - 1 , colorIdx + 1 );
1553
+ ColorSet::currentSet ()->setCurrentColorIndex (colorIdx);
1554
+ BMessage a_message (HS_PALETTE_SELECTION_CHANGED);
1555
+ a_message.AddInt32 (" index" , colorIdx);
1556
+ ColorContainer::sendMessageToAllContainers (&a_message);
1557
+ SelectedColorsView::sendMessageToAll (new BMessage (HS_COLOR_CHANGED));
1558
+
1559
+ // give the window the information that selection has changed
1560
+ rgb_color c = ColorSet::currentSet ()->currentColor ();
1561
+ ColorPaletteWindow::ChangePaletteColor (c);
1562
+ Window ()->PostMessage (HS_PALETTE_SELECTION_CHANGED, Window ());
1563
+ } break ;
1564
+ case B_DOWN_ARROW:
1565
+ {
1566
+ int32 colorIdx = ColorSet::currentSet ()->currentColorIndex ();
1567
+ colorIdx += column_count;
1568
+ if (colorIdx <= ColorSet::currentSet ()->sizeOfSet () - 1 ) {
1569
+ ColorSet::currentSet ()->setCurrentColorIndex (colorIdx);
1570
+ BMessage a_message (HS_PALETTE_SELECTION_CHANGED);
1571
+ a_message.AddInt32 (" index" , colorIdx);
1572
+ ColorContainer::sendMessageToAllContainers (&a_message);
1573
+
1574
+ SelectedColorsView::sendMessageToAll (new BMessage (HS_COLOR_CHANGED));
1575
+
1576
+ // give the window the information that selection has changed
1577
+ rgb_color c = ColorSet::currentSet ()->currentColor ();
1578
+ ColorPaletteWindow::ChangePaletteColor (c);
1579
+ Window ()->PostMessage (HS_PALETTE_SELECTION_CHANGED, Window ());
1580
+ }
1581
+ } break ;
1582
+ case B_UP_ARROW:
1583
+ {
1584
+ int32 colorIdx = ColorSet::currentSet ()->currentColorIndex ();
1585
+ colorIdx -= column_count;
1586
+ if (colorIdx >= 0 ) {
1587
+ ColorSet::currentSet ()->setCurrentColorIndex (colorIdx);
1588
+ BMessage a_message (HS_PALETTE_SELECTION_CHANGED);
1589
+ a_message.AddInt32 (" index" , colorIdx);
1590
+ ColorContainer::sendMessageToAllContainers (&a_message);
1591
+
1592
+ SelectedColorsView::sendMessageToAll (new BMessage (HS_COLOR_CHANGED));
1593
+
1594
+ // give the window the information that selection has changed
1595
+ rgb_color c = ColorSet::currentSet ()->currentColor ();
1596
+ ColorPaletteWindow::ChangePaletteColor (c);
1597
+ Window ()->PostMessage (HS_PALETTE_SELECTION_CHANGED, Window ());
1598
+ }
1599
+ } break ;
1600
+ default :
1601
+ BView::KeyDown (bytes, numBytes);
1602
+ }
1603
+ }
1604
+
1605
+
1486
1606
void
1487
1607
ColorContainer::setUpContainer (BRect frame, int32 number_of_colors, bool add_arrows)
1488
1608
{
@@ -1696,13 +1816,19 @@ ColorSet::ColorSet(int32 amount_of_colors, ColorSet* copy_this_palette)
1696
1816
// store the color count
1697
1817
color_count = amount_of_colors;
1698
1818
1699
- // create a default name
1700
- strcpy (name, " default palette" );
1701
-
1702
1819
// put the current color to 0
1703
1820
current_color_index = 0 ;
1704
1821
1705
1822
color_set_list->AddItem (this );
1823
+
1824
+ int32 index = color_set_list->CountItems ();
1825
+
1826
+ if (copy_this_palette == NULL )
1827
+ // create a default name
1828
+ sprintf (name, " %s %d" , B_TRANSLATE (" Color set" ), index);
1829
+ else
1830
+ sprintf (name, " %s %s" , copy_this_palette->getName (), " copy" );
1831
+
1706
1832
}
1707
1833
1708
1834
0 commit comments