From 4a1c3c4f83ee1f3ba4b0bc63d3d82b7a698df519 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Fri, 16 Aug 2013 16:47:25 +0200 Subject: [PATCH] More UI stuff, add glMapBuffer --- android/app-android.cpp | 16 ++++++++++++++++ base/colorutil.h | 1 + gfx_es2/gl_state.cpp | 7 ++++++- gfx_es2/gl_state.h | 2 ++ input/keycodes.h | 5 +++++ ui/ui_screen.cpp | 12 ++++++++---- ui/ui_screen.h | 7 ++++--- ui/view.cpp | 25 ++++++++++++------------- ui/view.h | 12 +++++++++--- ui/viewgroup.cpp | 20 +++++++++++++++----- 10 files changed, 78 insertions(+), 29 deletions(-) diff --git a/android/app-android.cpp b/android/app-android.cpp index 446ed77dcd..faa4d4494e 100644 --- a/android/app-android.cpp +++ b/android/app-android.cpp @@ -456,6 +456,22 @@ extern "C" void JNICALL Java_com_henrikrydgard_libnative_NativeApp_accelerometer input_state.acc.x = x; input_state.acc.y = y; input_state.acc.z = z; + + AxisInput axis; + axis.deviceId = DEVICE_ID_ACCELEROMETER; + axis.flags = 0; + + axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X; + axis.value = x; + NativeAxis(axis); + + axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y; + axis.value = y; + NativeAxis(axis); + + axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z; + axis.value = z; + NativeAxis(axis); } extern "C" void Java_com_henrikrydgard_libnative_NativeApp_sendMessage(JNIEnv *env, jclass, jstring message, jstring param) { diff --git a/base/colorutil.h b/base/colorutil.h index 61d6f8b127..cc5d27bcaf 100644 --- a/base/colorutil.h +++ b/base/colorutil.h @@ -5,6 +5,7 @@ uint32_t whiteAlpha(float alpha); uint32_t blackAlpha(float alpha); uint32_t colorAlpha(uint32_t color, float alpha); +uint32_t colorBlend(uint32_t color, uint32_t color2, float alpha); uint32_t alphaMul(uint32_t color, float alphaMul); uint32_t rgba(float r, float g, float b, float alpha); uint32_t rgba_clamp(float r, float g, float b, float alpha); diff --git a/gfx_es2/gl_state.cpp b/gfx_es2/gl_state.cpp index 0391639d0a..e0a61f9ddb 100644 --- a/gfx_es2/gl_state.cpp +++ b/gfx_es2/gl_state.cpp @@ -9,6 +9,7 @@ PFNGLALPHAFUNCQCOMPROC glAlphaFuncQCOM; PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC eglGetSystemTimeFrequencyNV; PFNEGLGETSYSTEMTIMENVPROC eglGetSystemTimeNV; +PFNGLMAPBUFFERPROC glMapBuffer; #endif #if !defined(IOS) && !defined(__SYMBIAN32__) && !defined(MEEGO_EDITION_HARMATTAN) PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT; @@ -95,7 +96,6 @@ void CheckGLExtensions() { gl_extensions.OES_depth24 = strstr(extString, "GL_OES_depth24") != 0; gl_extensions.OES_depth_texture = strstr(extString, "GL_OES_depth_texture") != 0; gl_extensions.OES_mapbuffer = strstr(extString, "GL_OES_mapbuffer") != 0; - #if defined(IOS) || defined(__SYMBIAN32__) || defined(MEEGO_EDITION_HARMATTAN) gl_extensions.OES_vertex_array_object = false; gl_extensions.EXT_discard_framebuffer = false; @@ -113,10 +113,15 @@ void CheckGLExtensions() { if (gl_extensions.EXT_discard_framebuffer) { glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXTPROC)eglGetProcAddress("glDiscardFramebufferEXT"); } + #endif #endif #ifdef ANDROID + if (gl_extensions.OES_mapbuffer) { + glMapBuffer = (PFNGLMAPBUFFERPROC)eglGetProcAddress( "glMapBufferOES" ); + } + gl_extensions.QCOM_alpha_test = strstr(extString, "GL_QCOM_alpha_test") != 0; // Load extensions that are not auto-loaded by Android. if (gl_extensions.QCOM_alpha_test) { diff --git a/gfx_es2/gl_state.h b/gfx_es2/gl_state.h index a6ae8885a3..1d692435bc 100644 --- a/gfx_es2/gl_state.h +++ b/gfx_es2/gl_state.h @@ -23,6 +23,8 @@ typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void); extern PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC eglGetSystemTimeFrequencyNV; extern PFNEGLGETSYSTEMTIMENVPROC eglGetSystemTimeNV; +typedef GLvoid* (GL_APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access); +extern PFNGLMAPBUFFERPROC glMapBuffer; #endif #if !defined(IOS) && !defined(__SYMBIAN32__) && !defined(MEEGO_EDITION_HARMATTAN) diff --git a/input/keycodes.h b/input/keycodes.h index e9a128937e..97ce3453b9 100644 --- a/input/keycodes.h +++ b/input/keycodes.h @@ -281,4 +281,9 @@ enum AndroidJoystickAxis { // Relative mouse axis for PC. JOYSTICK_AXIS_MOUSE_REL_X = 26, JOYSTICK_AXIS_MOUSE_REL_Y = 27, + + // Mobile device accelerometer/gyro + JOYSTICK_AXIS_ACCELEROMETER_X, + JOYSTICK_AXIS_ACCELEROMETER_Y, + JOYSTICK_AXIS_ACCELEROMETER_Z, }; diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index 39df32a739..49ebb23992 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -122,14 +122,18 @@ void PopupScreen::CreateViews() { if (ShowButtons()) { // And the two buttons at the bottom. - ViewGroup *buttonRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(200, WRAP_CONTENT)); + LinearLayout *buttonRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(200, WRAP_CONTENT)); + buttonRow->SetSpacing(0); + Margins buttonMargins(5, 5); // Adjust button order to the platform default. #if defined(_WIN32) - buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK); - buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel); + buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f, buttonMargins)))->OnClick.Handle(this, &PopupScreen::OnOK); + if (!button2_.empty()) + buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f, buttonMargins)))->OnClick.Handle(this, &PopupScreen::OnCancel); #else - buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel); + if (!button2_.empty()) + buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel); buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK); #endif diff --git a/ui/ui_screen.h b/ui/ui_screen.h index 9f323524a3..f1999f6c70 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -92,16 +92,17 @@ protected: virtual bool FillVertical() { return false; } virtual bool ShowButtons() { return true; } void CreatePopupContents(UI::ViewGroup *parent); - virtual void OnCompleted(DialogResult result); private: std::string message_; std::function callback_; }; +// TODO: Need a way to translate OK and Cancel + class SliderPopupScreen : public PopupScreen { public: - SliderPopupScreen(int *value, int minValue, int maxValue, const std::string &title) : PopupScreen(title), value_(value), minValue_(minValue), maxValue_(maxValue) {} + SliderPopupScreen(int *value, int minValue, int maxValue, const std::string &title) : PopupScreen(title, "OK", "Cancel"), value_(value), minValue_(minValue), maxValue_(maxValue) {} void CreatePopupContents(UI::ViewGroup *parent); private: @@ -115,7 +116,7 @@ private: class SliderFloatPopupScreen : public PopupScreen { public: - SliderFloatPopupScreen(float *value, float minValue, float maxValue, const std::string &title) : PopupScreen(title), value_(value), minValue_(minValue), maxValue_(maxValue) {} + SliderFloatPopupScreen(float *value, float minValue, float maxValue, const std::string &title) : PopupScreen(title, "OK", "Cancel"), value_(value), minValue_(minValue), maxValue_(maxValue) {} void CreatePopupContents(UI::ViewGroup *parent); private: diff --git a/ui/view.cpp b/ui/view.cpp index fa2154e297..caae38cdbc 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -250,8 +250,6 @@ void StickyChoice::FocusChanged(int focusFlags) { // Override Clickable's FocusChanged to do nothing. } - - Item::Item(LayoutParams *layoutParams) : InertView(layoutParams) { layoutParams_->width = FILL_PARENT; layoutParams_->height = ITEM_HEIGHT; @@ -275,24 +273,25 @@ ClickableItem::ClickableItem(LayoutParams *layoutParams) : Clickable(layoutParam void ClickableItem::Draw(UIContext &dc) { Style style = dc.theme->itemStyle; - if (down_) { - style = dc.theme->itemDownStyle; - } else if (HasFocus()) { + if (HasFocus()) { style = dc.theme->itemFocusedStyle; } + if (down_) { + style = dc.theme->itemDownStyle; + } dc.FillRect(style.background, bounds_); } void Choice::GetContentDimensions(const UIContext &dc, float &w, float &h) const { dc.Draw()->MeasureText(dc.theme->uiFont, text_.c_str(), &w, &h); - w += 16; + w += 24; h += 16; } void Choice::Draw(UIContext &dc) { ClickableItem::Draw(dc); - int paddingX = 8; + int paddingX = 12; dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); if (selected_) { @@ -303,7 +302,7 @@ void Choice::Draw(UIContext &dc) { void InfoItem::Draw(UIContext &dc) { Item::Draw(dc); - int paddingX = 8; + int paddingX = 12; dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER | ALIGN_RIGHT); // dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor); @@ -312,28 +311,28 @@ void InfoItem::Draw(UIContext &dc) { void ItemHeader::Draw(UIContext &dc) { float scale = 1.0f; if (dc.theme->uiFontSmaller == dc.theme->uiFont) { - scale = 0.6f; + scale = 0.7f; } dc.Draw()->SetFontScale(scale, scale); - dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 4, bounds_.y, 0xFFa0a0a0, ALIGN_LEFT); + dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 4, bounds_.y, 0xFFFFFFFF, ALIGN_LEFT); dc.Draw()->SetFontScale(1.0f, 1.0f); dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), 0xFFFFFFFF); } void PopupHeader::Draw(UIContext &dc) { dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 12, bounds_.centerY(), dc.theme->popupTitle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); - dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), 0xFFFFFFFF); + dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), dc.theme->popupTitle.fgColor); } void CheckBox::Draw(UIContext &dc) { ClickableItem::Draw(dc); - int paddingX = 8; + int paddingX = 12; int paddingY = 8; int image = *toggle_ ? dc.theme->checkOn : dc.theme->checkOff; dc.Draw()->DrawText(dc.theme->uiFont, text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER); - dc.Draw()->DrawImage(image, bounds_.x2() - 4, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); + dc.Draw()->DrawImage(image, bounds_.x2() - paddingX, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_RIGHT | ALIGN_VCENTER); } void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const { diff --git a/ui/view.h b/ui/view.h index 9bb36f2559..d3eeea8ee2 100644 --- a/ui/view.h +++ b/ui/view.h @@ -82,6 +82,7 @@ struct Theme { int checkOff; int sliderKnob; int whiteImage; + int dropShadow4Grid; Style buttonStyle; Style buttonFocusedStyle; @@ -91,6 +92,9 @@ struct Theme { Style itemStyle; Style itemDownStyle; Style itemFocusedStyle; + Style itemDisabledStyle; + + Style headerStyle; Style popupTitle; }; @@ -480,7 +484,9 @@ public: // Use to trigger something or open a submenu screen. class Choice : public ClickableItem { public: - Choice(const std::string &text, const std::string &smallText = "", bool selected = false, LayoutParams *layoutParams = 0) + Choice(const std::string &text, LayoutParams *layoutParams = 0) + : ClickableItem(layoutParams), text_(text), smallText_(), selected_(false) {} + Choice(const std::string &text, const std::string &smallText, bool selected = false, LayoutParams *layoutParams = 0) : ClickableItem(layoutParams), text_(text), smallText_(smallText), selected_(selected) {} virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; @@ -499,8 +505,8 @@ public: StickyChoice(const std::string &text, const std::string &smallText = "", LayoutParams *layoutParams = 0) : Choice(text, smallText, false, layoutParams) {} - virtual void Key(const KeyInput &input); - virtual void Touch(const TouchInput &input); + virtual void Key(const KeyInput &key); + virtual void Touch(const TouchInput &touch); virtual void FocusChanged(int focusFlags); void Press() { down_ = true; dragging_ = false; } diff --git a/ui/viewgroup.cpp b/ui/viewgroup.cpp index c4c83cb4e9..35487441e9 100644 --- a/ui/viewgroup.cpp +++ b/ui/viewgroup.cpp @@ -85,6 +85,9 @@ void ViewGroup::Draw(UIContext &dc) { if (hasDropShadow_) { // Darken things behind. dc.FillRect(UI::Drawable(0x60000000), Bounds(0,0,dp_xres, dp_yres)); + float dropsize = 30; + dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid, bounds_.x - dropsize, bounds_.y, bounds_.x2() + dropsize, bounds_.y2()+dropsize*1.5, 0xDF000000, 3.0f); + // dc.Draw()->DrawImage4Grid(dc.theme->dropShadow, ) } @@ -343,8 +346,10 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v const LinearLayoutParams *linLayoutParams = static_cast(layoutParams); if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0; - if (linLayoutParams && linLayoutParams->weight > 0.0f) - views_[i]->Measure(dc, MeasureSpec(EXACTLY, unit * linLayoutParams->weight), MeasureSpec(EXACTLY, measuredHeight_)); + if (linLayoutParams && linLayoutParams->weight > 0.0f) { + int marginSum = linLayoutParams->margins.left + linLayoutParams->margins.right; + views_[i]->Measure(dc, MeasureSpec(EXACTLY, unit * linLayoutParams->weight - marginSum), MeasureSpec(EXACTLY, measuredHeight_)); + } } } else { //MeasureBySpec(layoutParams_->height, vert.type == UNSPECIFIED ? sum : weightZeroSum, vert, &measuredHeight_); @@ -359,8 +364,10 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v const LinearLayoutParams *linLayoutParams = static_cast(layoutParams); if (!linLayoutParams->Is(LP_LINEAR)) linLayoutParams = 0; - if (linLayoutParams && linLayoutParams->weight > 0.0f) - views_[i]->Measure(dc, MeasureSpec(EXACTLY, measuredWidth_), MeasureSpec(EXACTLY, unit * linLayoutParams->weight)); + if (linLayoutParams && linLayoutParams->weight > 0.0f) { + int marginSum = linLayoutParams->margins.top + linLayoutParams->margins.bottom; + views_[i]->Measure(dc, MeasureSpec(EXACTLY, measuredWidth_), MeasureSpec(EXACTLY, unit * linLayoutParams->weight - marginSum)); + } } } } @@ -548,11 +555,13 @@ void ScrollView::Draw(UIContext &dc) { float scrollMax = std::max(0.0f, childHeight - bounds_.h); float ratio = bounds_.h / views_[0]->GetBounds().h; + + float bobWidth = 5; if (ratio < 1.0f && scrollMax > 0.0f) { float bobHeight = ratio * bounds_.h; float bobOffset = (scrollPos_ / scrollMax) * (bounds_.h - bobHeight); - Bounds bob(bounds_.x2() - 10, bounds_.y + bobOffset, 5, bobHeight); + Bounds bob(bounds_.x2() - bobWidth, bounds_.y + bobOffset, bobWidth, bobHeight); dc.FillRect(Drawable(0x80FFFFFF), bob); } } @@ -805,6 +814,7 @@ void ChoiceStrip::Key(const KeyInput &input) { SetSelection(selected_ + 1); } } + ViewGroup::Key(input); } ListView::ListView(ListAdaptor *a, LayoutParams *layoutParams)