~azzar1/unity/hud-alt-space

« back to all changes in this revision

Viewing changes to launcher/QuicklistView.cpp

  • Committer: CI Train Bot
  • Author(s): handsome_feng
  • Date: 2016-03-18 10:10:26 UTC
  • mfrom: (3999.7.28 unityshell-rotated-kylin)
  • Revision ID: ci-train-bot@canonical.com-20160318101026-8571jyv8ececmzai
Launcher: add Bottom mode, so that the launcher can be positioned horisontally Fixes: #1552630
Approved by: Marco Trevisan (Treviño)

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
{
82
82
  SetGeometry(nux::Geometry(0, 0, 1, 1));
83
83
 
84
 
  _left_space = new nux::SpaceLayout(RawPixel(_padding + ANCHOR_WIDTH + CORNER_RADIUS + LEFT_PADDING_CORRECTION).CP(cv_),
85
 
                                     RawPixel(_padding + ANCHOR_WIDTH + CORNER_RADIUS + LEFT_PADDING_CORRECTION).CP(cv_),
 
84
  int width = 0;
 
85
  int height = 0;
 
86
  // when launcher is on the left, the anchor is on the left of the menuitem, and
 
87
  // when launcher is on the bottom, the anchor is on the bottom of the menuitem.
 
88
  if (Settings::Instance().launcher_position == LauncherPosition::LEFT)
 
89
    width = ANCHOR_WIDTH;
 
90
  else
 
91
    height = ANCHOR_WIDTH;
 
92
  _left_space = new nux::SpaceLayout(RawPixel(_padding + width + CORNER_RADIUS + LEFT_PADDING_CORRECTION).CP(cv_),
 
93
                                     RawPixel(_padding + width + CORNER_RADIUS + LEFT_PADDING_CORRECTION).CP(cv_),
86
94
                                     1, MAX_HEIGHT.CP(cv_));
87
95
 
88
96
  _right_space = new nux::SpaceLayout(_padding.CP(cv_) + CORNER_RADIUS.CP(cv_),
94
102
                                    _padding.CP(cv_) + CORNER_RADIUS.CP(cv_));
95
103
 
96
104
  _bottom_space = new nux::SpaceLayout(1, MAX_WIDTH.CP(cv_),
97
 
                                       _padding.CP(cv_) + CORNER_RADIUS.CP(cv_),
98
 
                                       _padding.CP(cv_) + CORNER_RADIUS.CP(cv_));
 
105
                                       _padding.CP(cv_) + height + CORNER_RADIUS.CP(cv_),
 
106
                                       _padding.CP(cv_) + height + CORNER_RADIUS.CP(cv_));
99
107
 
100
108
  _vlayout = new nux::VLayout(TEXT(""), NUX_TRACKER_LOCATION);
101
109
  _vlayout->AddLayout(_top_space, 0);
129
137
 
130
138
int QuicklistView::CalculateX() const
131
139
{
132
 
  return _anchorX - _padding.CP(cv_);
 
140
  int x = 0;
 
141
  if (Settings::Instance().launcher_position() == LauncherPosition::LEFT)
 
142
    x = _anchorX - _padding.CP(cv_);
 
143
  else
 
144
  {
 
145
    int size = 0;
 
146
    int max = GetBaseWidth() - ANCHOR_HEIGHT.CP(cv_) - 2 * CORNER_RADIUS.CP(cv_) - 2 * _padding.CP(cv_);
 
147
    if (_top_size.CP(cv_) > max)
 
148
    {
 
149
      size = max;
 
150
    }
 
151
    else if (_top_size.CP(cv_) > 0)
 
152
    {
 
153
      size = _top_size.CP(cv_);
 
154
    }
 
155
    x = _anchorX - (ANCHOR_HEIGHT.CP(cv_) / 2) - size - CORNER_RADIUS.CP(cv_) - _padding.CP(cv_);
 
156
  }
 
157
 
 
158
  return x;
133
159
}
134
160
 
135
161
int QuicklistView::CalculateY() const
136
162
{
137
 
  return _anchorY - (ANCHOR_HEIGHT.CP(cv_) / 2) - _top_size.CP(cv_) - CORNER_RADIUS.CP(cv_) - _padding.CP(cv_);
 
163
  int y = 0;
 
164
  if (Settings::Instance().launcher_position() == LauncherPosition::LEFT)
 
165
    y = _anchorY - (ANCHOR_HEIGHT.CP(cv_) / 2) - _top_size.CP(cv_) - CORNER_RADIUS.CP(cv_) - _padding.CP(cv_);
 
166
  else
 
167
    y = _anchorY - GetBaseHeight() + _padding.CP(cv_);
 
168
  return y;
138
169
}
139
170
 
140
171
void
338
369
      auto* us = UScreen::GetDefault();
339
370
      int ql_monitor = us->GetMonitorAtPosition(_anchorX, _anchorY);
340
371
      auto const& ql_monitor_geo = us->GetMonitorGeometry(ql_monitor);
341
 
      int offscreen_size = GetBaseY() + GetBaseHeight() - (ql_monitor_geo.y + ql_monitor_geo.height);
 
372
      auto launcher_position = Settings::Instance().launcher_position();
342
373
 
343
 
      if (offscreen_size > 0)
344
 
        _top_size = offscreen_size + TOP_SIZE;
 
374
      if (launcher_position == LauncherPosition::LEFT)
 
375
      {
 
376
        int offscreen_size = GetBaseY() + GetBaseHeight() - (ql_monitor_geo.y + ql_monitor_geo.height);
 
377
        if (offscreen_size > 0)
 
378
          _top_size = offscreen_size + TOP_SIZE;
 
379
        else
 
380
          _top_size = TOP_SIZE;
 
381
      }
345
382
      else
346
 
        _top_size = TOP_SIZE;
 
383
      {
 
384
        int offscreen_size_left = ql_monitor_geo.x - (_anchorX - GetBaseWidth() / 2);
 
385
        int offscreen_size_right = _anchorX + GetBaseWidth()/2 - (ql_monitor_geo.x + ql_monitor_geo.width);
 
386
        int half_size = (GetBaseWidth() / 2) - _padding.CP(cv_) - CORNER_RADIUS.CP(cv_) - (ANCHOR_HEIGHT.CP(cv_) / 2);
 
387
 
 
388
        if (offscreen_size_left > 0)
 
389
          _top_size = half_size - offscreen_size_left;
 
390
        else if (offscreen_size_right > 0)
 
391
          _top_size = half_size + offscreen_size_right;
 
392
        else
 
393
          _top_size = half_size;
 
394
      }
347
395
 
348
396
      SetXY(CalculateX(), CalculateY());
349
397
    }
