WindowedGLContext (Component* const component_, HGLRC contextToShareWith, const OpenGLPixelFormat& pixelFormat) : renderContext (0), component (component_), dc (0) { initialiseGLExtensions(); jassert (component != nullptr); createNativeWindow(); PIXELFORMATDESCRIPTOR pfd; initialisePixelFormatDescriptor (pfd, pixelFormat); const int format = ChoosePixelFormat (dc, &pfd); if (format != 0) SetPixelFormat (dc, format, &pfd); renderContext = wglCreateContext (dc); if (renderContext != 0) { makeActive(); initialiseGLExtensions(); extensions.initialise(); setPixelFormat (pixelFormat); if (contextToShareWith != 0) wglShareLists (contextToShareWith, renderContext); } }
BOOL LLDrawable::updateMove() { if (isDead()) { llwarns << "Update move on dead drawable!" << llendl; return TRUE; } if (mVObjp.isNull()) { return FALSE; } makeActive(); BOOL done; if (isState(MOVE_UNDAMPED)) { done = updateMoveUndamped(); } else { done = updateMoveDamped(); } return done; }
void Renderer::renderMap() { record_section("renderMap"); if (mapSize_ == glm::vec2(0.f)) { return; } auto gridDim = mapSize_ * 2.f; auto mapShader = ResourceManager::get()->getShader("map"); mapShader->makeActive(); mapShader->uniform4f("color", mapColor_); mapShader->uniform2f("mapSize", mapSize_); mapShader->uniform2f("gridDim", gridDim); // TODO(zack): HACK ALERT this is for fog of war, render as a separate // step instead if (controller_) { controller_->updateMapShader(mapShader); } // TODO(zack): render map with height/terrain map glm::mat4 transform = glm::scale( glm::mat4(1.f), glm::vec3(mapSize_.x, mapSize_.y, 1.f)); renderRectangleProgram(transform); }
void LLDrawable::moveUpdatePipeline(BOOL moved) { makeActive(); // Update the face centers. for (S32 i = 0; i < getNumFaces(); i++) { getFace(i)->updateCenterAgent(); } }
int GlXOffscreenContext::getIntProperty(GLenum intProperty) { ContextRestorer restorer(!isActive()); makeActive(); int v = 0; glGetIntegerv(intProperty, &v); checkGlError("After GlXOffscreenContext::getIntProperty.."); return v; }
// XXX Need a way to deal with blits with Camera/Lighting. void DisplayDeviceOpenGL::doBlitTexture(const TexturePtr& tex, int dstx, int dsty, int dstw, int dsth, float rotation, int srcx, int srcy, int srcw, int srch) { ASSERT_LOG(false, "DisplayDevice::doBlitTexture deprecated"); ASSERT_LOG(!tex, "Texture passed in was not of expected type."); const float tx1 = float(srcx) / tex->width(); const float ty1 = float(srcy) / tex->height(); const float tx2 = srcw == 0 ? 1.0f : float(srcx + srcw) / tex->width(); const float ty2 = srch == 0 ? 1.0f : float(srcy + srch) / tex->height(); const float uv_coords[] = { tx1, ty1, tx2, ty1, tx1, ty2, tx2, ty2, }; const float vx1 = float(dstx); const float vy1 = float(dsty); const float vx2 = float(dstx + dstw); const float vy2 = float(dsty + dsth); const float vtx_coords[] = { vx1, vy1, vx2, vy1, vx1, vy2, vx2, vy2, }; // Apply blend mode from texture if there is any. BlendEquationScopeOGL be_scope(*tex); BlendModeScopeOGL bm_scope(*tex); glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3((vx1+vx2)/2.0f,(vy1+vy2)/2.0f,0.0f)) * glm::rotate(glm::mat4(1.0f), rotation, glm::vec3(0.0f,0.0f,1.0f)) * glm::translate(glm::mat4(1.0f), glm::vec3(-(vx1+vy1)/2.0f,-(vy1+vy1)/2.0f,0.0f)); glm::mat4 mvp = glm::ortho(0.0f, 800.0f, 600.0f, 0.0f) * model; auto shader = OpenGL::ShaderProgram::defaultSystemShader(); shader->makeActive(); getDefaultShader()->setUniformsForTexture(tex); shader->setUniformValue(shader->getMvpUniform(), glm::value_ptr(mvp)); shader->setUniformValue(shader->getColorUniform(), glm::value_ptr(glm::vec4(1.0f,1.0f,1.0f,1.0f))); // XXX the following line are only temporary, obviously. //shader->setUniformValue(shader->getUniform("discard"), 0); glEnableVertexAttribArray(shader->getVertexAttribute()); glVertexAttribPointer(shader->getVertexAttribute(), 2, GL_FLOAT, GL_FALSE, 0, vtx_coords); glEnableVertexAttribArray(shader->getTexcoordAttribute()); glVertexAttribPointer(shader->getTexcoordAttribute(), 2, GL_FLOAT, GL_FALSE, 0, uv_coords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableVertexAttribArray(shader->getTexcoordAttribute()); glDisableVertexAttribArray(shader->getVertexAttribute()); }
void LLDrawable::moveUpdatePipeline(BOOL moved) { if (moved) { makeActive(); } // Update the face centers. for (S32 i = 0; i < getNumFaces(); i++) { LLFace* face = getFace(i); if (face) { face->updateCenterAgent(); } } }
BOOL LLDrawable::updateMove() { if (isDead()) { LL_WARNS() << "Update move on dead drawable!" << LL_ENDL; return TRUE; } if (mVObjp.isNull()) { return FALSE; } makeActive(); return isState(MOVE_UNDAMPED) ? updateMoveUndamped() : updateMoveDamped(); }
double HCluster::update(int row, int col, float distance){ try { bool cluster = false; smallRow = row; smallCol = col; smallDist = distance; //find upmost parent of row and col smallRow = getUpmostParent(smallRow); smallCol = getUpmostParent(smallCol); //you don't want to cluster with yourself if (smallRow != smallCol) { if ((method == "furthest") || (method == "nearest")) { //can we cluster??? if (method == "nearest") { cluster = true; } else{ //assume furthest //are they active in the link table int linkValue = makeActive(); //after this point this nodes info is active in linkTable if (linkValue == (clusterArray[smallRow].numSeq * clusterArray[smallCol].numSeq)) { cluster = true; } } if (cluster) { updateArrayandLinkTable(); clusterBins(); clusterNames(); } }else { cluster = true; updateArrayandLinkTable(); clusterBins(); clusterNames(); combineFile(); } } return cutoff; //printInfo(); } catch(exception& e) { m->errorOut(e, "HCluster", "update"); exit(1); } }
WindowLessGLContext::WindowLessGLContext(int width, int height) : _width(width), _height(height) { typedef GLXContext (*glXCreateContextAttribsARBProc)( Display *, GLXFBConfig, GLXContext, Bool, const int *); typedef Bool (*glXMakeContextCurrentARBProc)(Display *, GLXDrawable, GLXDrawable, GLXContext); static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = 0; static int visual_attribs[] = { None }; int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, None }; int fbcount = 0; GLXFBConfig *fbc = NULL; /* open display */ if (!(dpy = XOpenDisplay(0))) throw std::runtime_error(std::string( "WindowLessGLContext::WindowLessGLContext: Failed to open display\n")); /* get framebuffer configs, any is usable (might want to add proper attribs) */ if (!(fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), visual_attribs, &fbcount))) throw std::runtime_error(std::string( "WindowLessGLContext::WindowLessGLContext: Failed to get FBConfig\n")); /* get the required extensions */ glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *)"glXCreateContextAttribsARB"); glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc)glXGetProcAddressARB( (const GLubyte *)"glXMakeContextCurrent"); if (!(glXCreateContextAttribsARB && glXMakeContextCurrentARB)) { XFree(fbc); throw std::runtime_error( std::string("WindowLessGLContext::WindowLessGLContext: Missing support " "for GLX_ARB_create_context\n")); } /* create a context using glXCreateContextAttribsARB */ if (!(ctx = glXCreateContextAttribsARB(dpy, fbc[0], 0, True, context_attribs))) { XFree(fbc); throw std::runtime_error( std::string("WindowLessGLContext::WindowLessGLContext: Failed to " "create opengl context\n")); } /* create temporary pbuffer */ int pbuffer_attribs[] = { GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height, None }; pbuf = glXCreatePbuffer(dpy, fbc[0], pbuffer_attribs); XFree(fbc); XSync(dpy, False); makeActive(); }
/* frees source fut on error */ PTErr_t fut2PT (fut_p *futSrc, KpInt32_t inSpace, KpInt32_t outSpace, KpInt32_t srcFormat, PTRefNum_p PTRefNumNew) { PTErr_t PTErr; fut_hdr_p PTHdr = NULL; KpHandle_t PTHdrH = NULL, PTDataH = NULL; KpChar_t colorSpaceAttr[20]; *PTRefNumNew = 0; if ( ! IS_FUT(*futSrc)) goto ErrOut1; PTHdr = allocBufferPtr (sizeof(fut_hdr_t)); /* get buffer for resultant info header */ if (PTHdr == NULL) { goto ErrOut4; } if (!fut_io_encode (*futSrc, PTHdr)) { /* make the info header */ goto ErrOut3; } PTHdr->srcFormat = srcFormat; PTDataH = fut_unlock_fut (*futSrc); if (PTDataH == NULL) { goto ErrOut2; } *futSrc = NULL; PTHdrH = unlockBufferPtr (PTHdr); /* unlock the header buffer */ if (PTHdrH == NULL) { goto ErrOut2; } PTHdr = NULL; PTErr = registerPT (PTHdrH, NULL, PTRefNumNew); /* enter PT into list */ if (PTErr != KCP_SUCCESS) { goto ErrOut0; } makeActive (*PTRefNumNew, PTDataH); /* activate the new PT */ if (inSpace != -1) { /* set the input color space attribute */ KpItoa (inSpace, colorSpaceAttr); PTErr = PTSetAttribute (*PTRefNumNew, KCM_IN_SPACE, colorSpaceAttr); } if (outSpace != -1) { /* set the output color space attribute */ KpItoa (outSpace, colorSpaceAttr); PTErr = PTSetAttribute (*PTRefNumNew, KCM_OUT_SPACE, colorSpaceAttr); } if (PTErr != KCP_SUCCESS) { goto ErrOut0; } getOut: return PTErr; ErrOut4: PTErr = KCP_NO_CHECKIN_MEM; goto ErrOut0; ErrOut3: PTErr = KCP_ENCODE_PTHDR_ERR; goto ErrOut0; ErrOut2: PTErr = KCP_MEM_UNLOCK_ERR; goto ErrOut0; ErrOut1: PTErr = KCP_BAD_ARG; ErrOut0: if (PTDataH != NULL) { *futSrc = fut_lock_fut (PTDataH); } if (*futSrc != FUT_NULL) fut_free (*futSrc); if (PTHdr != NULL) freeBufferPtr (PTHdr); if (PTHdrH != NULL) freeBuffer (PTHdrH); if (*PTRefNumNew != 0) PTCheckOut (*PTRefNumNew); goto getOut; }
void DisplayDeviceOpenGL::render(const Renderable* r) const { if(!r->isEnabled()) { // Renderable item not enabled then early return. return; } StencilScopePtr stencil_scope; if(r->hasClipSettings()) { ModelManager2D mm(r->getPosition().x, r->getPosition().y); auto clip_shape = r->getStencilMask(); bool cam_set = false; if(clip_shape->getCamera() == nullptr && r->getCamera() != nullptr) { cam_set = true; clip_shape->setCamera(r->getCamera()); } stencil_scope.reset(new StencilScopeOGL(r->getStencilSettings())); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glClear(GL_STENCIL_BUFFER_BIT); render(clip_shape.get()); stencil_scope->applyNewSettings(keep_stencil_settings); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); if(cam_set) { clip_shape->setCamera(nullptr); } } auto shader = r->getShader(); shader->makeActive(); BlendEquationScopeOGL be_scope(*r); BlendModeScopeOGL bm_scope(*r); // apply lighting/depth check/depth write here. bool use_lighting = r->isLightingStateSet() ? r->useLighting() : false; // Set the depth enable. if(r->isDepthEnableStateSet()) { if(get_current_depth_enable() != r->isDepthEnabled()) { if(r->isDepthEnabled()) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } get_current_depth_enable() = r->isDepthEnabled(); } } else { // We assume that depth is disabled if not specified. if(get_current_depth_enable() == true) { glDisable(GL_DEPTH_TEST); get_current_depth_enable() = false; } } glm::mat4 pmat(1.0f); glm::mat4 vmat(1.0f); if(r->getCamera()) { // set camera here. pmat = r->getCamera()->getProjectionMat(); vmat = r->getCamera()->getViewMat(); } else if(get_default_camera() != nullptr) { pmat = get_default_camera()->getProjectionMat(); vmat = get_default_camera()->getViewMat(); } if(use_lighting) { for(auto lp : r->getLights()) { /// xxx need to set lights here. } } if(r->getRenderTarget()) { r->getRenderTarget()->apply(); } if(shader->getPUniform() != ShaderProgram::INVALID_UNIFORM) { shader->setUniformValue(shader->getPUniform(), glm::value_ptr(pmat)); } if(shader->getMvUniform() != ShaderProgram::INVALID_UNIFORM) { glm::mat4 mvmat = vmat; if(is_global_model_matrix_valid() && !r->ignoreGlobalModelMatrix()) { mvmat *= get_global_model_matrix() * r->getModelMatrix(); } else { mvmat *= r->getModelMatrix(); } shader->setUniformValue(shader->getMvUniform(), glm::value_ptr(mvmat)); } if(shader->getMvpUniform() != ShaderProgram::INVALID_UNIFORM) { glm::mat4 pvmat(1.0f); if(is_global_model_matrix_valid() && !r->ignoreGlobalModelMatrix()) { pvmat = pmat * vmat * get_global_model_matrix() * r->getModelMatrix(); } else { pvmat = pmat * vmat * r->getModelMatrix(); } shader->setUniformValue(shader->getMvpUniform(), glm::value_ptr(pvmat)); } if(shader->getColorUniform() != ShaderProgram::INVALID_UNIFORM) { if(r->isColorSet()) { shader->setUniformValue(shader->getColorUniform(), r->getColor().asFloatVector()); } else { shader->setUniformValue(shader->getColorUniform(), ColorScope::getCurrentColor().asFloatVector()); } } shader->setUniformsForTexture(r->getTexture()); // XXX we should make this either or with setting the mvp/color uniforms above. auto uniform_draw_fn = shader->getUniformDrawFunction(); if(uniform_draw_fn) { uniform_draw_fn(shader); } // Loop through uniform render variables and set them. /*for(auto& urv : r->UniformRenderVariables()) { for(auto& rvd : urv->VariableDescritionList()) { auto rvdd = std::dynamic_pointer_cast<RenderVariableDeviceData>(rvd->GetDisplayData()); ASSERT_LOG(rvdd != nullptr, "Unable to cast DeviceData to RenderVariableDeviceData."); shader->SetUniformValue(rvdd->GetActiveMapIterator(), urv->Value()); } }*/ // Need to figure the interaction with shaders. /// XXX Need to create a mapping between attributes and the index value below. for(auto as : r->getAttributeSet()) { //ASSERT_LOG(as->getCount() > 0, "No (or negative) number of vertices in attribute set. " << as->getCount()); if((!as->isMultiDrawEnabled() && as->getCount() <= 0) || (as->isMultiDrawEnabled() && as->getMultiDrawCount() <= 0)) { //LOG_WARN("No (or negative) number of vertices in attribute set. " << as->getCount()); continue; } GLenum draw_mode = convert_drawing_mode(as->getDrawMode()); // apply blend, if any, from attribute set. BlendEquationScopeOGL be_scope(*as); BlendModeScopeOGL bm_scope(*as); if(shader->getColorUniform() != ShaderProgram::INVALID_UNIFORM && as->isColorSet()) { shader->setUniformValue(shader->getColorUniform(), as->getColor().asFloatVector()); } for(auto& attr : as->getAttributes()) { if(attr->isEnabled()) { shader->applyAttribute(attr); } } if(as->isInstanced()) { if(as->isIndexed()) { as->bindIndex(); // XXX as->GetIndexArray() should be as->GetIndexArray()+as->GetOffset() glDrawElementsInstanced(draw_mode, static_cast<GLsizei>(as->getCount()), convert_index_type(as->getIndexType()), as->getIndexArray(), as->getInstanceCount()); as->unbindIndex(); } else { glDrawArraysInstanced(draw_mode, static_cast<GLint>(as->getOffset()), static_cast<GLsizei>(as->getCount()), as->getInstanceCount()); } } else { if(as->isIndexed()) { as->bindIndex(); // XXX as->GetIndexArray() should be as->GetIndexArray()+as->GetOffset() glDrawElements(draw_mode, static_cast<GLsizei>(as->getCount()), convert_index_type(as->getIndexType()), as->getIndexArray()); as->unbindIndex(); } else { if(as->isMultiDrawEnabled()) { glMultiDrawArrays(draw_mode, as->getMultiOffsetArray().data(), as->getMultiCountArray().data(), as->getMultiDrawCount()); } else { glDrawArrays(draw_mode, static_cast<GLint>(as->getOffset()), static_cast<GLsizei>(as->getCount())); } } } shader->cleanUpAfterDraw(); glBindBuffer(GL_ARRAY_BUFFER, 0); } if(r->getRenderTarget()) { r->getRenderTarget()->unapply(); } }
int getSwapInterval() const { makeActive(); return wglGetSwapIntervalEXT != nullptr ? wglGetSwapIntervalEXT() : 0; }
bool setSwapInterval (int numFramesPerSwap) { makeActive(); return wglSwapIntervalEXT != nullptr && wglSwapIntervalEXT (numFramesPerSwap) != FALSE; }
bool setPixelFormat (const OpenGLPixelFormat& pixelFormat) { makeActive(); PIXELFORMATDESCRIPTOR pfd; initialisePixelFormatDescriptor (pfd, pixelFormat); int format = 0; if (wglChoosePixelFormatARB != nullptr) { int atts[64]; int n = 0; atts[n++] = WGL_DRAW_TO_WINDOW_ARB; atts[n++] = GL_TRUE; atts[n++] = WGL_SUPPORT_OPENGL_ARB; atts[n++] = GL_TRUE; atts[n++] = WGL_DOUBLE_BUFFER_ARB; atts[n++] = GL_TRUE; atts[n++] = WGL_PIXEL_TYPE_ARB; atts[n++] = WGL_TYPE_RGBA_ARB; atts[n++] = WGL_COLOR_BITS_ARB; atts[n++] = pfd.cColorBits; atts[n++] = WGL_RED_BITS_ARB; atts[n++] = pixelFormat.redBits; atts[n++] = WGL_GREEN_BITS_ARB; atts[n++] = pixelFormat.greenBits; atts[n++] = WGL_BLUE_BITS_ARB; atts[n++] = pixelFormat.blueBits; atts[n++] = WGL_ALPHA_BITS_ARB; atts[n++] = pixelFormat.alphaBits; atts[n++] = WGL_DEPTH_BITS_ARB; atts[n++] = pixelFormat.depthBufferBits; atts[n++] = WGL_STENCIL_BITS_ARB; atts[n++] = pixelFormat.stencilBufferBits; atts[n++] = WGL_ACCUM_RED_BITS_ARB; atts[n++] = pixelFormat.accumulationBufferRedBits; atts[n++] = WGL_ACCUM_GREEN_BITS_ARB; atts[n++] = pixelFormat.accumulationBufferGreenBits; atts[n++] = WGL_ACCUM_BLUE_BITS_ARB; atts[n++] = pixelFormat.accumulationBufferBlueBits; atts[n++] = WGL_ACCUM_ALPHA_BITS_ARB; atts[n++] = pixelFormat.accumulationBufferAlphaBits; if (pixelFormat.multisamplingLevel > 0 && OpenGLHelpers::isExtensionSupported ("GL_ARB_multisample")) { atts[n++] = WGL_SAMPLE_BUFFERS_ARB; atts[n++] = 1; atts[n++] = WGL_SAMPLES_ARB; atts[n++] = pixelFormat.multisamplingLevel; } atts[n++] = 0; jassert (n <= numElementsInArray (atts)); UINT formatsCount = 0; wglChoosePixelFormatARB (dc, atts, nullptr, 1, &format, &formatsCount); } if (format == 0) format = ChoosePixelFormat (dc, &pfd); if (format != 0) { makeInactive(); // win32 can't change the pixel format of a window, so need to delete the // old one and create a new one.. jassert (nativeWindow != 0); ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc); nativeWindow = nullptr; createNativeWindow(); if (SetPixelFormat (dc, format, &pfd)) { wglDeleteContext (renderContext); renderContext = wglCreateContext (dc); jassert (renderContext != 0); return renderContext != 0; } } return false; }
/* PTActivate reads the PT data from an external memory block and * sets up the technology specific PT memory structures. Before loading * the PT, check to make sure that it matches the "checked in" info. */ PTErr_t PTActivate( PTRefNum_t PTRefNum, KpInt32_t mBlkSize, PTAddr_t PTAddr) { PTErr_t errnum; KpFd_t fd; KpHandle_t PTHdr, PTData, PTHdr2; fut_hdr_p futp; #if !defined KCMS_NO_CRC KpChar_t strCRCmade[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpChar_t strCRCfound[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpInt32_t crcAttrSize, crc32; #endif KpInt32_t attrSize; PTType_t format; errnum = getPTStatus (PTRefNum); if (errnum != KCP_PT_INACTIVE) { goto ErrOut1; } /* initialize memory file manager */ if (KpOpen (NULL, "m", &fd, NULL, (KpGenericPtr_t)PTAddr, mBlkSize) != KCMS_IO_SUCCESS) { errnum = KCP_SYSERR_1; goto ErrOut1; } /* read in the encoded header, verify that its the same as the original, then discard */ errnum = TpReadHdr (&fd, &PTHdr2, &format); if (errnum != KCP_SUCCESS ) { goto ErrOut2; } #if defined KCP_DIAG_LOG {KpChar_t string[256]; sprintf (string, "\nPTActivate\n PTRefNum %x, mBlkSize %d, PTAddr %x, format %x\n", PTRefNum, mBlkSize, PTAddr, format); kcpDiagLog (string);} #endif /* get and save size of attributes */ futp = lockBuffer (PTHdr2); attrSize = futp->idstr_len; unlockBuffer (PTHdr2); PTHdr = getPTHdr (PTRefNum); /* get the original PT header */ /* make sure the PT header and checkin info match */ errnum = TpCompareHdr (PTHdr, PTHdr2); (void) TpFreeHdr (PTHdr2); /* free the header */ if (errnum != KCP_SUCCESS) { /* then check for an error in hdrVerify */ goto ErrOut2; } #if !defined KCP_ICC_ONLY switch (format) { case PTTYPE_FUTF: /* discard the attribute info */ if (Kp_skip (&fd, attrSize) != KCMS_IO_SUCCESS){ /* may have been setAttribute after checkin */ errnum = KCP_PTERR_3; goto ErrOut2; } break; default: break; } #endif errnum = TpReadData (&fd, format, PTRefNum, PTHdr, &PTData); /* get the PT data */ if (errnum == KCP_SUCCESS) { if (PTMemTest () == 0) { /* enough memory to continue operations? */ errnum = KCP_NO_ACTIVATE_MEM; goto ErrOut3; } #if !defined KCMS_NO_CRC errnum = TpCalCrc (PTHdr, PTData, &crc32); /* calculate the CRC */ if (errnum == KCP_SUCCESS) { KpItoa(crc32, strCRCmade); crcAttrSize = KCM_MAX_ATTRIB_VALUE_LENGTH; errnum = PTGetAttribute(PTRefNum, KCM_CRC, &crcAttrSize, strCRCfound); if (errnum == KCP_INVAL_PTA_TAG) { /* if not present, just set it */ PTSetAttribute(PTRefNum, KCM_CRC, strCRCmade); errnum = KCP_SUCCESS; } else { /* if ((errnum == KCP_SUCCESS)*/ /* if present, must match */ /* && (strcmp (strCRCmade, strCRCfound) != 0)) { */ /* errnum = KCP_INCON_PT; */ /* goto ErrOut3; */ /* } */ } } #endif } if (errnum == KCP_SUCCESS) { /* Everything's OK, now activate */ makeActive (PTRefNum, PTData); } ErrOut2: (void) Kp_close (&fd); ErrOut1: return (errnum); ErrOut3: (void) TpFreeData (PTData); /* Release the PT memory */ goto ErrOut2; }
struct eventResult cbEvent(newtComponent co, struct event ev) { struct checkbox * cb = co->data; struct eventResult er; const char * cur; if (ev.when == EV_NORMAL) { switch (ev.event) { case EV_FOCUS: cb->hasFocus = 1; cbDraw(co); er.result = ER_SWALLOWED; break; case EV_UNFOCUS: cb->hasFocus = 0; cbDraw(co); er.result = ER_SWALLOWED; break; case EV_KEYPRESS: if (ev.u.key == ' ') { if (cb->type == RADIO) { makeActive(co); } else if (cb->type == CHECK) { cur = strchr(cb->seq, *cb->result); if (!cur) *cb->result = *cb->seq; else { cur++; if (! *cur) *cb->result = *cb->seq; else *cb->result = *cur; } cbDraw(co); er.result = ER_SWALLOWED; if (co->callback) co->callback(co, co->callbackData); } else { er.result = ER_IGNORED; } } else if(ev.u.key == NEWT_KEY_ENTER) { er.result = ER_IGNORED; } else { er.result = ER_IGNORED; } break; case EV_MOUSE: if (ev.u.mouse.type == MOUSE_BUTTON_DOWN) { if (cb->type == RADIO) { makeActive(co); } else if (cb->type == CHECK) { cur = strchr(cb->seq, *cb->result); if (!cur) *cb->result = *cb->seq; else { cur++; if (! *cur) *cb->result = *cb->seq; else *cb->result = *cur; } cbDraw(co); er.result = ER_SWALLOWED; if (co->callback) co->callback(co, co->callbackData); } } } } else er.result = ER_IGNORED; return er; }
//BEGIN KateViewSpace KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, const char *name) : QWidget(parent) , m_viewManager(viewManager) , m_isActiveSpace(false) { setObjectName(QString::fromLatin1(name)); QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(0); layout->setMargin(0); //BEGIN tab bar QHBoxLayout *hLayout = new QHBoxLayout(); hLayout->setSpacing(0); hLayout->setMargin(0); // add tab bar m_tabBar = new KateTabBar(this); connect(m_tabBar, &KateTabBar::currentChanged, this, &KateViewSpace::changeView); connect(m_tabBar, &KateTabBar::moreTabsRequested, this, &KateViewSpace::addTabs); connect(m_tabBar, &KateTabBar::lessTabsRequested, this, &KateViewSpace::removeTabs); connect(m_tabBar, &KateTabBar::closeTabRequested, this, &KateViewSpace::closeTabRequest, Qt::QueuedConnection); connect(m_tabBar, &KateTabBar::contextMenuRequest, this, &KateViewSpace::showContextMenu, Qt::QueuedConnection); connect(m_tabBar, &KateTabBar::newTabRequested, this, &KateViewSpace::createNewDocument); connect(m_tabBar, SIGNAL(activateViewSpaceRequested()), this, SLOT(makeActive())); hLayout->addWidget(m_tabBar); // add quick open m_quickOpen = new QToolButton(this); m_quickOpen->setAutoRaise(true); KAcceleratorManager::setNoAccel(m_quickOpen); m_quickOpen->installEventFilter(this); // on click, active this view space hLayout->addWidget(m_quickOpen); // forward tab bar quick open action to globa quick open action QAction * bridge = new QAction(QIcon::fromTheme(QStringLiteral("tab-duplicate")), i18nc("indicator for more documents", "+%1", 100), this); m_quickOpen->setDefaultAction(bridge); QAction * quickOpen = m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_quick_open")); Q_ASSERT(quickOpen); bridge->setToolTip(quickOpen->toolTip()); bridge->setWhatsThis(i18n("Click here to switch to the Quick Open view.")); connect(bridge, SIGNAL(triggered()), quickOpen, SLOT(trigger())); // add vertical split view space m_split = new QToolButton(this); m_split->setAutoRaise(true); m_split->setPopupMode(QToolButton::InstantPopup); m_split->setIcon(QIcon::fromTheme(QStringLiteral("view-split-left-right"))); m_split->addAction(m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_split_vert"))); m_split->addAction(m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_split_horiz"))); m_split->addAction(m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_close_current_space"))); m_split->addAction(m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_close_others"))); m_split->addAction(m_viewManager->mainWindow()->actionCollection()->action(QStringLiteral("view_hide_others"))); m_split->setWhatsThis(i18n("Control view space splitting")); m_split->installEventFilter(this); // on click, active this view space hLayout->addWidget(m_split); layout->addLayout(hLayout); //END tab bar stack = new QStackedWidget(this); stack->setFocus(); stack->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding)); layout->addWidget(stack); m_group.clear(); // connect signal to hide/show statusbar connect(m_viewManager->mainWindow(), SIGNAL(statusBarToggled()), this, SLOT(statusBarToggled())); connect(m_viewManager->mainWindow(), SIGNAL(tabBarToggled()), this, SLOT(tabBarToggled())); // init the bars... statusBarToggled(); tabBarToggled(); // make sure we show correct number of hidden documents updateQuickOpen(); connect(KateApp::self()->documentManager(), SIGNAL(documentCreated(KTextEditor::Document*)), this, SLOT(updateQuickOpen())); connect(KateApp::self()->documentManager(), SIGNAL(documentsDeleted(const QList<KTextEditor::Document*>&)), this, SLOT(updateQuickOpen())); }