//! from json
void WarpPerspectiveBilinear::fromJson(const JsonTree &json)
{
	Warp::fromJson(json);
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// get corners
		JsonTree corners(warp.getChild("corners"));
		for (size_t i = 0; i < corners.getNumChildren(); i++) {
			JsonTree child = corners.getChild(i);
			float x = (child.hasChild("x")) ? child.getValueForKey<float>("x") : 0.0f;
			float y = (child.hasChild("y")) ? child.getValueForKey<float>("y") : 0.0f;
			mWarp->setControlPoint(i, vec2(x, y));
			CI_LOG_V("corner:" + toString(x) + " " + toString(y));
		}
	}
}
예제 #2
0
	void PretzelGlobal::loadSettings(fs::path settingsPath){
		fs::path loadPath = settingsPath;
		if (loadPath.string() == ""){
			loadPath = getAppPath() / "guiSettings" / "settings.json";
		}

		if (!fs::exists(loadPath)){
			console() << loadPath << " does not exist" << endl;
		}
		else{
			JsonTree loadTree(loadFile(loadPath));
			JsonTree appSettings = loadTree.getChild(0);

			for (int i = 0; i < mParamList.size(); i++){
				string pName = mParamList[i].name;
				switch (mParamList[i].type){
				case _FLOAT:
					if (appSettings.hasChild(pName)){
						float fVal = appSettings.getChild(pName).getValue<float>();
						*((float*)mParamList[i].value) = fVal;
					}
					break;
				case _INT:
					if (appSettings.hasChild(pName)){
						int fVal = appSettings.getChild(pName).getValue<int>();
						*((int*)mParamList[i].value) = fVal;
					}
					break;
				case _BOOL:
					if (appSettings.hasChild(pName)){
						bool bVal = appSettings.getChild(pName).getValue<float>();
						*((bool*)mParamList[i].value) = bVal;
					}
					break;
				default:
					console() << "Pretzel :: Can't load settings type " << endl;
					break;
				}
			}
		}
	}
예제 #3
0
void View::load( const JsonTree &data )
{
    if( data.hasChild( "SUBVIEWS" ) && mLoadSubViews )
    {
        JsonTree tree = data.getChild( "SUBVIEWS" );
        int numSubViews = tree.getNumChildren();
        for(int i = 0; i < numSubViews; i++)
        {
            JsonTree sub = tree[i];
            ViewRef subview = getSubView( sub.getValueForKey( "NAME" ) );
            if( subview )
            {
                subview->load( sub ); 
            }
        }
    }    
}
//! to json
JsonTree	WarpPerspectiveBilinear::toJson() const
{
	JsonTree		json = WarpBilinear::toJson();
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// set corners
		JsonTree	corners = JsonTree::makeArray("corners");
		for (unsigned i = 0; i < 4; ++i) {
			vec2 corner = mWarp->getControlPoint(i);
			JsonTree	cr;
			cr.addChild(ci::JsonTree("corner", i));
			cr.addChild(ci::JsonTree("x", corner.x));
			cr.addChild(ci::JsonTree("y", corner.y));

			corners.pushBack(cr);
		}
		warp.pushBack(corners);
		json.pushBack(warp);
	}
	return json;
}
예제 #5
0
	void PretzelGlobal::loadSettings(fs::path settingsPath){
		fs::path loadPath = settingsPath;
		if (loadPath.string() == ""){
			loadPath = getAppPath() / "guiSettings" / "settings.json";
		}

		if (!fs::exists(loadPath)){
			CI_LOG_W("Pretzel :: Can't load ") << loadPath << " Path does not exist.";
		}
		else{
			JsonTree loadTree(loadFile(loadPath));
			JsonTree appSettings = loadTree.getChild(0);

			for (int i = 0; i < mParamList.size(); i++){
				string pName = mParamList[i].name;
				switch (mParamList[i].type){
				case _FLOAT:
					if (appSettings.hasChild(pName)){
						float fVal = appSettings.getChild(pName).getValue<float>();
						*((float*)mParamList[i].value) = fVal;
					}
					break;
				case _INT:
					if (appSettings.hasChild(pName)){
						int fVal = appSettings.getChild(pName).getValue<int>();
						*((int*)mParamList[i].value) = fVal;
					}
					break;
				case _BOOL:
					if (appSettings.hasChild(pName)){
						bool bVal = appSettings.getChild(pName).getValue<float>();
						*((bool*)mParamList[i].value) = bVal;
					}
					break;
				case _STRING:
					if (appSettings.hasChild(pName)){
						std::string sVal = appSettings.getChild(pName).getValue<std::string>();
						*((std::string*)mParamList[i].value) = sVal;
					}
					break;
                case _VEC2:
                    if (appSettings.hasChild(pName)){
                        vec2 p;
                        p.x = appSettings.getChild(pName).getChild("x").getValue<float>();
                        p.y = appSettings.getChild(pName).getChild("y").getValue<float>();
                        *((vec2*)mParamList[i].value) = p;
                    }
                    break;
                case _VEC3:
                    if (appSettings.hasChild(pName)){
                        vec3 p;
                        p.x = appSettings.getChild(pName).getChild("x").getValue<float>();
                        p.y = appSettings.getChild(pName).getChild("y").getValue<float>();
                        p.z = appSettings.getChild(pName).getChild("z").getValue<float>();
                        *((vec3*)mParamList[i].value) = p;
                    }
                    break;
                case _COLOR:
                    if (appSettings.hasChild(pName)){
                        Color p;
                        p.r = appSettings.getChild(pName).getChild("r").getValue<float>();
                        p.g = appSettings.getChild(pName).getChild("g").getValue<float>();
                        p.b = appSettings.getChild(pName).getChild("b").getValue<float>();
                        *((Color*)mParamList[i].value) = p;
                    }
                    break;
                case _COLORA:
                    if (appSettings.hasChild(pName)){
                        ColorA p;
                        p.r = appSettings.getChild(pName).getChild("r").getValue<float>();
                        p.g = appSettings.getChild(pName).getChild("g").getValue<float>();
                        p.b = appSettings.getChild(pName).getChild("b").getValue<float>();
                        p.a = appSettings.getChild(pName).getChild("a").getValue<float>();
                        *((ColorA*)mParamList[i].value) = p;
                    }
                    break;
				default:
					CI_LOG_W( "Pretzel :: Unrecognized settings type.");
					break;
				}
			}
		}
        signalOnSettingsLoad.emit();
	}
