bool ofxColorPicker_<ColorType>::mouseReleased(ofMouseEventArgs & mouse){ if(!isGuiDrawing()){ return false; } bool bReturn = mouseUpdate(mouse); state = Waiting; return bReturn; }
void Panzerfaust::update(float deltaTime) { bool forwardVelocity = m_IOHandler.m_keyIsDown['W']; bool backwardVelocity = m_IOHandler.m_keyIsDown['S']; bool leftwardVelocity = m_IOHandler.m_keyIsDown['A']; bool rightwardVelocity = m_IOHandler.m_keyIsDown['D']; //HACK const float SPEED_OF_CAMERA = 50.f; g_localUser.m_unit.m_target.x += (rightwardVelocity - leftwardVelocity)*SPEED_OF_CAMERA*deltaTime; g_localUser.m_unit.m_target.y += (forwardVelocity - backwardVelocity)*SPEED_OF_CAMERA*deltaTime; g_localUser.update(deltaTime); GamePacket currentPacket; do { bool newUser = true; currentPacket = g_serverConnection->receivePackets(); if (currentPacket.ID != 0) { Color3b packetColor = Color3b(); packetColor.r = currentPacket.r; packetColor.g = currentPacket.g; packetColor.b = currentPacket.b; for (unsigned int ii = 0; ii < g_users.size(); ii++) { if (Color3b(g_users[ii].m_unit.m_color) == packetColor) { newUser = false; g_users[ii].m_unit.m_target = Vector2f(currentPacket.x, currentPacket.y); } } if (newUser) { User tempUser = User(); tempUser.m_unit.m_position = Vector2f(currentPacket.x, currentPacket.y); tempUser.m_unit.m_target = Vector2f(currentPacket.x, currentPacket.y); tempUser.m_unit.m_color = Color4f(packetColor.r/255.f, packetColor.g/255.f, packetColor.b/255.f, 1.f); tempUser.m_userType = USER_REMOTE; g_users.push_back(tempUser); } } } while (currentPacket.ID != 0); for (unsigned int ii = 0; ii < g_users.size(); ii++) { g_users[ii].update(deltaTime); } mouseUpdate(); m_internalTime += deltaTime; //m_world.update(deltaTime); }
void update() { #if !(INPUT_DISABLE_KEYBOARD) keyUpdate(); #endif #if !(INPUT_DISABLE_MOUSE) mouseUpdate(); #endif #if !(INPUT_DISABLE_JOYSTICK) joystickUpdate(); #endif }
bool ofxColorPicker_<ColorType>::mousePressed(ofMouseEventArgs & mouse){ if(!isGuiDrawing()){ return false; } if(rectColorScaleBar.inside(mouse)){ state = ChangingScale; }else if(rectColorWheel.inside(mouse)){ state = ChangingWheel; } return mouseUpdate(mouse); }
int main() { swInit(); swInitGL(); SWindow* window = swCreateWindow(1000, 620, "Grapher2D"); SView* rootView = swGetRootView(window); SOpenGLContextAttribs attribs; attribs.major = 3; attribs.minor = 3; attribs.debug = 0; attribs.swapInterval = 1; SRect* glViewBounds = swMakeRect(390, 10, 600, 600); SView* view = swCreateView(rootView, glViewBounds); SOpenGLContext* conetxt = swCreateOpenGLContext(view, &attribs); UIState* state = malloc(sizeof(UIState)); state->y = 0; state->first = 1; state->rootView = rootView; for (int i = 0; i < 15; i++) { createEntry(state, i); } g_parseInfo = eqGetDefaultParseInfo(); g_colors[0].r = 0.8f; g_colors[0].g = 0.2f; g_colors[0].b = 0.2f; g_colors[1].r = 0.1f; g_colors[1].g = 0.6f; g_colors[1].b = 0.1f; g_colors[2].r = 0.2f; g_colors[2].g = 0.2f; g_colors[2].b = 0.9f; g_colors[3].r = 0.9f; g_colors[3].g = 0.65f; g_colors[3].b = 0.2f; g_colors[4].r = 0.8f; g_colors[4].g = 0.2f; g_colors[4].b = 0.8f; swMakeContextCurrent(conetxt); if (!gladLoadGLLoader((GLADloadproc)swGetProcAddressGL)) { printf("Could not load opengl!\n"); return 0; } glClearColor(1.0f, 1.0f, 1.0f, 1.0f); GLMesh* quad = createQuadMesh(); GLShader* quadShader = createQuadShader(); GLShader* lineShader = createLineShader(); GLShader* edgeShader = createEdgeShader(GRAPH_PORT_SIZE); GLShader* renderShader = createRenderShader(GRAPH_PORT_SIZE); float* lineModel = malloc(sizeof(float) * 16); getModelviewMatrix(lineModel, 0, 0, 1, 1); float* lineProj = malloc(sizeof(float) * 16); getOrthoMatrix(lineProj, 0, 600, 0, 600, -1, 1); glUseProgram(lineShader->program); glUniformMatrix4fv(lineShader->uniformLocs[0], 1, GL_FALSE, lineProj); glUniformMatrix4fv(lineShader->uniformLocs[1], 1, GL_FALSE, lineModel); glUseProgram(0); SMouseState preMouseState; preMouseState.x = 0; preMouseState.y = 0; preMouseState.ldown = 0; preMouseState.scroll = 0; SMouseState* mouseState = swGetMouseState(window); GLuint g_fbo, g_gtex; glGenFramebuffers(1, &g_fbo); glBindFramebuffer(GL_FRAMEBUFFER, g_fbo); glDrawBuffer(GL_COLOR_ATTACHMENT0); glGenTextures(1, &g_gtex); glBindTexture(GL_TEXTURE_2D, g_gtex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, GRAPH_PORT_SIZE, GRAPH_PORT_SIZE, 0, GL_RGBA, GL_FLOAT, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, g_gtex, 0); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); int fps = 0; float time = 0; uint8_t i_color = 0; //SLabel* label = swCreateLabel(rootView, swMakeRect(250, 200, 300, 100), "Hello World!"); while (!swCloseRequested(window)) { swPollEvents(); //printf("%d\n", fps); //fps++; mouseUpdate(mouseState, &preMouseState, glViewBounds); time += 1.0f / 60.0f; glBindFramebuffer(GL_FRAMEBUFFER, g_fbo); glClear(GL_COLOR_BUFFER_BIT); glViewport(0, 0, GRAPH_PORT_SIZE, GRAPH_PORT_SIZE); glBindVertexArray(quad->vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glUseProgram(lineShader->program); glUniform3f(lineShader->uniformLocs[2], 0.45f, 0.45f, 0.45f); drawGrid(lineModel, lineShader->uniformLocs[1], g_left, g_right, g_down, g_up, 600, 600); glUniform3f(lineShader->uniformLocs[2], 0, 0, 0); drawAxes(lineModel, lineShader->uniformLocs[1], 600, 600); Entry* currentEntry = state->root; while (currentEntry != NULL) { if (currentEntry->active) { drawGraphData(currentEntry->graph, time, 0); } currentEntry = currentEntry->next; } glUseProgram(edgeShader->program); currentEntry = state->root; while (currentEntry != NULL) { if (currentEntry->active) { drawGraphEdges(currentEntry->graph); } currentEntry = currentEntry->next; } glBindFramebuffer(GL_FRAMEBUFFER, g_fbo); glViewport(0, 0, GRAPH_PORT_SIZE, GRAPH_PORT_SIZE); glUseProgram(renderShader->program); i_color = 0; currentEntry = state->root; while (currentEntry != NULL) { if (currentEntry->active) { glUniform3f(renderShader->uniformLocs[1], g_colors[i_color % COLOR_NUM].r, g_colors[i_color % COLOR_NUM].g, g_colors[i_color % COLOR_NUM].b); glBindTexture(GL_TEXTURE_2D, currentEntry->graph->etex); glActiveTexture(GL_TEXTURE0); glDrawArrays(GL_TRIANGLES, 0, 6); } i_color++; currentEntry = currentEntry->next; } glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, 600, 600); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(quadShader->program); glBindTexture(GL_TEXTURE_2D, g_gtex); glActiveTexture(GL_TEXTURE0); glDrawArrays(GL_TRIANGLES, 0, 6); swSwapBufers(conetxt); swDraw(window); } swCloseWindow(window); return 0; }
bool ofxColorPicker_<ColorType>::mouseDragged(ofMouseEventArgs & mouse){ if(!isGuiDrawing()){ return false; } return mouseUpdate(mouse); }
void Panzerfaust::update(float deltaTime) { bool forwardVelocity = m_IOHandler.m_keyIsDown['W']; bool backwardVelocity = m_IOHandler.m_keyIsDown['S']; bool leftwardVelocity = m_IOHandler.m_keyIsDown['A']; bool rightwardVelocity = m_IOHandler.m_keyIsDown['D']; //HACK const float SPEED_OF_CAMERA = 50.f; g_localUser.m_unit.m_target.x += (rightwardVelocity - leftwardVelocity)*SPEED_OF_CAMERA*deltaTime; g_localUser.m_unit.m_target.y += (forwardVelocity - backwardVelocity)*SPEED_OF_CAMERA*deltaTime; g_localUser.update(deltaTime); if (g_localUser.m_unit.m_position.distanceSquared(g_flag.m_position) < 100.f) { CS6Packet vicPacket; vicPacket.packetType = TYPE_Victory; Color3b userColor = Color3b(g_localUser.m_unit.m_color); memcpy(vicPacket.playerColorAndID, &userColor, sizeof(userColor)); memcpy(vicPacket.data.victorious.playerColorAndID, &userColor, sizeof(userColor)); g_serverConnection->sendPacket(vicPacket); } CS6Packet currentPacket; do { bool newUser = true; currentPacket = g_serverConnection->receivePackets(); if (currentPacket.packetType == TYPE_Reset) { //Reset type things g_localUser.m_unit.m_position = Vector2f(currentPacket.data.reset.playerXPosition, currentPacket.data.reset.playerYPosition); g_localUser.m_unit.m_target = g_localUser.m_unit.m_position; Color3b packetColor = Color3b(); memcpy(&packetColor, currentPacket.playerColorAndID, sizeof(packetColor)); g_localUser.m_unit.m_color = Color4f(packetColor.r/255.f, packetColor.g/255.f, packetColor.b/255.f, 1.f); g_flag.m_position = Vector2f(currentPacket.data.reset.flagXPosition, currentPacket.data.reset.flagYPosition); g_flag.m_target = g_flag.m_position; g_localUser.m_isInGame = true; } else if (currentPacket.packetType != 0) { Color3b packetColor = Color3b(); memcpy(&packetColor, currentPacket.playerColorAndID, sizeof(packetColor)); for (unsigned int ii = 0; ii < g_users.size(); ii++) { if (Color3b(g_users[ii].m_unit.m_color) == packetColor) { newUser = false; g_users[ii].processUpdatePacket(currentPacket); } } if (newUser) { User tempUser = User(); tempUser.processUpdatePacket(currentPacket); //tempUser.m_unit.m_position = Vector2f(currentPacket.x, currentPacket.y); //tempUser.m_unit.m_target = Vector2f(currentPacket.x, currentPacket.y); //tempUser.m_unit.m_color = Color4f(packetColor.r/255.f, packetColor.g/255.f, packetColor.b/255.f, 1.f); tempUser.m_userType = USER_REMOTE; g_users.push_back(tempUser); } } } while (currentPacket.packetType != 0); for (unsigned int ii = 0; ii < g_users.size(); ii++) { g_users[ii].update(deltaTime); } mouseUpdate(); m_internalTime += deltaTime; //m_world.update(deltaTime); }
void InputHandler::update() { keyUpdate(); mouseUpdate(); joystickUpdate(); }