442
490
    TotalItemHeight += text_extents.height;
443
491
  }
444
492
 
 
493
  int rotated_anchor_height = 0;
 
494
  if (Settings::Instance().launcher_position() == LauncherPosition::BOTTOM)
 
495
    rotated_anchor_height = ANCHOR_WIDTH;
 
496
 
445
497
  if (TotalItemHeight < ANCHOR_HEIGHT.CP(cv_))
446
498
  {
447
 
    int b = (ANCHOR_HEIGHT.CP(cv_) - TotalItemHeight) / 2 + _padding.CP(cv_) + CORNER_RADIUS.CP(cv_);
448
 
    int t = b + OFFSET_CORRECTION.CP(cv_);
 
499
    int b = (ANCHOR_HEIGHT.CP(cv_) - TotalItemHeight) / 2 + _padding.CP(cv_) + CORNER_RADIUS.CP(cv_) + rotated_anchor_height;
 
500
    int t = b + OFFSET_CORRECTION.CP(cv_) - rotated_anchor_height;
449
501
 
450
502
    _top_space->SetMinimumHeight(t);
451
503
    _top_space->SetMaximumHeight(t);
455
507
  }
456
508
  else
457
509
  {
458
 
    int b = _padding.CP(cv_) + CORNER_RADIUS.CP(cv_);
459
 
    int t = b + OFFSET_CORRECTION.CP(cv_);
 
510
    int b = _padding.CP(cv_) + CORNER_RADIUS.CP(cv_) + rotated_anchor_height;
 
511
    int t = b + OFFSET_CORRECTION.CP(cv_) - rotated_anchor_height;
460
512
 
461
513
    _top_space->SetMinimumHeight(t);
462
514
    _top_space->SetMaximumHeight(t);
476
528
 
477
529
  UpdateTexture();
478
530
 
479
 
  int x = RawPixel(_padding + ANCHOR_WIDTH + CORNER_RADIUS + OFFSET_CORRECTION).CP(cv_);
 
531
  int width = 0;
 
532
  if (Settings::Instance().launcher_position() == LauncherPosition::LEFT)
 
533
    width = ANCHOR_WIDTH;
 
534
  int x = RawPixel(_padding + width + CORNER_RADIUS + OFFSET_CORRECTION).CP(cv_);
480
535
  int y = _top_space->GetMinimumHeight();
481
536
 
482
537
  for (auto const& item : _item_list)
655
710
 
656
711
nux::Area* QuicklistView::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type)
657
712
{
658
 
  if (mouse_position.x > _anchorX)
 
713
  auto launcher_position = Settings::Instance().launcher_position();
 
714
  if ((launcher_position == LauncherPosition::LEFT && (mouse_position.x > _anchorX)) ||
 
715
      (launcher_position == LauncherPosition::BOTTOM && (mouse_position.y < _anchorY)))
659
716
  {
660
717
    return (CairoBaseWindow::FindAreaUnderMouse(mouse_position, event_type));
661
718
  }
864
921
                               gfloat   radius,
865
922
                               guint    pad)
