void ComponentGUIDrawIcon::draw (const std::shared_ptr<CameraObject> &camera, const Color4f &parent_color) { if (!_material.as_ref() || !_shader.as_ref()) return; GUIObject *gui = checked_cast<GUIObject*>(owner()); if (!gui) return; if (gui->color().a_as_float() * parent_color.a_as_float() <= 0.0F) return; if (gui->scale() == Vector3(0.0F,0.0F,0.0F)) return; // Get Alternate materials Color4f c = gui->color() * parent_color; std::shared_ptr<MaterialResource> m = _material; if (gui->state() == GUIObject::STATE_FOCUSED) { if (_pressed_material.as_ref()) { m = _pressed_material; } else { c = gui->color() * 0.5F; } } Rectangle local_rect = gui->rectangle(); // Draw background if ( (_corner_width > 0.0F || _corner_height > 0.0F) && _draw_style == DRAW_STYLE_STRETCH_CENTER_3X3) { DrawUtils::draw_quad_stretch_center_3x3 ( _b, camera, m, _shader, c, gui->draw_transform(), local_rect.minus_x(), local_rect.minus_y(), local_rect.width(), local_rect.height(), _corner_width, _corner_height * System::renderer()->screen_aspect()); } else if ( (_corner_width > 0.0F || _corner_height > 0.0F) && _draw_style == DRAW_STYLE_STRETCH_CENTER_2X2) { DrawUtils::draw_quad_stretch_center_2x2 ( _b, camera, m, _shader, c, gui->draw_transform(), local_rect.minus_x(), local_rect.minus_y(), local_rect.width(), local_rect.height(), _corner_width, _corner_height * System::renderer()->screen_aspect()); } else { _b.batch_begin( camera, m, _shader, gui->draw_transform(), DT3GL_PRIM_TRI_STRIP, DrawBatcher::FMT_V | DrawBatcher::FMT_T0 | DrawBatcher::FMT_C); _b.add().v(local_rect.minus_x(),local_rect.plus_y(),0.0F) .t0(0.0F,1.0F) .c(c); _b.add().v(local_rect.minus_x(),local_rect.minus_y(),0.0F) .t0(0.0F,0.0F) .c(c); _b.add().v(local_rect.plus_x(),local_rect.plus_y(),0.0F) .t0(1.0F,1.0F) .c(c); _b.add().v(local_rect.plus_x(),local_rect.minus_y(),0.0F) .t0(1.0F,0.0F) .c(c); _b.batch_end(); _b.flush(); } // DrawBatcher b; // b.batch_begin( camera, // _material, // _shader, // gui->draw_transform(), // DT3GL_PRIM_TRI_STRIP, // DrawBatcher::FMT_V | DrawBatcher::FMT_T0 | DrawBatcher::FMT_C, // 4); // // Rectangle rect = gui->rectangle(); // // b.add().v(rect.minus_x(),rect.plus_y(),0.0F).t0(0.0F,1.0F).c(c); // b.add().v(rect.minus_x(),rect.minus_y(),0.0F).t0(0.0F,0.0F).c(c); // b.add().v(rect.plus_x(),rect.plus_y(),0.0F).t0(1.0F,1.0F).c(c); // b.add().v(rect.plus_x(),rect.minus_y(),0.0F).t0(1.0F,0.0F).c(c); // // b.batch_end(); }
void GUIController::draw_gui_recursive (PlaceableObject *root, const std::shared_ptr<CameraObject> &camera, const Color4f &parent_color, DTint stencil) { GUIObject *gui = checked_cast<GUIObject*>(root); Rectangle gui_rect(0.0F,1.0F,0.0F,1.0F); DTboolean use_stencil = false; std::list<PlaceableObject*> c = root->children(); if (gui) { // Check for transparent Color4f color = parent_color * gui->color(); if (color.a <= 0.0F) return; // Check for no scale if (gui->scale() == Vector3(0.0F,0.0F,0.0F)) return; // Get Rectangle gui_rect = gui->screen_rectangle(); // Check if we need to stencil use_stencil = c.size() > 0; if (use_stencil) { ++stencil; gui->draw_gui_mask(camera); } System::renderer()->set_stencil_ref(stencil); gui->draw_gui(camera, parent_color); } c.sort(CompareDraw()); for (auto &i : c) { GUIObject *gui_child = checked_cast<GUIObject*>(i); if (gui_child) { // Get Rectangle Rectangle gui_child_rect = gui_child->screen_rectangle(); if (!gui_rect.is_touching(gui_child_rect)) continue; draw_gui_recursive(gui_child, camera, parent_color * gui_child->color(), stencil ); } else { draw_gui_recursive(i, camera, parent_color, stencil); } } if (gui) { System::renderer()->set_stencil_ref(stencil); gui->post_draw_gui(camera, parent_color); if (use_stencil) { gui->draw_gui_unmask(camera); } } }
void GUIAttrEdit::handleMsg( ZMsg *msg ) { float lineH = getLineH(); int scroll = getAttrI( "scroll" ); float x = zmsgF(localX); float y = zmsgF(localY); if( zmsgIs(type,Key) && zmsgIs(which,wheelforward) ) { if( contains(x,y) ) { scroll-=2; scroll = max( -10, scroll ); scroll = min( view.count-5, scroll ); setAttrI( "scroll", scroll ); mouseOver = (int)( (myH-y) / lineH ); mouseOver += scroll; mouseOver = selected > view.count-1 ? view.count-1 : mouseOver; zMsgUsed(); } } else if( zmsgIs(type,Key) && zmsgIs(which,wheelbackward) ) { if( contains(x,y) ) { scroll+=2; scroll = max( -10, scroll ); scroll = min( view.count-5, scroll ); setAttrI( "scroll", scroll ); mouseOver = (int)( (myH-y) / lineH ); mouseOver += scroll; mouseOver = selected > view.count-1 ? view.count-1 : mouseOver; zMsgUsed(); } } else if( zmsgIs(type,MouseMove) ) { mouseOver = (int)( (myH-y) / lineH ); mouseOver += scroll; mouseOver = selected > view.count-1 ? view.count-1 : mouseOver; } else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgI(ctrl) && zmsgI(shift) ) { //ADJUST the linIncrement if( zmsgIs(which,L) ) { linIncrement *= 2.f; } else if( zmsgIs(which,R) ) { linIncrement /= 2.f; } } else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgIs(which,L) ) { selected = (int)( (myH-y) / lineH ); selected += scroll; selected = selected > view.count-1 ? view.count-1 : selected; ZHashTable *hash = (ZHashTable *)getAttrp( "hashPtr" ); if( !hash ) return; char *val = hash->getS( view[selected] ); char *end; double valD = strtod( val, &end ); if( end != val ) { // This is a number that can be manipulated // if( zmsgI(shift) && !zmsgI(ctrl) ) { // linMode = 0; // zMsgQueue( "type=GUIAttrEdit_CreateOptionMenu key=%s val=%lf toGUI=%s", selectVarPtr->name, selectVarPtr->getDouble(), getAttrS("name") ); // } // else { if( zmsgI(ctrl) && !zmsgI(shift) ) { linMode = 1; } else { linMode = 0; } selectX = x; selectY = y; mouseX = x; mouseY = y; startVal = valD; requestExclusiveMouse( 1, 1 ); // } } else { selected = -1; } /* ZVarPtr *selectVarPtr = getSelectedVar( selected ); if( selectVarPtr ) { if( zmsgI(shift) && !zmsgI(ctrl) ) { linMode = 0; zMsgQueue( "type=GUIAttrEdit_CreateOptionMenu key=%s val=%lf toGUI=%s", selectVarPtr->name, selectVarPtr->getDouble(), getAttrS("name") ); } else { if( zmsgI(ctrl) && !zmsgI(shift) ) { linMode = 1; } else { linMode = 0; } selectX = x; selectY = y; mouseX = x; mouseY = y; switch( selectVarPtr->type ) { case zVarTypeINT: startVal = (double)*(int *)selectVarPtr->ptr + 0.4; break; case zVarTypeSHORT: startVal = (double)*(short *)selectVarPtr->ptr + 0.4; break; case zVarTypeFLOAT: startVal = (double)*(float *)selectVarPtr->ptr; break; case zVarTypeDOUBLE: startVal = (double)*(double *)selectVarPtr->ptr; break; } requestExclusiveMouse( 1, 1 ); } } */ zMsgUsed(); return; } else if( zmsgIs(type,MouseReleaseDrag) ) { if( selected >= 0 ) { // ZVarPtr *selectVarPtr = getSelectedVar( selected ); // if( selectVarPtr ) { // zMsgQueue( "type=GUIAttrEdit_VarDoneChange key=%s val=%lf", selectVarPtr->name, selectVarPtr->getDouble() ); // } } requestExclusiveMouse( 1, 0 ); selected = -1; zMsgUsed(); return; } else if( zmsgIs(type,MouseDrag) && zmsgI(l) ) { int last = -1; int count = 0; //while( count++ != selected+1 && zVarsEnum( last, selectVarPtr, regExp ) ); ZHashTable *hash = (ZHashTable *)getAttrp( "hashPtr" ); double val = hash->getD( view[selected] ); mouseX = x; mouseY = y; if( linMode ) { val = startVal + (mouseY-selectY) * linIncrement; } else{ val = startVal * exp( (mouseY-selectY) / 50.0 ); } hash->putS( view[selected], ZTmpStr("%4.3le",val) ); } else if( zmsgIs(type,MouseClickOn) && zmsgIs(dir,D) && zmsgIs(which,R) ) { selectX = x; selectY = y; startScroll = scroll; requestExclusiveMouse( 1, 1 ); zMsgUsed(); return; } else if( zmsgIs(type,MouseDrag) && zmsgI(r) ) { scroll = (int)( startScroll + ( y - selectY ) / lineH ); scroll = max( -10, scroll ); scroll = min( view.count-5, scroll ); setAttrI( "scroll", scroll ); } else if( zmsgIs(type,GUIAttrEdit_Clear) ) { clearView(); } // else if( zmsgIs(type,GUIAttrEdit_Add) ) { // if( zmsgHas(regexp) ) { // addVarsByRegExp( zmsgS(regexp) ); // } // else if( zmsgHas(name) ) { // addVar( zmsgS(name) ); // } // } else if( zmsgIs(type,GUIAttrEdit_Sort) ) { if( zmsgIs(which,name) ) { sortViewByName(); } // else if( zmsgIs(which,order) ) { // sortViewByDeclOrder(); // } } else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenu) ) { ZHashTable hash; hash.putS( "who", getAttrS("name") ); hash.putS( "key", zmsgS(key) ); hash.putS( "val", ZTmpStr("%1.2e", zmsgF(val)) ); createOptionMenu( &hash ); optMenuUp = 1; zMsgQueue( "type=GUILayout toGUI=varEditOptMenu" ); zMsgQueue( "type=GUIMoveNear who=%s where=T x=4 y=%f toGUI=varEditOptMenu", getAttrS("name"), -(mouseOver-scroll)*lineH ); zMsgQueue( "type=GUISetModal val=1 toGUI=varEditOptMenu" ); } else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenuDone) ) { optMenuUp = 0; selected = -1; } else if( zmsgIs(type,GUIAttrEdit_CreateOptionMenuDirectEntry) ) { GUIObject *obj = guiFind( zmsgS(fromGUI) ); if( obj ) { zMsgQueue( "type=SetVar key=%s val=%f", zmsgS(key), atof(obj->getAttrS("text")) ); } } // else if( zmsgIs(type,GUIAttrEdit_ResetAll) ) { // for( int i=0; i<view.count; i++ ) { // ZVarPtr *v = zVarsLookup( varsView.vec[i] ); // v->resetDefault(); // } // } else if( zmsgIs(type,GUIAttrEdit_Clear) ) { clearView(); } else if( zmsgIs(type,GUIAttrEdit_Add) ) { addVar( zmsgS(key) ); } else if( zmsgIs(type,GUIAttrEdit_ViewAll) ) { if( zmsgI(clear) ) { clearView(); } addAllVars(); } GUIPanel::handleMsg( msg ); }
void GUIController::touch_gui (const TouchEvent *event, const std::shared_ptr<CameraObject> &camera, WorldNode* &handled) { if (handled) return; // Scan for first event for (DTuint i = 0; i < TouchEvent::MAX_NUM_TOUCHES; ++i) { if ( event->touches[i].state != TouchEvent::STATE_NONE ) { _touch.set_initial_position(event->touches[i].first_pos); _touch.set_previous_position(event->touches[i].previous_pos); _touch.set_position(event->touches[i].pos); _touch.set_velocity(event->touches[i].velocity); _touch.set_state(event->touches[i].state); break; } } // If this is a new event, then we find the target widget if (_touch.state() == TouchEvent::STATE_PRESSED) { // Find first hit object std::list<PlaceableObject*> c = children(); c.sort(CompareTouch()); for (auto i = c.rbegin(); i != c.rend(); ++i) { GUIObject *gui = checked_cast<GUIObject*>(*i); if (!gui) continue; GUIObject *hit_object = NULL; gui->hit_test(&_touch, hit_object, Color4f(1.0F,1.0F,1.0F,1.0F)); if (hit_object) { _touch.set_focused(hit_object); break; } } // Start touches if (_touch.focused()) _touch.focused()->touches_began(&_touch); handled = _touch.focused(); } else if (_touch.state() == TouchEvent::STATE_DOWN) { if (_touch.focused()) _touch.focused()->touches_moved(&_touch); handled = _touch.focused(); } else if (_touch.state() == TouchEvent::STATE_RELEASED) { if (_touch.focused()) _touch.focused()->touches_ended(&_touch); handled = _touch.focused(); // Reset touch _touch.set_state(TouchEvent::STATE_NONE); _touch.set_focused(NULL); } else if (_touch.state() == TouchEvent::STATE_HOVER) { // Do nothing } else { handled = _touch.focused(); } }