diff options
Diffstat (limited to 'dash')
| -rwxr-xr-x | dash/CoverflowResultView.cpp | 36 | ||||
| -rwxr-xr-x | dash/CoverflowResultView.h | 3 | ||||
| -rw-r--r-- | dash/DashController.cpp | 34 | ||||
| -rw-r--r-- | dash/DashView.cpp | 118 | ||||
| -rw-r--r-- | dash/DashView.h | 7 | ||||
| -rwxr-xr-x | dash/LensView.cpp | 64 | ||||
| -rw-r--r-- | dash/LensView.h | 4 | ||||
| -rwxr-xr-x | dash/PlacesGroup.cpp | 27 | ||||
| -rw-r--r-- | dash/PlacesGroup.h | 6 | ||||
| -rw-r--r-- | dash/PreviewStateMachine.cpp | 10 | ||||
| -rw-r--r-- | dash/ResultView.cpp | 12 | ||||
| -rw-r--r-- | dash/ResultView.h | 14 | ||||
| -rw-r--r-- | dash/ResultViewGrid.cpp | 118 | ||||
| -rw-r--r-- | dash/ResultViewGrid.h | 5 | ||||
| -rw-r--r-- | dash/StandaloneDash.cpp | 5 | ||||
| -rw-r--r-- | dash/previews/ActionButton.cpp | 2 | ||||
| -rw-r--r-- | dash/previews/PreviewContainer.cpp | 17 | ||||
| -rw-r--r-- | dash/previews/SocialPreviewContent.cpp | 77 | ||||
| -rw-r--r-- | dash/previews/SocialPreviewContent.h | 4 |
19 files changed, 326 insertions, 237 deletions
diff --git a/dash/CoverflowResultView.cpp b/dash/CoverflowResultView.cpp index 4441651c8..7c2d04d23 100755 --- a/dash/CoverflowResultView.cpp +++ b/dash/CoverflowResultView.cpp @@ -18,6 +18,7 @@ */ #include "CoverflowResultView.h" +#include <UnityCore/Variant.h> #include "unity-shared/IconLoader.h" #include "unity-shared/IconTexture.h" #include "unity-shared/DashStyle.h" @@ -124,18 +125,18 @@ nux::ObjectPtr<nux::BaseTexture> CoverflowResultItem::GetTexture() const void CoverflowResultItem::Activate(int button) { + int index = Index(); + int size = model_->Items().size(); + + glib::Variant data(g_variant_new("(iiii)", 0, 0, index, size - index)); + //Left and right click take you to previews. if (button == 1 || button == 3) - parent_->UriActivated.emit(result_.uri, ResultView::ActivateType::PREVIEW); + parent_->Activate(result_.uri, index, ResultView::ActivateType::PREVIEW); //Scroll click opens up music player. else if (button == 2) - parent_->UriActivated.emit(result_.uri, ResultView::ActivateType::DIRECT); - - int index = Index(); - int size = model_->Items().size(); + parent_->Activate(result_.uri, index, ResultView::ActivateType::DIRECT); - ubus_.SendMessage(UBUS_DASH_PREVIEW_INFO_PAYLOAD, - g_variant_new("(iiii)", 0, 0, index, size - index)); } CoverflowResultView::Impl::Impl(CoverflowResultView *parent) @@ -189,11 +190,8 @@ CoverflowResultView::Impl::Impl(CoverflowResultView *parent) if (nav_mode) { - int left_results = current_index; - int right_results = num_results ? (num_results - current_index) - 1 : 0; - parent_->UriActivated.emit(GetUriForIndex(current_index), ActivateType::PREVIEW); - ubus_.SendMessage(UBUS_DASH_PREVIEW_INFO_PAYLOAD, - g_variant_new("(iiii)", 0, 0, left_results, right_results)); + std::string uri = GetUriForIndex(current_index); + parent_->Activate(uri, current_index, ActivateType::PREVIEW); } }); } @@ -309,5 +307,19 @@ long CoverflowResultView::ComputeContentSize() } +void CoverflowResultView::Activate(std::string const& uri, int index, ResultView::ActivateType type) +{ + unsigned num_results = pimpl->coverflow_->model()->Items().size(); + + int left_results = index; + int right_results = num_results ? (num_results - index) - 1 : 0; + int row_y = GetRootGeometry().y; + int row_height = renderer_->height; + + glib::Variant data(g_variant_new("(iiii)", row_y, row_height, left_results, right_results)); + UriActivated.emit(uri, type, data); +} + + } } diff --git a/dash/CoverflowResultView.h b/dash/CoverflowResultView.h index f300f3d5d..57cc4fa72 100755 --- a/dash/CoverflowResultView.h +++ b/dash/CoverflowResultView.h @@ -39,12 +39,15 @@ public: virtual void AddResult(Result& result); virtual void RemoveResult(Result& result); + + virtual void Activate(std::string const& uri, int index, ActivateType type); protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); virtual long ComputeContentSize(); + private: struct Impl; Impl* pimpl; diff --git a/dash/DashController.cpp b/dash/DashController.cpp index 668a73b1e..38faea260 100644 --- a/dash/DashController.cpp +++ b/dash/DashController.cpp @@ -1,5 +1,6 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2012 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -22,12 +23,13 @@ #include <Nux/HLayout.h> #include <UnityCore/GLibWrapper.h> -#include "unity-shared/UnitySettings.h" -#include "unity-shared/PanelStyle.h" #include "unity-shared/DashStyle.h" -#include "unity-shared/PluginAdapter.h" +#include "unity-shared/PanelStyle.h" #include "unity-shared/UBusMessages.h" +#include "unity-shared/UnitySettings.h" #include "unity-shared/UScreen.h" +#include "unity-shared/WindowManager.h" + namespace unity { @@ -89,7 +91,7 @@ Controller::Controller() }); auto spread_cb = sigc::bind(sigc::mem_fun(this, &Controller::HideDash), true); - PluginAdapter::Default()->initiate_spread.connect(spread_cb); + WindowManager::Default().initiate_spread.connect(spread_cb); g_bus_get (G_BUS_TYPE_SESSION, dbus_connect_cancellable_, OnBusAcquired, this); } @@ -114,11 +116,11 @@ void Controller::SetupWindow() window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow)); /* FIXME - first time we load our windows there is a race that causes the input window not to actually get input, this side steps that by causing an input window show and hide before we really need it. */ - auto plugin_adapter = PluginAdapter::Default(); - plugin_adapter->saveInputFocus (); + WindowManager& wm = WindowManager::Default(); + wm.SaveInputFocus (); window_->EnableInputWindow(true, dash::window_title, true, false); window_->EnableInputWindow(false, dash::window_title, true, false); - plugin_adapter->restoreInputFocus (); + wm.RestoreInputFocus (); } void Controller::SetupDashView() @@ -228,7 +230,6 @@ void Controller::Relayout(bool check_monitor) if (check_monitor) { monitor_ = CLAMP(GetIdealMonitor(), 0, static_cast<int>(UScreen::GetDefault()->GetMonitors().size()-1)); - printf("relayout on monitor:%d, monitor count:%d\n", monitor_, static_cast<int>(UScreen::GetDefault()->GetMonitors().size())); } nux::Geometry geo = GetIdealWindowGeometry(); @@ -277,18 +278,18 @@ void Controller::OnExternalHideDash(GVariant* variant) void Controller::ShowDash() { EnsureDash(); - PluginAdapter* adaptor = PluginAdapter::Default(); + WindowManager& wm = WindowManager::Default(); // Don't want to show at the wrong time - if (visible_ || adaptor->IsExpoActive() || adaptor->IsScaleActive()) + if (visible_ || wm.IsExpoActive() || wm.IsScaleActive()) return; // We often need to wait for the mouse/keyboard to be available while a plugin // is finishing it's animations/cleaning up. In these cases, we patiently wait // for the screen to be available again before honouring the request. - if (adaptor->IsScreenGrabbed()) + if (wm.IsScreenGrabbed()) { screen_ungrabbed_slot_.disconnect(); - screen_ungrabbed_slot_ = PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed)); + screen_ungrabbed_slot_ = wm.screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed)); need_show_ = true; return; } @@ -338,7 +339,7 @@ void Controller::HideDash(bool restore) nux::GetWindowCompositor().SetKeyFocusArea(NULL,nux::KEY_NAV_NONE); if (restore) - PluginAdapter::Default ()->restoreInputFocus (); + WindowManager::Default().RestoreInputFocus(); StartShowHideTimeline(); @@ -377,8 +378,9 @@ gboolean Controller::CheckShortcutActivation(const char* key_string) std::string lens_id = view_->GetIdForShortcutActivation(std::string(key_string)); if (lens_id != "") { - if (PluginAdapter::Default()->IsScaleActive()) - PluginAdapter::Default()->TerminateScale(); + WindowManager& wm = WindowManager::Default(); + if (wm.IsScaleActive()) + wm.TerminateScale(); GVariant* args = g_variant_new("(sus)", lens_id.c_str(), dash::GOTO_DASH_URI, ""); OnActivateRequest(args); diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 21a2a3b72..39d2abcf7 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -160,6 +160,7 @@ void DashView::ClosePreview() animation_.Start(); } + preview_navigation_mode_ = previews::Navigation::NONE; preview_displaying_ = false; // re-focus dash view component. @@ -196,6 +197,39 @@ void DashView::FadeInCallBack(float const& fade_in_value) } } +void DashView::OnUriActivated(ResultView::ActivateType type, std::string const& uri, GVariant* data, std::string const& unique_id) +{ + last_activated_uri_ = uri; + stored_activated_unique_id_ = unique_id; + + if (data) + { + // Update positioning information. + int position = -1; + int row_height = 0; + int results_to_the_left = 0; + int results_to_the_right = 0; + g_variant_get(data, "(iiii)", &position, &row_height, &results_to_the_left, &results_to_the_right); + preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, position); + preview_state_machine_.left_results = results_to_the_left; + preview_state_machine_.right_results = results_to_the_right; + + if (opening_row_y_ == -1) + { + // Update only when opening the previews + opening_row_y_ = position; + } + opening_row_height_ = row_height; + } + + // we want immediate preview reaction on first opening. + if (type == ResultView::ActivateType::PREVIEW && !preview_displaying_) + { + BuildPreview(Preview::Ptr(nullptr)); + } +} + + void DashView::BuildPreview(Preview::Ptr model) { if (!preview_displaying_) @@ -234,21 +268,19 @@ void DashView::BuildPreview(Preview::Ptr model) // connect to nav left/right signals to request nav left/right movement. preview_container_->navigate_left.connect([&] () { - preview_state_machine_.Reset(); preview_navigation_mode_ = previews::Navigation::LEFT; // sends a message to all result views, sending the the uri of the current preview result // and the unique id of the result view that should be handling the results - ubus_manager_.SendMessage(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, g_variant_new("(iss)", -1, stored_preview_uri_identifier_.c_str(), stored_preview_unique_id_.c_str())); + ubus_manager_.SendMessage(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, g_variant_new("(iss)", -1, last_activated_uri_.c_str(), stored_activated_unique_id_.c_str())); }); preview_container_->navigate_right.connect([&] () { - preview_state_machine_.Reset(); preview_navigation_mode_ = previews::Navigation::RIGHT; // sends a message to all result views, sending the the uri of the current preview result // and the unique id of the result view that should be handling the results - ubus_manager_.SendMessage(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, g_variant_new("(iss)", 1, stored_preview_uri_identifier_.c_str(), stored_preview_unique_id_.c_str())); + ubus_manager_.SendMessage(UBUS_DASH_PREVIEW_NAVIGATION_REQUEST, g_variant_new("(iss)", 1, last_activated_uri_.c_str(), stored_activated_unique_id_.c_str())); }); preview_container_->request_close.connect([&] () { ClosePreview(); }); @@ -367,11 +399,7 @@ void DashView::SetupViews() content_layout_->AddView(lenses_layout_, 1, nux::MINOR_POSITION_LEFT); home_view_ = new LensView(home_lens_, nullptr); - home_view_->uri_preview_activated.connect([&] (std::string const& uri, std::string const& unique_id) - { - stored_preview_unique_id_ = unique_id; - stored_preview_uri_identifier_ = uri; - }); + home_view_->uri_activated.connect(sigc::mem_fun(this, &DashView::OnUriActivated)); AddChild(home_view_); active_lens_view_ = home_view_; @@ -388,26 +416,6 @@ void DashView::SetupUBusConnections() { ubus_manager_.RegisterInterest(UBUS_PLACE_ENTRY_ACTIVATE_REQUEST, sigc::mem_fun(this, &DashView::OnActivateRequest)); - - ubus_manager_.RegisterInterest(UBUS_DASH_PREVIEW_INFO_PAYLOAD, [&] (GVariant *data) - { - int position = -1; - int row_height = 0; - int results_to_the_left = 0; - int results_to_the_right = 0; - g_variant_get(data, "(iiii)", &position, &row_height, &results_to_the_left, &results_to_the_right); - preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, position); - preview_state_machine_.left_results = results_to_the_left; - preview_state_machine_.right_results = results_to_the_right; - - if (opening_row_y_ == -1) - { - // Update only when opening the previews - opening_row_y_ = position; - } - opening_row_height_ = row_height; - - }); } long DashView::PostLayoutManagement (long LayoutResult) @@ -489,9 +497,40 @@ void DashView::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) renderer_.DrawFull(graphics_engine, content_geo_, GetAbsoluteGeometry(), GetGeometry(), true); } +/** + * Parametrically interpolates a value in one of two consecutive closed intervals. + * + * @param[in] p + * @param[in] start The left (least) value of the closed interval. + * @param[in] end1 The right (greatest) value of the closed interval, + * if start <= end1 + * @param[in] end2 The right (greatest) value of the closed interval, + * if start > end1 + * + * @returns the linear interpolation at @p p of the interval [start, end] where end + * is @p end1 if start <= @p end1, otherwise end is @end2. + */ +static float Interpolate2(float p, int start, int end1, int end2) +{ + float result = end2; + if (start < end2) + { + int end = start > end1 ? end2 : end1; + result = start + p * (end - start); + } + + return result; +} + void DashView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) { + auto& style = dash::Style::Instance(); + renderer_.DrawInner(graphics_engine, content_geo_, GetAbsoluteGeometry(), GetGeometry()); + + nux::Geometry clip_geo = layout_->GetGeometry(); + clip_geo.x += style.GetVSeparatorSize(); + graphics_engine.PushClippingRectangle(clip_geo); bool display_ghost = false; bool preview_redraw = false; @@ -641,7 +680,7 @@ void DashView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw graphics_engine.QRP_TexDesaturate( fade_out_value_ * layout_->GetX() + (1 - fade_out_value_) * final_x, - fade_out_value_ * (opening_row_y_ + opening_row_height_) + (1 - fade_out_value_) * final_y, + Interpolate2(1.0f - fade_out_value_, opening_row_y_ + opening_row_height_, final_y, layout_->GetHeight()), layout_->GetWidth() - filter_width, layout_->GetHeight() - opening_row_y_ - opening_row_height_, layout_copy_, texxform, @@ -724,7 +763,7 @@ void DashView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw graphics_engine.QRP_TexDesaturate( (1.0f - fade_in_value_) * layout_->GetX() + (fade_in_value_) * final_x, - (1.0f - fade_in_value_) * (opening_row_y_ + opening_row_height_) + (fade_in_value_) * final_y, + Interpolate2(fade_in_value_, opening_row_y_ + opening_row_height_, final_y, layout_->GetHeight()), layout_->GetWidth() - filter_width, layout_->GetHeight() - opening_row_y_ - opening_row_height_, layout_copy_, texxform, @@ -745,6 +784,8 @@ void DashView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw nux::GetPainter().PopBackgroundStack(); } + graphics_engine.PopClippingRectangle(); + renderer_.DrawInnerCleanup(graphics_engine, content_geo_, GetAbsoluteGeometry(), GetGeometry()); } @@ -886,12 +927,6 @@ void DashView::OnLensAdded(Lens::Ptr& lens) AddChild(view); view->SetVisible(false); view->uri_activated.connect(sigc::mem_fun(this, &DashView::OnUriActivated)); - view->uri_preview_activated.connect([&] (std::string const& uri, std::string const& unique_id) - { - LOG_DEBUG(logger) << "got unique id from preview activation: " << unique_id; - stored_preview_unique_id_ = unique_id; - stored_preview_uri_identifier_ = uri; - }); lenses_layout_->AddView(view, 1); lens_views_[lens->id] = view; @@ -1011,11 +1046,6 @@ void DashView::OnAppsGlobalSearchFinished(Lens::Hints const& hints) } } -void DashView::OnUriActivated(std::string const& uri) -{ - last_activated_uri_ = uri; -} - void DashView::OnUriActivatedReply(std::string const& uri, HandledType type, Lens::Hints const&) { // We don't want to close the dash if there was another activation pending @@ -1373,8 +1403,8 @@ nux::Area* DashView::FindKeyFocusArea(unsigned int key_symbol, if (direction == KEY_NAV_NONE) { - if (ui::KeyboardUtil::IsPrintableKeySymbol(x11_key_code) || - ui::KeyboardUtil::IsMoveKeySymbol(x11_key_code)) + if (keyboard::is_printable_key_symbol(x11_key_code) || + keyboard::is_move_key_symbol(x11_key_code)) { search_key = true; } diff --git a/dash/DashView.h b/dash/DashView.h index 43f7aca9f..7a1dca40d 100644 --- a/dash/DashView.h +++ b/dash/DashView.h @@ -92,7 +92,7 @@ private: void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw); virtual long PostLayoutManagement (long LayoutResult); nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type); - + void BuildPreview(Preview::Ptr model); void OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key); void OnBackgroundColorChanged(GVariant* args); @@ -103,7 +103,7 @@ private: void OnSearchFinished(Lens::Hints const& hints); void OnGlobalSearchFinished(Lens::Hints const& hints); void OnAppsGlobalSearchFinished(Lens::Hints const& hints); - void OnUriActivated(std::string const& uri); + void OnUriActivated(ResultView::ActivateType type, std::string const& uri, GVariant* data, std::string const& unique_id); void OnUriActivatedReply(std::string const& uri, HandledType type, Lens::Hints const&); bool DoFallbackActivation(std::string const& uri); bool LaunchApp(std::string const& appname); @@ -129,8 +129,7 @@ private: PreviewStateMachine preview_state_machine_; previews::PreviewContainer::Ptr preview_container_; bool preview_displaying_; - std::string stored_preview_unique_id_; - std::string stored_preview_uri_identifier_; + std::string stored_activated_unique_id_; dash::previews::Navigation preview_navigation_mode_; nux::VLayout* layout_; diff --git a/dash/LensView.cpp b/dash/LensView.cpp index c7177fb94..444905b50 100755 --- a/dash/LensView.cpp +++ b/dash/LensView.cpp @@ -22,6 +22,8 @@ #include <boost/lexical_cast.hpp> #include <NuxCore/Logger.h> +#include <Nux/HScrollBar.h> +#include <Nux/VScrollBar.h> #include "unity-shared/DashStyle.h" #include "CoverflowResultView.h" @@ -96,6 +98,14 @@ public: up_area_ = area; } + void RedrawScrollbars() + { + if (m_horizontal_scrollbar_enable) + _hscrollbar->QueueDraw(); + if (m_vertical_scrollbar_enable) + _vscrollbar->QueueDraw(); + } + protected: // This is so we can break the natural key navigation path. @@ -298,7 +308,7 @@ void LensView::OnCategoryAdded(Category const& category) if (existing_group->GetCategoryIndex() == index) return; } - PlacesGroup* group = new PlacesGroup(); + PlacesGroup* group = new PlacesGroup(dash::Style::Instance()); AddChild(group); group->SetName(name); group->SetIcon(icon_hint); @@ -344,18 +354,17 @@ void LensView::OnCategoryAdded(Category const& category) grid->expanded = false; group->SetRendererName(renderer_name.c_str()); - grid->UriActivated.connect(sigc::bind([&] (std::string const& uri, ResultView::ActivateType type, std::string const& view_id) + grid->UriActivated.connect(sigc::bind([&] (std::string const& uri, ResultView::ActivateType type, GVariant* data, std::string const& view_id) { + uri_activated.emit(type, uri, data, view_id); switch (type) { case ResultView::ActivateType::DIRECT: { - uri_activated.emit(uri); lens_->Activate(uri); } break; case ResultView::ActivateType::PREVIEW: { - uri_preview_activated.emit(uri, view_id); lens_->Preview(uri); } break; default: break; @@ -398,8 +407,6 @@ void LensView::OnCategoryAdded(Category const& category) scroll_layout_->AddView(group, 0, nux::MinorDimensionPosition::eAbove, nux::MinorDimensionSize::eFull, 100.0f, (nux::LayoutPosition)index); - - group->SetMinimumWidth(GetGeometry().width); } void LensView::OnCategoryOrderChanged() @@ -452,6 +459,13 @@ ResultViewGrid* LensView::GetGridForCategory(unsigned category_index) return static_cast<ResultViewGrid*>(group->GetChildView()); } +ResultView* LensView::GetResultViewForCategory(unsigned category_index) +{ + if (category_index >= categories_.size()) return nullptr; + PlacesGroup* group = categories_.at(category_index); + return static_cast<ResultView*>(group->GetChildView()); +} + void LensView::OnResultAdded(Result const& result) { try { @@ -662,6 +676,16 @@ void LensView::Draw(nux::GraphicsEngine& gfx_context, bool force_draw) nux::Geometry const& geo = GetGeometry(); gfx_context.PushClippingRectangle(geo); + + if (RedirectedAncestor()) + { + unsigned int alpha = 0, src = 0, dest = 0; + gfx_context.GetRenderStates().GetBlend(alpha, src, dest); + gfx_context.GetRenderStates().SetBlend(false); + gfx_context.QRP_Color(GetX(), GetY(), GetWidth(), GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); + gfx_context.GetRenderStates().SetBlend(alpha, src, dest); + } + nux::GetPainter().PaintBackground(gfx_context, geo); gfx_context.PopClippingRectangle(); } @@ -669,6 +693,22 @@ void LensView::Draw(nux::GraphicsEngine& gfx_context, bool force_draw) void LensView::DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw) { gfx_context.PushClippingRectangle(GetGeometry()); + + // This is necessary when doing redirected rendering. + // Clean the area below this view before drawing anything. + if (RedirectedAncestor() && !IsFullRedraw()) + { + // scrollbars are drawn in Draw, not DrawContent, so we need to flag them to redraw. + scroll_view_->RedrawScrollbars(); + fscroll_view_->RedrawScrollbars(); + + unsigned int alpha = 0, src = 0, dest = 0; + gfx_context.GetRenderStates().GetBlend(alpha, src, dest); + gfx_context.GetRenderStates().SetBlend(false); + gfx_context.QRP_Color(GetX(), GetY(), GetWidth(), GetHeight(), nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); + gfx_context.GetRenderStates().SetBlend(alpha, src, dest); + } + layout_->ProcessDraw(gfx_context, force_draw); gfx_context.PopClippingRectangle(); } @@ -720,22 +760,22 @@ void LensView::ActivateFirst() for (unsigned int i = 0; i < category_order.size(); i++) { unsigned cat_index = category_order.at(i); - ResultViewGrid* grid = GetGridForCategory(cat_index); - if (grid == nullptr) continue; - auto it = grid->GetIteratorAtRow(0); + ResultView* result_view = GetResultViewForCategory(cat_index); + if (result_view == nullptr) continue; + auto it = result_view->GetIteratorAtRow(0); if (!it.IsLast()) { Result result(*it); - uri_activated(result.uri); - lens_->Activate(result.uri); + result_view->Activate(result.uri, result_view->GetIndexForUri(result.uri), ResultView::ActivateType::DIRECT); return; } } + // Fallback Result result = results->RowAtIndex(0); if (result.uri != "") { - uri_activated(result.uri); + uri_activated.emit(ResultView::ActivateType::DIRECT, result.uri, nullptr, ""); lens_->Activate(result.uri); } } diff --git a/dash/LensView.h b/dash/LensView.h index 01a46b45f..71da4c9df 100644 --- a/dash/LensView.h +++ b/dash/LensView.h @@ -68,8 +68,7 @@ public: nux::Property<ViewType> view_type; nux::Property<bool> can_refine_search; - sigc::signal<void, std::string const&> uri_activated; - sigc::signal<void, std::string const&, std::string const&> uri_preview_activated; + sigc::signal<void, ResultView::ActivateType, std::string const&, GVariant*, std::string const&> uri_activated; void PerformSearch(std::string const& search_query); void CheckNoResults(Lens::Hints const& hints); @@ -95,6 +94,7 @@ private: void OnViewTypeChanged(ViewType view_type); bool ReinitializeFilterModels(); ResultViewGrid* GetGridForCategory(unsigned category_index); + ResultView* GetResultViewForCategory(unsigned category_index); void BuildPreview(std::string const& uri, Preview::Ptr model); diff --git a/dash/PlacesGroup.cpp b/dash/PlacesGroup.cpp index f920bd1c2..43031695e 100755 --- a/dash/PlacesGroup.cpp +++ b/dash/PlacesGroup.cpp @@ -31,8 +31,6 @@ #include <UnityCore/GLibWrapper.h> #include "unity-shared/StaticCairoText.h" -#include "unity-shared/DashStyle.h" -#include "unity-shared/LineSeparator.h" #include "unity-shared/ubus-server.h" #include "unity-shared/UBusMessages.h" @@ -112,8 +110,9 @@ protected: NUX_IMPLEMENT_OBJECT_TYPE(PlacesGroup); -PlacesGroup::PlacesGroup() +PlacesGroup::PlacesGroup(dash::StyleInterface& style) : nux::View(NUX_TRACKER_LOCATION), + _style(style), _child_view(nullptr), _is_expanded(false), _n_visible_items_in_unexpand_mode(0), @@ -122,15 +121,13 @@ PlacesGroup::PlacesGroup() _coverflow_enabled(false), disabled_header_count_(false) { - dash::Style& style = dash::Style::Instance(); - SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(false); - nux::BaseTexture* arrow = style.GetGroupUnexpandIcon(); + nux::BaseTexture* arrow = _style.GetGroupExpandIcon(); - _background = style.GetCategoryBackground(); - _background_nofilters = style.GetCategoryBackgroundNoFilters(); + _background = _style.GetCategoryBackground(); + _background_nofilters = _style.GetCategoryBackgroundNoFilters(); nux::ROPConfig rop; rop.Blend = true; @@ -154,7 +151,7 @@ PlacesGroup::PlacesGroup() _group_layout->AddView(_header_view, 0, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_FULL); _header_layout = new nux::HLayout(NUX_TRACKER_LOCATION); - _header_layout->SetLeftAndRightPadding(style.GetCategoryHeaderLeftPadding(), 0); + _header_layout->SetLeftAndRightPadding(_style.GetCategoryHeaderLeftPadding(), 0); _header_layout->SetSpaceBetweenChildren(10); _header_view->SetLayout(_header_layout); @@ -449,7 +446,7 @@ long PlacesGroup::ComputeContentSize() // only the width matters if (_cached_geometry.GetWidth() != geo.GetWidth()) { - _focus_layer.reset(dash::Style::Instance().FocusOverlay(geo.width - kHighlightLeftPadding - kHighlightRightPadding, kHighlightHeight)); + _focus_layer.reset(_style.FocusOverlay(geo.width - kHighlightLeftPadding - kHighlightRightPadding, kHighlightHeight)); _cached_geometry = geo; } return ret; @@ -512,11 +509,6 @@ PlacesGroup::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) } -void PlacesGroup::PostDraw(nux::GraphicsEngine& graphics_engine, - bool forceDraw) -{ -} - void PlacesGroup::SetCategoryIndex(unsigned index) { @@ -557,11 +549,10 @@ PlacesGroup::SetExpanded(bool is_expanded) Refresh(); - dash::Style& style = dash::Style::Instance(); if (_is_expanded) - _expand_icon->SetTexture(style.GetGroupUnexpandIcon()); + _expand_icon->SetTexture(_style.GetGroupUnexpandIcon()); else - _expand_icon->SetTexture(style.GetGroupExpandIcon()); + _expand_icon->SetTexture(_style.GetGroupExpandIcon()); expanded.emit(this); } diff --git a/dash/PlacesGroup.h b/dash/PlacesGroup.h index 45d321bba..6f068b952 100644 --- a/dash/PlacesGroup.h +++ b/dash/PlacesGroup.h @@ -28,6 +28,7 @@ #include <sigc++/sigc++.h> +#include "unity-shared/DashStyleInterface.h" #include "unity-shared/IconTexture.h" #include "unity-shared/Introspectable.h" #include "unity-shared/StaticCairoText.h" @@ -53,7 +54,7 @@ class PlacesGroup : public nux::View, public debug::Introspectable NUX_DECLARE_OBJECT_TYPE(PlacesGroup, nux::View); public: - PlacesGroup(); + PlacesGroup(dash::StyleInterface& style); void SetIcon(std::string const& icon); void SetName(std::string const& name); @@ -90,7 +91,6 @@ protected: long ComputeContentSize(); void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw); void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw); - void PostDraw (nux::GraphicsEngine &graphics_engine, bool force_draw); // Key navigation virtual bool AcceptKeyNavFocus(); @@ -115,6 +115,8 @@ private: void RefreshLabel(); private: + dash::StyleInterface& _style; + nux::VLayout* _group_layout; nux::View* _header_view; nux::HLayout* _header_layout; diff --git a/dash/PreviewStateMachine.cpp b/dash/PreviewStateMachine.cpp index c2fe3e42c..1d667820e 100644 --- a/dash/PreviewStateMachine.cpp +++ b/dash/PreviewStateMachine.cpp @@ -50,10 +50,8 @@ PreviewStateMachine::~PreviewStateMachine() void PreviewStateMachine::ActivatePreview(Preview::Ptr preview) { stored_preview_ = preview; - CheckPreviewRequirementsFulfilled(); - left_results = -1; - right_results = -1; requires_activation_ = true; + CheckPreviewRequirementsFulfilled(); } void PreviewStateMachine::Reset() @@ -66,8 +64,7 @@ void PreviewStateMachine::Reset() void PreviewStateMachine::ClosePreview() { - stored_preview_ = nullptr; - preview_active = true; + Reset(); SetSplitPosition(SplitPosition::CONTENT_AREA, -1); } @@ -88,7 +85,10 @@ void PreviewStateMachine::CheckPreviewRequirementsFulfilled() return; if (stored_preview_ == nullptr) + { + requires_activation_ = true; return; + } /* right now this is disabled as long as we aren't doing the fancy splitting animation * as we don't care about positions diff --git a/dash/ResultView.cpp b/dash/ResultView.cpp index 13effa95f..c14fe6dd7 100644 --- a/dash/ResultView.cpp +++ b/dash/ResultView.cpp @@ -28,6 +28,7 @@ #include <Nux/VLayout.h> #include <Nux/Button.h> #include <NuxCore/Logger.h> +#include <UnityCore/Variant.h> namespace unity { @@ -238,7 +239,7 @@ debug::Introspectable::IntrospectableList ResultView::GetIntrospectableChildren( { Result const& result = *iter; - debug::Introspectable* result_wrapper = NULL; + debug::ResultWrapper* result_wrapper = NULL; auto map_iter = introspectable_children_.find(result.uri); // Create new result. if (map_iter == introspectable_children_.end()) @@ -247,7 +248,10 @@ debug::Introspectable::IntrospectableList ResultView::GetIntrospectableChildren( introspectable_children_[result.uri] = result_wrapper; } else + { result_wrapper = map_iter->second; + UpdateResultWrapper(result_wrapper, result, index); + } AddChild(result_wrapper); @@ -275,10 +279,14 @@ debug::Introspectable::IntrospectableList ResultView::GetIntrospectableChildren( return debug::Introspectable::GetIntrospectableChildren(); } -debug::Introspectable* ResultView::CreateResultWrapper(Result const& result, int index) +debug::ResultWrapper* ResultView::CreateResultWrapper(Result const& result, int index) { return new debug::ResultWrapper(result); } +void ResultView::UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index) +{ +} + } } diff --git a/dash/ResultView.h b/dash/ResultView.h index 97c9c8796..9fdcc0b83 100644 --- a/dash/ResultView.h +++ b/dash/ResultView.h @@ -36,6 +36,11 @@ namespace unity { +namespace debug +{ +class ResultWrapper; +} + namespace dash { class ResultView : public nux::View, public debug::Introspectable @@ -61,13 +66,15 @@ public: nux::Property<bool> expanded; nux::Property<int> results_per_row; nux::Property<std::string> unique_id; - sigc::signal<void, std::string const&, ActivateType> UriActivated; + sigc::signal<void, std::string const&, ActivateType, GVariant*> UriActivated; std::string GetName() const; ResultIterator GetIteratorAtRow(unsigned row); void AddProperties(GVariantBuilder* builder); IntrospectableList GetIntrospectableChildren(); + virtual void Activate(std::string const& uri, int index, ActivateType type) = 0; + protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); @@ -79,14 +86,15 @@ protected: unsigned GetNumResults(); static void ChildResultDestructor(debug::Introspectable* child); - virtual debug::Introspectable* CreateResultWrapper(Result const& result, int index); + virtual debug::ResultWrapper* CreateResultWrapper(Result const& result, int index); + virtual void UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index); // properties ResultRenderer* renderer_; glib::Object<DeeModel> result_model_; DeeModelTag* renderer_tag_; glib::SignalManager sig_manager_; - std::map<std::string, debug::Introspectable*> introspectable_children_; + std::map<std::string, debug::ResultWrapper*> introspectable_children_; private: void OnRowAdded(DeeModel* model, DeeModelIter* iter); diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index 840455f0c..c2757410a 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -28,6 +28,7 @@ #include <gdk/gdk.h> #include <unity-protocol.h> +#include <UnityCore/Variant.h> #include "unity-shared/IntrospectableWrappers.h" #include "unity-shared/Timer.h" #include "unity-shared/ubus-server.h" @@ -75,7 +76,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) key_nav_focus_change.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyNavFocusChange)); key_nav_focus_activate.connect([&] (nux::Area *area) { - UriActivated.emit (focused_uri_, ResultView::ActivateType::DIRECT); + Activate(focused_uri_, selected_index_, ResultView::ActivateType::DIRECT); }); key_down.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyDown)); mouse_move.connect(sigc::mem_fun(this, &ResultViewGrid::MouseMove)); @@ -140,30 +141,9 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) { activated_uri_ = GetUriForIndex(current_index); LOG_DEBUG(logger) << "activating preview for index: " - << "(" << current_index << ")" - << " " << activated_uri_; - int left_results = current_index; - int right_results = num_results ? (num_results - current_index) - 1 : 0; - - int row_y = padding + GetRootGeometry().y; - int row_size = renderer_->height + vertical_spacing; - int row_height = row_size; - - if (GetItemsPerRow()) - { - int num_row = GetNumResults() / GetItemsPerRow(); - if (GetNumResults() % GetItemsPerRow()) - { - ++num_row; - } - int row_index = current_index / GetItemsPerRow(); - - row_y += row_index * row_size; - } - - ubus_.SendMessage(UBUS_DASH_PREVIEW_INFO_PAYLOAD, - g_variant_new("(iiii)", row_y, row_height, left_results, right_results)); - UriActivated.emit(activated_uri_, ActivateType::PREVIEW); + << "(" << current_index << ")" + << " " << activated_uri_; + Activate(activated_uri_, current_index, ActivateType::PREVIEW); } } @@ -176,6 +156,33 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) SetDndEnabled(true, false); } +void ResultViewGrid::Activate(std::string const& uri, int index, ResultView::ActivateType type) +{ + unsigned num_results = GetNumResults(); + + int left_results = index; + int right_results = num_results ? (num_results - index) - 1 : 0; + //FIXME - just uses y right now, needs to use the absolute position of the bottom of the result + // (jay) Here is the fix: Compute the y position of the row where the item is located. + int row_y = padding + GetRootGeometry().y; + int row_height = renderer_->height + vertical_spacing; + + if (GetItemsPerRow()) + { + int num_row = GetNumResults() / GetItemsPerRow(); + if (GetNumResults() % GetItemsPerRow()) + { + ++num_row; + } + int row_index = index / GetItemsPerRow(); + + row_y += row_index * row_height; + } + + glib::Variant data(g_variant_new("(iiii)", row_y, row_height, left_results, right_results)); + UriActivated.emit(uri, type, data); +} + void ResultViewGrid::QueueLazyLoad() { lazy_load_source_.reset(new glib::Idle(glib::Source::Priority::DEFAULT)); @@ -483,12 +490,7 @@ void ResultViewGrid::OnKeyDown (unsigned long event_type, unsigned long event_ke if (event_type == nux::NUX_KEYDOWN && event_keysym == XK_Menu) { - UriActivated.emit (focused_uri_, ResultView::ActivateType::PREVIEW); - int left_results = selected_index_; - int right_results = (num_results - selected_index_) - 1; - //FIXME - just uses y right now, needs to use the absolute position of the bottom of the result - ubus_.SendMessage(UBUS_DASH_PREVIEW_INFO_PAYLOAD, - g_variant_new("(iii)", mouse_last_y_, left_results, right_results)); + Activate(focused_uri_, selected_index_, ActivateType::PREVIEW); } } @@ -715,36 +717,12 @@ void ResultViewGrid::MouseClick(int x, int y, unsigned long button_flags, unsign Result result = *it; selected_index_ = index; focused_uri_ = result.uri; - if (nux::GetEventButton(button_flags) == nux::MouseButton::MOUSE_BUTTON3) - { - activated_uri_ = result.uri(); - UriActivated.emit(result.uri, ResultView::ActivateType::PREVIEW); - int left_results = index; - int right_results = (num_results - index) - 1; - //FIXME - just uses y right now, needs to use the absolute position of the bottom of the result - // (jay) Here is the fix: Compute the y position of the row where the item is located. - int row_y = padding + GetRootGeometry().y; - int row_size = renderer_->height + vertical_spacing; - int row_height = row_size; - - if (GetItemsPerRow()) - { - int num_row = GetNumResults() / GetItemsPerRow(); - if (GetNumResults() % GetItemsPerRow()) - { - ++num_row; - } - int row_index = index / GetItemsPerRow(); - row_y += row_index * row_size; - } - ubus_.SendMessage(UBUS_DASH_PREVIEW_INFO_PAYLOAD, - g_variant_new("(iiii)", row_y, row_height, left_results, right_results)); - } - else - { - UriActivated.emit(result.uri, ResultView::ActivateType::DIRECT); - } + ActivateType type = nux::GetEventButton(button_flags) == nux::MouseButton::MOUSE_BUTTON3 ? ResultView::ActivateType::PREVIEW : + ResultView::ActivateType::DIRECT; + + activated_uri_ = result.uri(); + Activate(activated_uri_, index, type); } } @@ -980,7 +958,7 @@ ResultViewGrid::GetSelectedIndex() return selected_index_; } -debug::Introspectable* ResultViewGrid::CreateResultWrapper(Result const& result, int index) +debug::ResultWrapper* ResultViewGrid::CreateResultWrapper(Result const& result, int index) { int x_offset = GetAbsoluteX(); int y_offset = GetAbsoluteY(); @@ -994,6 +972,24 @@ debug::Introspectable* ResultViewGrid::CreateResultWrapper(Result const& result, return new debug::ResultWrapper(result, geo); } +void ResultViewGrid::UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index) +{ + if (!wrapper) + return; + + int x_offset = GetAbsoluteX(); + int y_offset = GetAbsoluteY(); + + std::tuple<int, int> result_coord = GetResultPosition(index); + + nux::Geometry geo(std::get<0>(result_coord) + x_offset, + std::get<1>(result_coord) + y_offset, + renderer_->width, + renderer_->height); + + wrapper->UpdateGeometry(geo); +} + } } diff --git a/dash/ResultViewGrid.h b/dash/ResultViewGrid.h index 2e50adf63..8a9b4618a 100644 --- a/dash/ResultViewGrid.h +++ b/dash/ResultViewGrid.h @@ -52,6 +52,8 @@ public: int GetSelectedIndex(); virtual unsigned GetIndexAtPosition(int x, int y); + + virtual void Activate(std::string const& uri, int index, ActivateType type); protected: void MouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); @@ -77,7 +79,8 @@ protected: void RemoveResult(Result& result); // This is overridden so we can include position of results. - virtual debug::Introspectable* CreateResultWrapper(Result const& result, int index); + virtual debug::ResultWrapper* CreateResultWrapper(Result const& result, int index); + virtual void UpdateResultWrapper(debug::ResultWrapper* wrapper, Result const& result, int index); private: typedef std::tuple <int, int> ResultListBounds; diff --git a/dash/StandaloneDash.cpp b/dash/StandaloneDash.cpp index cbc38743c..3b7fa1264 100644 --- a/dash/StandaloneDash.cpp +++ b/dash/StandaloneDash.cpp @@ -21,9 +21,11 @@ #include <gtk/gtk.h> #include "Nux/Nux.h" +#include "Nux/NuxTimerTickSource.h" #include "Nux/VLayout.h" #include "Nux/WindowThread.h" #include "NuxGraphics/GraphicsEngine.h" +#include <NuxCore/AnimationController.h> #include <NuxCore/Logger.h> #include "unity-shared/BGHash.h" @@ -101,6 +103,9 @@ int main(int argc, char **argv) &TestRunner::InitWindowThread, test_runner); + nux::NuxTimerTickSource tick_source; + nux::animation::AnimationController animation_controller(tick_source); + wt->Run (NULL); delete wt; return 0; diff --git a/dash/previews/ActionButton.cpp b/dash/previews/ActionButton.cpp index 7c392787f..76582f6a4 100644 --- a/dash/previews/ActionButton.cpp +++ b/dash/previews/ActionButton.cpp @@ -199,7 +199,7 @@ void ActionButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::Butt void ActionButton::RedrawFocusOverlay(nux::Geometry const& geom, cairo_t* cr) { - Style::Instance().ButtonFocusOverlay(cr); + Style::Instance().ButtonFocusOverlay(cr, 0.20f); } long ActionButton::ComputeContentSize() diff --git a/dash/previews/PreviewContainer.cpp b/dash/previews/PreviewContainer.cpp index 191e75131..e6d78b426 100644 --- a/dash/previews/PreviewContainer.cpp +++ b/dash/previews/PreviewContainer.cpp @@ -47,11 +47,8 @@ namespace { nux::logging::Logger logger("unity.dash.previews.previewcontainer"); - - -const int ANIM_DURATION_SHORT_SHORT = 100; -const int ANIM_DURATION = 200; const int ANIM_DURATION_LONG = 500; +const int PREVIEW_SPINNER_WAIT = 300; const std::string ANIMATION_IDLE = "animation-idle"; } @@ -99,11 +96,10 @@ public: void PushPreview(previews::Preview::Ptr preview, Navigation direction) { - preview_initiate_count_++; - StopPreviewWait(); - if (preview) { + preview_initiate_count_++; + StopPreviewWait(); // the parents layout will not change based on the previews. preview->SetReconfigureParentLayoutOnGeometryChange(false); @@ -111,6 +107,11 @@ public: AddView(preview.GetPointer()); preview->SetVisible(false); } + else + { + // if we push a null preview, then start waiting. + StartPreviewWait(); + } PreviewSwipe swipe; swipe.direction = direction; swipe.preview = preview; @@ -227,7 +228,7 @@ public: void StartPreviewWait() { - preview_wait_timer_.reset(new glib::Timeout(300, [&] () { + preview_wait_timer_.reset(new glib::Timeout(PREVIEW_SPINNER_WAIT, [&] () { if (waiting_preview_) return false; diff --git a/dash/previews/SocialPreviewContent.cpp b/dash/previews/SocialPreviewContent.cpp index f1f476241..7b224e686 100644 --- a/dash/previews/SocialPreviewContent.cpp +++ b/dash/previews/SocialPreviewContent.cpp @@ -38,14 +38,19 @@ namespace previews namespace { nux::logging::Logger logger("unity.dash.previews.socialpreviewcontent"); + +const int BUBBLE_WIDTH = 300; +const int BUBBLE_HEIGHT = 250; +const int TAIL_HEIGHT = 50; +const int TAIL_POS_FROM_RIGHT = 60; } inline nux::Geometry GetBubbleGeometry(nux::Geometry const& geo) { - return nux::Geometry(geo.x + geo.width*0.1, - geo.y + geo.height*0.1, - geo.width - 2*(geo.width*0.1), - geo.height - 2*(geo.height*0.1)); + int width = MIN(BUBBLE_WIDTH, geo.width); + int height = MIN(BUBBLE_HEIGHT + TAIL_HEIGHT, geo.height); + + return nux::Geometry(geo.x + (geo.width - width)/2, geo.y + (geo.height - height)/2, width, height); } NUX_IMPLEMENT_OBJECT_TYPE(SocialPreviewContent); @@ -98,7 +103,7 @@ void SocialPreviewContent::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw tex->GetHeight(), tex, texxform, - nux::Color(0.2f, 0.2f, 0.2f, 0.2f)); + nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); @@ -145,10 +150,8 @@ void SocialPreviewContent::UpdateBaloonTexture() nux::Geometry geo_cr(GetBubbleGeometry(geo)); - double tail_width = MAX(0, MIN(geo_cr.width - 2*15.0, MIN(geo_cr.width*0.125, geo_cr.height*0.125))); - int max_width = geo_cr.width - 2*(geo_cr.width*0.1); - int max_height = geo_cr.height - 2*(geo_cr.height*0.1) - tail_width; + int max_height = (geo_cr.height - TAIL_HEIGHT) - 2*((geo_cr.height - TAIL_HEIGHT)*0.1); // this will update the texture with the actual size of the text. text_->SetMaximumHeight(max_height); @@ -156,8 +159,8 @@ void SocialPreviewContent::UpdateBaloonTexture() nux::Geometry const& geo_text = text_->GetGeometry(); // center text - text_->SetBaseX(geo.x + geo.width/2 - geo_text.width/2); - text_->SetBaseY(geo.y + geo.height/2 - geo_text.height/2 - tail_width/2); + text_->SetBaseX(geo_cr.x + geo_cr.width/2 - geo_text.width/2); + text_->SetBaseY(geo_cr.y + geo_cr.height/2 - geo_text.height/2 - TAIL_HEIGHT/2); if (geo_cr.width > 0 && geo_cr.height > 0) { @@ -167,21 +170,18 @@ void SocialPreviewContent::UpdateBaloonTexture() void SocialPreviewContent::RedrawBubble(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state) { - double blur = 4.0; + double line_width = 6.0; + double radius = 28.0; + double x = 0.0; + double y = 0.0; - double line_width = 1.0; - double radius = 20.0; - double tailWidthPercentage = 0.125; - double tailPositionPercentage = 0.7; - double x = 0.0 + blur; - double y = 0.0 + blur; - double width = cairo_image_surface_get_width(cairo_get_target(cr)) - 2*blur; - double height = cairo_image_surface_get_height(cairo_get_target(cr)) - 2*blur; + double width = MAX(0, cairo_image_surface_get_width(cairo_get_target(cr))); + double height = MAX(0, cairo_image_surface_get_height(cairo_get_target(cr)) - TAIL_HEIGHT); + double tailPosition = x + width - TAIL_POS_FROM_RIGHT - TAIL_HEIGHT; if (width > 0 && height > 0) { - DrawBubble(cr, line_width, radius, x, y, width, height, tailPositionPercentage, tailWidthPercentage); - dash::Style::Instance().Blur(cr, blur); + DrawBubble(cr, line_width, radius, x, y, width, height, tailPosition, TAIL_HEIGHT); } } @@ -214,8 +214,8 @@ void SocialPreviewContent::DrawBubble(cairo_t* cr, double y, double width, double height, - double tailPositionPercentage, - double tailWidthPercentage) + double tailPosition, + double tailWidth) { // sanity check if (cairo_status(cr) != CAIRO_STATUS_SUCCESS && @@ -224,16 +224,6 @@ void SocialPreviewContent::DrawBubble(cairo_t* cr, cairo_set_line_width(cr, line_width); - double tailWidth = MAX(0, MIN(width - 2*radius, MIN(width*tailWidthPercentage, height*tailWidthPercentage))); - double tail_start_pos = x + tailPositionPercentage*width - tailWidth/2; - - // recitfications for outer draw. - x += line_width/2; - y += line_width/2; - height -= line_width; - height -= tailWidth; - width -= line_width; - bool odd = true; odd = line_width != double((int)line_width); @@ -262,16 +252,16 @@ void SocialPreviewContent::DrawBubble(cairo_t* cr, 0.0f * G_PI / 180.0f, 90.0f * G_PI / 180.0f); - if (tailWidth > 0.0) + if (tailWidth > 0.0 && tailPosition > 0 && tailPosition <= (x + width - tailWidth - radius)) { // tail-right, tail top - cairo_line_to(cr, _align(tail_start_pos + tailWidth, odd), _align(y + height, odd)); + cairo_line_to(cr, _align(tailPosition + tailWidth, odd), _align(y + height, odd)); // tail-right, tail bottom - cairo_line_to(cr, _align(tail_start_pos + tailWidth, odd), _align(y + height + tailWidth, odd)); + cairo_line_to(cr, _align(tailPosition + tailWidth, odd), _align(y + height + tailWidth, odd)); // tail-right, tail bottom - cairo_line_to(cr, _align(tail_start_pos, odd), _align(y + height, odd)); + cairo_line_to(cr, _align(tailPosition, odd), _align(y + height, odd)); } // bottom-left, right of the corner @@ -293,14 +283,13 @@ void SocialPreviewContent::DrawBubble(cairo_t* cr, 180.0f * G_PI / 180.0f, 270.0f * G_PI / 180.0f); + nux::Color color_fill(1.0, 1.0, 1.0, 0.2); + cairo_set_source_rgba(cr, color_fill.red, color_fill.green, color_fill.blue, color_fill.alpha); + cairo_fill_preserve(cr); - nux::Color color(0.53, 1.0, 0.66, 0.5); - if (color.alpha != 0.0) - { - cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha); - cairo_fill_preserve(cr); - } - cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha); + cairo_set_operator(cr, CAIRO_OPERATOR_DEST_OUT); + nux::Color color_stroke(1.0, 1.0, 1.0, 0.5); + cairo_set_source_rgba(cr, color_stroke.red, color_stroke.green, color_stroke.blue, color_stroke.alpha); cairo_stroke(cr); } diff --git a/dash/previews/SocialPreviewContent.h b/dash/previews/SocialPreviewContent.h index 8dedef436..308a99e32 100644 --- a/dash/previews/SocialPreviewContent.h +++ b/dash/previews/SocialPreviewContent.h @@ -66,8 +66,8 @@ protected: double y, double width, double height, - double tailPositionPercentage, - double tailWidthPercentage); + double tailPosition, + double tailWidth); virtual std::string GetName() const; virtual void AddProperties(GVariantBuilder* builder); |