866
923
{
867
 
  //     0  1        2  3
868
 
  //     +--+--------+--+
869
 
  //     |              |
870
 
  //     + 14           + 4
871
 
  //     |              |
872
 
  //     |              |
873
 
  //     |              |
874
 
  //     + 13           |
875
 
  //    /               |
876
 
  //   /                |
877
 
  //  + 12              |
878
 
  //   \                |
879
 
  //    \               |
880
 
  //  11 +              |
881
 
  //     |              |
882
 
  //     |              |
883
 
  //     |              |
884
 
  //  10 +              + 5
885
 
  //     |              |
886
 
  //     +--+--------+--+ 6
887
 
  //     9  8        7
 
924
  //  On the right of the icon:   On the top of the icon:
 
925
  //     0  1        2  3            0  1           2  3
 
926
  //     +--+--------+--+            +--+-----------+--+
 
927
  //     |              |            |                 |
 
928
  //     + 14           + 4       14 +                 + 4
 
929
  //     |              |            |                 |
 
930
  //     |              |            |                 |
 
931
  //     |              |            |                 |
 
932
  //     + 13           |            |                 |
 
933
  //    /               |            |                 |
 
934
  //   /                |            |                 |
 
935
  //  + 12              |            |                 |
 
936
  //   \                |            |                 |
 
937
  //    \               |            |                 |
 
938
  //  11 +              |            |                 |
 
939
  //     |              |         13 +                 + 5
 
940
  //     |              |            |     10    8     |
 
941
  //     |              |         12 +--+--+     +--+--+ 6
 
942
  //  10 +              + 5             11  \   /   7
 
943
  //     |              |                    \ /
 
944
  //     +--+--------+--+ 6                   +
 
945
  //     9  8        7                        9
888
946
 
889
947
 
890
948
  gfloat padding  = pad;
891
949
  int ZEROPOINT5 = 0.0f;
892
 
 
893
 
  gfloat HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height - 2 * padding) / 2.0f;
894
 
  if (HeightToAnchor < 0.0f)
895
 
  {
896
 
    g_warning("Anchor-height and corner-radius a higher than whole texture!");
897
 
    return;
898
 
  }
 
950
  auto launcher_position = Settings::Instance().launcher_position();
899
951
 
900
952
  //gint dynamic_size = height - 2*radius - 2*padding - anchor_height;
901
953
  //gint upper_dynamic_size = upper_size;
902
954
  //gint lower_dynamic_size = dynamic_size - upper_dynamic_size;
903
955
 
 
956
  int size = 0;
 
957
  if (launcher_position == LauncherPosition::LEFT)
 
958
    size = height;
 
959
  else
 
960
    size = width;
 
961
 
 
962
  gfloat HeightToAnchor = ((gfloat) size - 2.0f * radius - anchor_height - 2 * padding) / 2.0f;
 
963
  if (HeightToAnchor < 0.0f)
 
964
  {
 
965
    g_warning("Anchor-height and corner-radius a higher than whole texture!");
 
966
    return;
 
967
  }
 
968
 
904
969
  if (upper_size >= 0)
905
970
  {
906
 
    if (upper_size > height - 2.0f * radius - anchor_height - 2 * padding)
 
971
    if (upper_size > size - 2.0f * radius - anchor_height - 2 * padding)
907
972
    {
908
973
      //g_warning ("[_compute_full_mask_path] incorrect upper_size value");
909
974
      HeightToAnchor = 0;
910
975
    }
911
976
    else
912
977
    {
913
 
      HeightToAnchor = height - 2.0f * radius - anchor_height - 2 * padding - upper_size;
 
978
      HeightToAnchor = size - 2.0f * radius - anchor_height - 2 * padding - upper_size;
914
979
    }
915
980
  }