예제 #6
0
ChattyPostDataRef getChattyPostDataRefFromJSONPost(const JsonTree& post)
{
   ChattyPostDataRef post_data_ref = ChattyPostData::create();

   post_data_ref->m_id = fromString<uint32_t>(post["id"].getValue());
   post_data_ref->m_thread_id = fromString<uint32_t>(post["threadId"].getValue());
   post_data_ref->m_parent_id = fromString<uint32_t>(post["parentId"].getValue());
   post_data_ref->m_author = post["author"].getValue();
   post_data_ref->m_body = post["body"].getValue();

   replaceEncodingsInString(post_data_ref->m_body);

   std::string strvalue = post["category"].getValue();
   if(strvalue.length() > 0)
   {
           if(strvalue == "ontopic")        post_data_ref->m_category = category_type::NORMAL;
      else if(strvalue == "nws")            post_data_ref->m_category = category_type::NWS;
      else if(strvalue == "stupid")         post_data_ref->m_category = category_type::STUPID;
      else if(strvalue == "political")      post_data_ref->m_category = category_type::POLITICAL;
      else if(strvalue == "tangent")        post_data_ref->m_category = category_type::OFFTOPIC;
      else if(strvalue == "informative")    post_data_ref->m_category = category_type::INFORMATIVE;
      else if(strvalue == "nuked")          post_data_ref->m_category = category_type::NUKED;
   }

   strvalue = post["date"].getValue();
   if(strvalue.length() > 0)
   {
      std::tm post_time;
      memset(&post_time, 0, sizeof(std::tm));
      
#if defined(CINDER_MSW)
      sscanf_s(strvalue.c_str(), "%d-%d-%dT%d:%d",
               &post_time.tm_year,
               &post_time.tm_mon,
               &post_time.tm_mday,
               &post_time.tm_hour,
               &post_time.tm_min);
#else
      sscanf(strvalue.c_str(), "%d-%d-%dT%d:%d",
               &post_time.tm_year,
               &post_time.tm_mon,
               &post_time.tm_mday,
               &post_time.tm_hour,
               &post_time.tm_min);
#endif

      post_time.tm_year -= 1900;
      post_time.tm_mon -= 1;

#if defined(CINDER_MSW)
      post_data_ref->m_date_time = _mkgmtime(&post_time);
#else
      post_data_ref->m_date_time = timegm(&post_time); // and I have no idea if this is right
#endif
      // if mac doesn't have _mkgmtime, need to find a way to convert UTC to local
      //post_data_ref->m_date_time = std::mktime(&post_time);
   }

   if(post.hasChild("lols"))
   {
      const JsonTree& lols = post.getChild("lols");
      for(size_t lol_i = 0; lol_i < lols.getNumChildren(); lol_i++)
      {
         const JsonTree& lol = lols.getChild(lol_i);
         strvalue = lol["tag"].getValue();
         if(strvalue.length() > 0)
         {
            lol_type which_lol = LOL;
                 if(strvalue == "lol") which_lol = lol_type::LOL;
            else if(strvalue == "inf") which_lol = lol_type::INF;
            else if(strvalue == "unf") which_lol = lol_type::UNF;
            else if(strvalue == "tag") which_lol = lol_type::TAG;
            else if(strvalue == "wtf") which_lol = lol_type::WTF;
            else if(strvalue == "ugh") which_lol = lol_type::UGH;

            post_data_ref->m_lol_count[which_lol] = fromString<unsigned int>(lol["count"].getValue());
         }
      }
   }

   return post_data_ref;
}
예제 #7
0
void TreeHeartbeat::getNewEvents()
{
   try
   {
      JsonTree queryResult = queryWinChattyv2Server("waitForEvent?lastEventId=" + toString(m_last_event_id));

      if(queryResult.hasChild("lastEventId"))
      {
         std::string strvalue = queryResult["lastEventId"].getValue();

         if(strvalue.length() > 0)
         {
            m_last_event_id = fromString<uint32_t>(strvalue);
         }

         if(queryResult.hasChild("events"))
         {
            AppMessageRef worldTreeEventMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_EVENT);

            const JsonTree& events = queryResult.getChild("events");
            for(size_t event_i = 0; event_i < events.getNumChildren(); event_i++)
            {
               const JsonTree& this_event = events.getChild(event_i);

               const JsonTree& event_data = this_event.getChild("eventData");

               strvalue = this_event["eventType"].getValue();

               if(strvalue == "newPost")
               {
                  const JsonTree& post = event_data.getChild("post");

                  worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list.push_front(getChattyPostDataRefFromJSONPost(post));
               }
               else if(strvalue == "categoryChange")
               {

               }
               else if(strvalue == "serverMessage")
               {

               }
               else if(strvalue == "lolCountsUpdate")
               {

               }
            }

            sortChattyPostDataList(worldTreeEventMessage->AsWorldTreeEvent()->m_new_posts_list);

            if(!m_canceled)
            {
               ((LampApp*)app::App::get())->postMessage(worldTreeEventMessage);
            }
         }
      }
      else
      {
         ci::sleep(2000.0f);
      }
   }
   catch(ci::Exception& exc)
   {
      CI_LOG_E("Error calling WCv2 method waitForEvent: " << exc.what());
      ci::sleep(2000.0f);
   }
}
예제 #8
0
void TreeHeartbeat::getWorldTree()
{
   getLastEventId();

   try
   {
      JsonTree queryResult = queryWinChattyv2Server("getChatty");

      if(queryResult.hasChild("threads"))
      {
         AppMessageRef worldTreeBuiltMessage = AppMessage::create(AppMessage::message_type::WORLDTREE_BUILT);

         const JsonTree& threads = queryResult.getChild("threads");
         for(size_t thread_i = 0; thread_i < threads.getNumChildren(); thread_i++)
         {
            std::list<ChattyPostDataRef> list_of_posts_in_thread;

            const JsonTree& this_thread = threads.getChild(thread_i);
            if(this_thread.hasChild("posts"))
            {
               const JsonTree& posts = this_thread.getChild("posts");
               for(size_t post_i = 0; post_i < posts.getNumChildren(); post_i++)
               {
                  const JsonTree& post = posts.getChild(post_i);
                  list_of_posts_in_thread.push_back(getChattyPostDataRefFromJSONPost(post));
               }
            }

            // sort list into tree
            chatty_post_id thread_id = fromString<uint32_t>(this_thread["threadId"].getValue());
            ChattyPostDataRef thread_tree;
            
            for(std::list<ChattyPostDataRef>::iterator it = list_of_posts_in_thread.begin();
                it != list_of_posts_in_thread.end();
                it++)
            {
               if((*it)->m_id == thread_id)
               {
                  thread_tree = *it;
                  list_of_posts_in_thread.erase(it);
                  break;
               }
            }

            if(thread_tree)
            {
               thread_tree->adoptChildren(list_of_posts_in_thread);
               CI_ASSERT(list_of_posts_in_thread.size() == 0);
            }

            thread_tree->markAsRead(false);

            // add tree to list of thread trees
            worldTreeBuiltMessage->AsWorldTreeBuilt()->m_thread_tree_list.push_back(thread_tree);
         }

         if(!m_canceled)
         {
            ((LampApp*)app::App::get())->postMessage(worldTreeBuiltMessage);
         }
      }
   }
   catch(ci::Exception& exc)
   {
      CI_LOG_E("Error calling WCv2 method getChatty: " << exc.what());
      m_last_event_id = 0;
   }
}