Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Add name property to WidgetPlacement (#1765)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and bluemarvin committed Sep 12, 2019
1 parent f750a5a commit 8b29a0d
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private void initialize() {
mBorderWidth = SettingsStore.getInstance(getContext()).getTransparentBorderWidth();
mWidgetManager = (WidgetManagerDelegate) getContext();
mWidgetPlacement = new WidgetPlacement(getContext());
mWidgetPlacement.name = getClass().getSimpleName();
mHandle = mWidgetManager.newWidgetHandle();
mWorldWidth = WidgetPlacement.pixelDimension(getContext(), R.dimen.world_width);
initializeWidgetPlacement(mWidgetPlacement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public WidgetPlacement(Context aContext) {
// Widget will be curved if enabled.
public boolean cylinder = true;
public int borderColor = 0;
public String name;
/*
* Flat surface placements are automatically mapped to curved coordinates.
* If a radius is set it's used for the automatic mapping of the yaw & angle when the
Expand Down Expand Up @@ -92,6 +93,7 @@ public void copyFrom(WidgetPlacement w) {
this.cylinder = w.cylinder;
this.cylinderMapRadius = w.cylinderMapRadius;
this.borderColor = w.borderColor;
this.name = w.name;
}

public int textureWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.visible = true;
aPlacement.cylinder = true;
aPlacement.textureScale = 1.0f;
aPlacement.name = "Window";
// Check Windows.placeWindow method for remaining placement set-up
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/cpp/VRLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct VRLayer::State {
device::EyeRect textureRect[2];
SurfaceChangedDelegate surfaceChangedDelegate;
std::function<void()> pendingEvent;
std::string name;
State():
initialized(false),
priority(0),
Expand Down Expand Up @@ -94,6 +95,11 @@ VRLayer::GetDrawInFront() const {
return m.drawInFront;
}

std::string
VRLayer::GetName() const {
return m.name;
}

bool
VRLayer::ShouldDrawBefore(const VRLayer& aLayer) {
if (m.layerType == VRLayer::LayerType::CUBEMAP || m.layerType == VRLayer::LayerType::EQUIRECTANGULAR) {
Expand Down Expand Up @@ -177,6 +183,11 @@ VRLayer::SetDrawInFront(bool aDrawInFront) {
m.drawInFront = aDrawInFront;
}

void
VRLayer::SetName(const std::string &aName) {
m.name = aName;
}

void VRLayer::NotifySurfaceChanged(SurfaceChange aChange, const std::function<void()>& aFirstCompositeCallback) {
if (m.surfaceChangedDelegate) {
m.surfaceChangedDelegate(*this, aChange, aFirstCompositeCallback);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/cpp/VRLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class VRLayer {
const vrb::Color& GetTintColor() const;
const device::EyeRect& GetTextureRect(device::Eye aEye) const;
bool GetDrawInFront() const;
std::string GetName() const;

bool ShouldDrawBefore(const VRLayer& aLayer);
void SetInitialized(bool aInitialized);
Expand All @@ -60,6 +61,7 @@ class VRLayer {
void SetTextureRect(device::Eye aEye, const device::EyeRect& aTextureRect);
void SetSurfaceChangedDelegate(const SurfaceChangedDelegate& aDelegate);
void SetDrawInFront(bool aDrawInFront);
void SetName(const std::string& aName);
void NotifySurfaceChanged(SurfaceChange aChange, const std::function<void()>& aFirstCompositeCallback);
protected:
struct State;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/cpp/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ Widget::SetPlacement(const WidgetPlacementPtr& aPlacement) {
if (m.cylinder) {
m.UpdateCylinderMatrix();
}
if (GetLayer()) {
GetLayer()->SetName(aPlacement->name);
}
}

WidgetResizerPtr
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/cpp/WidgetPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ WidgetPlacement::FromJava(JNIEnv* aEnv, jobject& aObject) {
result->name = aEnv->GetBooleanField(aObject, f); \
}

#define GET_STRING_FIELD(name) { \
jfieldID f = aEnv->GetFieldID(clazz, #name, "Ljava/lang/String;"); \
jstring javaString = (jstring)aEnv->GetObjectField(aObject, f); \
if (javaString) { \
const char* nativeString = aEnv->GetStringUTFChars(javaString, 0); \
result->name = nativeString; \
aEnv->ReleaseStringUTFChars(javaString, nativeString); \
} \
}


GET_INT_FIELD(width);
GET_INT_FIELD(height);
GET_FLOAT_FIELD(anchor.x(), "anchorX");
Expand All @@ -60,6 +71,7 @@ WidgetPlacement::FromJava(JNIEnv* aEnv, jobject& aObject) {
GET_BOOLEAN_FIELD(cylinder);
GET_FLOAT_FIELD(cylinderMapRadius, "cylinderMapRadius");
GET_INT_FIELD(borderColor);
GET_STRING_FIELD(name);

return result;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/WidgetPlacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct WidgetPlacement {
bool cylinder;
float cylinderMapRadius;
int borderColor;
std::string name;

int32_t GetTextureWidth() const;
int32_t GetTextureHeight() const;
Expand Down

0 comments on commit 8b29a0d

Please sign in to comment.