916
981
  else
917
982
  {
918
 
    HeightToAnchor = (height - 2.0f * radius - anchor_height - 2 * padding) / 2.0f;
 
983
    if (launcher_position == LauncherPosition::LEFT)
 
984
      HeightToAnchor = (size - 2.0f * radius - anchor_height - 2 * padding) / 2.0f;
 
985
    else
 
986
      HeightToAnchor = size - 2.0f * radius - anchor_height - 2 * padding;
919
987
  }
920
988
 
921
989
  cairo_translate(cr, -0.5f, -0.5f);
922
990
 
923
991
  // create path
924
 
  cairo_move_to(cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5);  // Point 1
925
 
  cairo_line_to(cr, width - padding - radius, padding + ZEROPOINT5);    // Point 2
926
 
  cairo_arc(cr,
927
 
            width  - padding - radius + ZEROPOINT5,
928
 
            padding + radius + ZEROPOINT5,
929
 
            radius,
930
 
            -90.0f * G_PI / 180.0f,
931
 
            0.0f * G_PI / 180.0f);   // Point 4
932
 
  cairo_line_to(cr,
933
 
                (gdouble) width - padding + ZEROPOINT5,
934
 
                (gdouble) height - radius - padding + ZEROPOINT5); // Point 5
935
 
  cairo_arc(cr,
936
 
            (gdouble) width - padding - radius + ZEROPOINT5,
937
 
            (gdouble) height - padding - radius + ZEROPOINT5,
938
 
            radius,
939
 
            0.0f * G_PI / 180.0f,
940
 
            90.0f * G_PI / 180.0f);  // Point 7
941
 
  cairo_line_to(cr,
942
 
                anchor_width + padding + radius + ZEROPOINT5,
943
 
                (gdouble) height - padding + ZEROPOINT5); // Point 8
944
 
 
945
 
  cairo_arc(cr,
946
 
            anchor_width + padding + radius + ZEROPOINT5,
947
 
            (gdouble) height - padding - radius,
948
 
            radius,
949
 
            90.0f * G_PI / 180.0f,
950
 
            180.0f * G_PI / 180.0f); // Point 10
951
 
 
952
 
  cairo_line_to(cr,
953
 
                padding + anchor_width + ZEROPOINT5,
954
 
                (gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5);   // Point 11
955
 
  cairo_line_to(cr,
956
 
                padding + ZEROPOINT5,
957
 
                (gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
958
 
  cairo_line_to(cr,
959
 
                padding + anchor_width + ZEROPOINT5,
960
 
                (gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5);  // Point 13
961
 
 
962
 
  cairo_line_to(cr, padding + anchor_width + ZEROPOINT5, padding + radius  + ZEROPOINT5);   // Point 14
963
 
  cairo_arc(cr,
964
 
            padding + anchor_width + radius + ZEROPOINT5,
965
 
            padding + radius + ZEROPOINT5,
966
 
            radius,
967
 
            180.0f * G_PI / 180.0f,
968
 
            270.0f * G_PI / 180.0f);
969
 
 
 
992
  if (launcher_position == LauncherPosition::LEFT)
 
993
  {
 
994
    cairo_move_to(cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5);  // Point 1
 
995
    cairo_line_to(cr, width - padding - radius, padding + ZEROPOINT5);    // Point 2
 
996
    cairo_arc(cr,
 
997
              width  - padding - radius + ZEROPOINT5,
 
998
              padding + radius + ZEROPOINT5,
 
999
              radius,
 
1000
              -90.0f * G_PI / 180.0f,
 
1001
              0.0f * G_PI / 180.0f);   // Point 4
 
1002
    cairo_line_to(cr,
 
1003
                  (gdouble) width - padding + ZEROPOINT5,
 
1004
                  (gdouble) height - radius - padding + ZEROPOINT5); // Point 5
 
1005
    cairo_arc(cr,
 
1006
              (gdouble) width - padding - radius + ZEROPOINT5,
 
1007
              (gdouble) height - padding - radius + ZEROPOINT5,
 
1008
              radius,
 
1009
              0.0f * G_PI / 180.0f,
 
1010
              90.0f * G_PI / 180.0f);  // Point 7
 
1011
    cairo_line_to(cr,
 
1012
                  anchor_width + padding + radius + ZEROPOINT5,
 
1013
                  (gdouble) height - padding + ZEROPOINT5); // Point 8
 
1014
    cairo_arc(cr,
 
1015
              anchor_width + padding + radius + ZEROPOINT5,
 
1016
              (gdouble) height - padding - radius,
 
1017
              radius,
 
1018
              90.0f * G_PI / 180.0f,
 
1019
              180.0f * G_PI / 180.0f); // Point 10
 
1020
    cairo_line_to(cr,
 
1021
                  padding + anchor_width + ZEROPOINT5,
 
1022
                  (gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5);   // Point 11
 
1023
    cairo_line_to(cr,
 
1024
                  padding + ZEROPOINT5,
 
1025
                  (gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
 
1026
    cairo_line_to(cr,
 
1027
                  padding + anchor_width + ZEROPOINT5,
 
1028
                  (gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5);  // Point 13
 
1029
    cairo_line_to(cr, padding + anchor_width + ZEROPOINT5, padding + radius  + ZEROPOINT5);   // Point 14
 
1030
    cairo_arc(cr,
 
1031
              padding + anchor_width + radius + ZEROPOINT5,
 
1032
              padding + radius + ZEROPOINT5,
 
1033
              radius,
 
1034
              180.0f * G_PI / 180.0f,
 
1035
              270.0f * G_PI / 180.0f);
 
1036
  }
 
1037
  else
 
1038
  {
 
1039
    cairo_move_to(cr, padding + radius + ZEROPOINT5, padding + ZEROPOINT5);  // Point 1
 
1040
    cairo_line_to(cr, width - padding - radius, padding + ZEROPOINT5);    // Point 2
 
1041
    cairo_arc(cr,
 
1042
              width  - padding - radius + ZEROPOINT5,
 
1043
              padding + radius + ZEROPOINT5,
 
1044
              radius,
 
1045
              -90.0f * G_PI / 180.0f,
 
1046
              0.0f * G_PI / 180.0f);   // Point 4
 
1047
    cairo_line_to(cr,
 
1048
                  (gdouble) width - padding + ZEROPOINT5,
 
1049
                  (gdouble) height - radius - anchor_width - padding + ZEROPOINT5); // Point 5
 
1050
    cairo_arc(cr,
 
1051
              (gdouble) width - padding - radius + ZEROPOINT5,
 
1052
              (gdouble) height - padding - anchor_width - radius + ZEROPOINT5,
 
1053
              radius,
 
1054
              0.0f * G_PI / 180.0f,
 
1055
              90.0f * G_PI / 180.0f);  // Point 7
 
1056
    cairo_line_to(cr,
 
1057
                  (gdouble) width - padding - radius - HeightToAnchor + ZEROPOINT5,
 
1058
                  height - padding - anchor_width + ZEROPOINT5);   // Point 8
 
1059
    cairo_line_to(cr,
 
1060
                  (gdouble) width - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5,
 
1061
                  height - padding + ZEROPOINT5); // Point 9
 
1062
    cairo_line_to(cr,
 
1063
                  (gdouble) width - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5,
 
1064
                  height - padding - anchor_width + ZEROPOINT5);  // Point 10
 
1065
    cairo_arc(cr,
 
1066
              padding + radius + ZEROPOINT5,
 
1067
              (gdouble) height - padding - anchor_width - radius,
 
1068
              radius,
 
1069
              90.0f * G_PI / 180.0f,
 
1070
              180.0f * G_PI / 180.0f); // Point 11
 
1071
    cairo_line_to(cr,
 
1072
                  padding + ZEROPOINT5,
 
1073
                  (gdouble) height - padding -anchor_width - radius + ZEROPOINT5); // Point 13
 
1074
    cairo_line_to(cr, padding + ZEROPOINT5, padding + radius  + ZEROPOINT5);   // Point 14
 
1075
    cairo_arc(cr,
 
1076
              padding + radius + ZEROPOINT5,
 
1077
              padding + radius + ZEROPOINT5,
 
1078
              radius,
 
1079
              180.0f * G_PI / 180.0f,
 
1080
              270.0f * G_PI / 180.0f);
 
1081
  }
970
1082
  cairo_close_path(cr);
971
1083
}
972
1084