void GuiList::Draw() { if (!IsVisible()) { return; } // This rectangle bounds the height of the list and the widest item. // This is not necessarily the size of the list box, which may be bigger or smaller! Rect r = GetRect(this); // Draw bg - TODO just the parts not covered by child items AmjuGL::Disable(AmjuGL::AMJU_TEXTURE_2D); PushColour(); AmjuGL::SetColour(1, 1, 1, 1); DrawSolidRect(r); PopColour(); AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D); GuiComposite::Draw(); // Border AmjuGL::Disable(AmjuGL::AMJU_TEXTURE_2D); PushColour(); AmjuGL::SetColour(0, 0, 0, 1); DrawRect(r); PopColour(); AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D); }
void TrailCircle::Draw() { static GuiImage* circleImg = 0; static GuiText text; if (!circleImg) { circleImg = new GuiImage; Texture* tex = (Texture*)TheResourceManager::Instance()->GetRes("circ1.png"); tex->SetFilter(AmjuGL::AMJU_TEXTURE_NICE); circleImg->SetTexture(tex); float aspect = (float)Screen::X() / (float)Screen::Y(); circleImg->SetSize(Vec2f(CIRCLE_SIZE, CIRCLE_SIZE * aspect)); text.SetSize(Vec2f(0.1f, 0.1f)); } const Colour BLACK(0, 0, 0, 1); const Colour WHITE(1, 1, 1, 1); const Colour RED(1, 0, 0, 1); circleImg->SetLocalPos(Vec2f(m_pos.x - CIRCLE_SIZE * 0.5f, m_pos.y + CIRCLE_SIZE * 0.5f)); PushColour(); MultColour(m_incorrect ? RED : (m_clicked ? BLACK : WHITE)); circleImg->Draw(); PopColour(); // Draw number/letter text.SetSize(Vec2f(0.2f, 0.1f)); text.SetJust(GuiText::AMJU_JUST_CENTRE); text.SetLocalPos(m_pos + Vec2f(-0.1f, 0.012f)); text.SetText(m_str); text.SetFgCol(m_clicked || m_incorrect ? WHITE : BLACK); text.Draw(); }
void LayerSprite::DrawLayers(const Vec2f& pos, float size) { AmjuGL::Tri t[2]; m_seq.MakeTris(m_cellNum, size, t, 0, 0); //pos.x, pos.y); AmjuGL::Tris tris; tris.reserve(2); tris.push_back(t[0]); tris.push_back(t[1]); m_triList->Set(tris); // TODO Only when cellNum changes AmjuGL::PushMatrix(); AmjuGL::Translate(pos.x, 0, pos.y); for (LayerMap::iterator it = m_map.begin(); it != m_map.end(); ++it) { const SpriteLayer& layer = it->second; if (!layer.visible) { continue; } Assert(layer.tex); layer.tex->UseThisTexture(); AmjuGL::SetTextureFilter(AmjuGL::AMJU_TEXTURE_NEAREST); PushColour(); MultColour(layer.colour); AmjuGL::Draw(m_triList); PopColour(); } AmjuGL::PopMatrix(); }
void Ve1Node::Draw() { AmjuGL::PushAttrib(AmjuGL::AMJU_TEXTURE_2D); AmjuGL::Disable(AmjuGL::AMJU_TEXTURE_2D); PushColour(); if (m_obj->IsSelected()) { MultColour(Colour(1, 0, 0, 1)); } else { MultColour(Colour(0, 0, 1, 1)); // So visible, grey is not very noticeable } Assert(m_obj->GetAABB()); DrawSolidAABB(*(m_obj->GetAABB())); DrawAABB(*(m_obj->GetAABB())); Vec2f screenpos; Vec3f pos = m_obj->GetPos(); Project(pos, &screenpos); PopColour(); AmjuGL::PopAttrib(); }
void GuiKeyboard::Draw() { PushColour(); static const float G = 0.5f; AmjuGL::SetColour(Colour(G, G, G, 1)); AmjuGL::Disable(AmjuGL::AMJU_TEXTURE_2D); Rect r = GetRect(this); DrawSolidRect(r); AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D); PopColour(); GuiWindow::Draw(); }
void Spring::Draw() { // Draw OBB between the 2 particles..? // Spring can be twisted ?? // Just a line for now glLineWidth(2.0f); PushColour(); AmjuGL::SetColour(Colour(0, 0, 0, 1)); Vec3f p1 = m_particles[0]->GetPos(); Vec3f p2 = m_particles[1]->GetPos(); AmjuGL::DrawLine(AmjuGL::Vec3(p1.x, p1.y, p1.z), AmjuGL::Vec3(p2.x, p2.y, p2.z)); PopColour(); }
void GSTrailMakingTest::Draw2d() { // Draw lines connecting correctly clicked dots AmjuGL::Disable(AmjuGL::AMJU_TEXTURE_2D); PushColour(); AmjuGL::SetColour(Colour(0, 0, 0, 1)); glLineWidth(3); // ? Make AmjuGL func for (int i = 1; i <= m_currentCircle; i++) { Vec2f pos[2] = { m_circles[i - 1].m_pos, m_circles[i].m_pos }; AmjuGL::DrawLine(AmjuGL::Vec3(pos[0].x, pos[0].y, 0), AmjuGL::Vec3(pos[1].x, pos[1].y, 0)); } PopColour(); AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D); for (unsigned int i = 0; i < m_circles.size(); i++) { m_circles[i].Draw(); } GSCogTestBase::Draw2d(); // cursor }
void GuiTextEdit::Draw() { static const float BLINK_TIME_END = 0.5f; static const float BLINK_TIME_HALF = BLINK_TIME_END * 0.5f; if (!IsVisible()) { return; } float dt = TheTimer::Instance()->GetDt(); m_caretTimer += dt; m_drawCaret = false; if (m_caretTimer > BLINK_TIME_END) { m_caretTimer = 0; } else if (m_caretTimer < BLINK_TIME_HALF) { m_drawCaret = true; } if (HasFocus()) { // Draw border // TODO Could be image - allow flexible way to give GUIs themes static float t = 0; t += dt; PushColour(); float s = (sin(t * 5.0f) + 1.0f) * 0.5f; Colour c(s, s, 1, 1); AmjuGL::SetColour(c); //inverse ? m_fgCol : m_bgCol); AmjuGL::Disable(AmjuGL::AMJU_TEXTURE_2D); const float BORDER = 0.02f; m_rect.SetSize(GetSize() + Vec2f(2 * BORDER, 2 * BORDER)); m_rect.SetLocalPos(Vec2f(-BORDER, BORDER)); m_rect.SetCornerRadius(BORDER); m_rect.SetRoundCorners(0); m_rect.SetColour(c); m_rect.Draw(); AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D); PopColour(); } GuiText::Draw(); if (m_drawCaret && HasFocus()) { // Draw caret - TODO multi line PushColour(); AmjuGL::SetColour(m_drawCaret ? m_fgCol : m_bgCol); float startX = GetCombinedPos().x; float x = (GetFont()->GetTextWidth(m_text.substr(m_first, m_caret - m_first)) * GetFontSize() * m_scaleX) + startX; if (!m_triListCaret) { m_triListCaret = GetFont()->MakeTriList(0, 0, "|", 1.0f); } float y = GetCombinedPos().y - GetFontSize() * CHAR_HEIGHT_FOR_SIZE_1; AmjuGL::PushMatrix(); AmjuGL::Translate(x, y, 0); AmjuGL::Draw(m_triListCaret); AmjuGL::PopMatrix(); PopColour(); } }
BOOL FreeHandEPSFilter::ProcessToken() { // Decode the command, and execute it... switch (Token) { // state saving case EPSC_vms: if(!Import_gsave()) return FALSE; break; case EPSC_vmr: if(!Import_grestore()) return FALSE; break; case EPSC_vmrs: if(!Import_grestore()) return FALSE; if(!Import_gsave()) return FALSE; break; // tokens to ignore case EPSC_FREEHAND_IGNOREDTOKEN: break; // tokens which should be ignored and one entry discarded case EPSC_load: // the load part of a fill - discard the /clipper before it case EPSC_fhsetspreadallow: if(!Stack.Discard(1)) goto EPSError; break; case EPSC_concat: if(!Stack.DiscardArray()) goto EPSError; break; // complex paths... case EPSC_eomode: { INT32 ComplexStart; if(!Stack.Pop(&ComplexStart)) goto EPSError; // is this a start of a complex path? if(ComplexStart != TRUE) { ComplexPathMode = FALSE; } else { HadFirstOfComplexPath = FALSE; ComplexPathMode = TRUE; } } break; case EPSC_true: Stack.Push((INT32)TRUE); break; case EPSC_false: Stack.Push((INT32)FALSE); break; case EPSC_u: HadFirstOfComplexPath = FALSE; return EPSFilter::ProcessToken(); break; // colours case EPSC_Ka: case EPSC_ka: { DocColour Colour; if(PopColour(&Colour)) { // Remember this colour for future objects if (Token == EPSC_ka) { if (!SetFillColour(Colour)) goto NoMemory; } else { if (!SetLineColour(Colour)) goto NoMemory; } } else // Invalid colour operands goto EPSError; } break; case EPSC_Xa: case EPSC_xa: { DocColour Colour; if(PopNamedColour(&Colour)) { // Remember this colour for future objects if (Token == EPSC_xa) { if (!SetFillColour(Colour)) goto NoMemory; } else { if (!SetLineColour(Colour)) goto NoMemory; } } else // Invalid colour operands goto EPSError; } break; case EPSC_H: if(ComplexPathMode) { // in complex path mode - make this a filled one, not a discarded one Token = EPSC_S; } return EPSFilter::ProcessToken(); break; case EPSC_h: if(ComplexPathMode) { // in complex path mode - modify and process Token = EPSC_s; return EPSFilter::ProcessToken(); break; } // the hidden path closing operator - a grad fill thingy will follow shortly maybe... // this will prevent it being processed now, although it may get processed later on. HadhToken = TRUE; break; // for clipping masks, do some funky stuff case EPSC_q: // if there's a pending grad fill... if(DoingGradFill) { if(pPath != 0) { // right then, make a copy of the path... NodePath *pPathClone; if(!pPath->NodeCopy((Node **)&pPathClone)) { goto NoMemory; } // copy the flags EPSFlagsDefn EPSFlagsClone = EPSFlags; // send a token to finish and fill the path... Token = (pInkPath->IsFilled)?EPSC_f:EPSC_s; if(!EPSFilter::ProcessToken()) return FALSE; // restore the old fill if(!RestoreCurrentFill()) goto NoMemory; // restore the copy of the path pPath = pPathClone; pInkPath = &pPath->InkPath; // restore the flags EPSFlags = EPSFlagsClone; // definately want to send an h HadhToken = TRUE; } // done the grad fill DoingGradFill = FALSE; // restore the old token Token = EPSC_q; } // clipping started - have we got an h token to send? if(HadhToken) FHEF_SENDh // process this return EPSFilter::ProcessToken(); break; // for now, if there's no path, don't return a W case EPSC_W: if(pPath == 0) { // OK, now we want to get the last path we created, make a copy of it and then install it as the current one if(pLastPathSeen == 0) goto EPSError; // make a copy of it NodePath *pClone; if(!pLastPathSeen->NodeCopy((Node **)&pClone)) goto NoMemory; // delete it's attributes pClone->DeleteChildren(pClone->FindFirstChild()); // make it the current path pPath = pClone; pInkPath = &pPath->InkPath; ThePathType = PATH_NORMAL; EPSFlags.NoAttributes = TRUE; } if(pPath != 0) return EPSFilter::ProcessToken(); break; // we may need to modify path closing things if we're doing a grad fill case EPSC_s: case EPSC_S: if(Token == EPSC_S) { // if we've had an h token but no grad fill, send the h now if(HadhToken) FHEF_SENDh // if we've got a grad fill, modify the token we got if(DoingGradFill) Token = EPSC_b; } // process the possily modified token normally HadhToken = FALSE; return EPSFilter::ProcessToken(); break; // modify path closing for grad fills. case EPSC_n: if(DoingGradFill) { Token = EPSC_f; // we want to fill the thing HadhToken = FALSE; return EPSFilter::ProcessToken(); break; } HadhToken = FALSE; // ignore h's as this is another end path thingy... if(pPath != 0) return EPSFilter::ProcessToken(); break; // unset the had h token for other path closing things case EPSC_N: case EPSC_F: case EPSC_f: case EPSC_B: case EPSC_b: HadhToken = FALSE; return EPSFilter::ProcessToken(); break; // interested in path element things to switch off grad fills case EPSC_m: if(InText) { // if we're doing some text, discard the moveto command if(!Stack.Discard(2)) goto EPSError; break; } case EPSC_l: case EPSC_L: case EPSC_c: case EPSC_C: case EPSC_v: case EPSC_V: case EPSC_y: case EPSC_Y: // maybe we need an h token to be sent if(HadhToken) FHEF_SENDh // stop grad fill if(DoingGradFill) { // turn the grad fill state off DoingGradFill = FALSE; // restore the old fill type RestoreCurrentFill(); } return EPSFilter::ProcessToken(); break; case EPSC_recfill: { // get the colours DocColour StartColour, EndColour; if(!PopColour(&EndColour) || !PopColour(&StartColour)) goto EPSError; // discard the fill type thingy - we can only do colours if(!DiscardFillSubType()) goto EPSError; // OK, now a few coords DocCoord Centre; double Angle; DocRect BBox; if(!Stack.PopCoordPair(&BBox.hi) || !Stack.PopCoordPair(&BBox.lo) || !Stack.Pop(&Angle) || !Stack.PopCoordPair(&Centre)) goto EPSError; // munge the angle a little and get it into radians Angle += 225; Angle = (Angle * (2 * PI)) / 360; // see if we can get a more accurate BBox if(pPath != 0) { BBox = pPath->GetBoundingRect(); Centre.x = BBox.lo.x + (BBox.Width() / 2); Centre.y = BBox.lo.y + (BBox.Height() / 2); } // OK, we've got all the stuff we need to do some niceness on it BBox.Translate(0 - Centre.x, 0 - Centre.y); DocCoord StartPoint, EndPoint; StartPoint.x = Centre.x + (INT32)(((double)BBox.lo.x * cos(Angle)) - ((double)BBox.lo.y * sin(Angle))); StartPoint.y = Centre.y + (INT32)(((double)BBox.lo.x * sin(Angle)) + ((double)BBox.lo.y * cos(Angle))); EndPoint.x = Centre.x + (INT32)(((double)BBox.hi.x * cos(Angle)) - ((double)BBox.hi.y * sin(Angle))); EndPoint.y = Centre.y + (INT32)(((double)BBox.hi.x * sin(Angle)) + ((double)BBox.hi.y * cos(Angle))); // store current fill attribute SaveCurrentFill(); // set the fill if(!SetLinearFill(StartColour, EndColour, StartPoint, EndPoint)) goto NoMemory; // say we're doing a grad fill DoingGradFill = TRUE; HadhToken = FALSE; // absorb this } break; case EPSC_radfill: { // get the colours DocColour StartColour, EndColour; if(!PopColour(&StartColour) || !PopColour(&EndColour)) goto EPSError; // get the radius and centre coordinate DocCoord Centre; INT32 Radius; if(!Stack.PopCoord(&Radius) || !Stack.PopCoordPair(&Centre)) goto EPSError; // store current fill attribute SaveCurrentFill(); // set the fill DocCoord EndPoint(Centre.x + Radius, Centre.y); if(!SetRadialFill(StartColour, EndColour, Centre, EndPoint)) goto NoMemory; // say we're doing a grad fill DoingGradFill = TRUE; HadhToken = FALSE; } break; case EPSC_BeginSetup: // there's probably a colour list or something in that there setup thingy - search for the spots token { BOOL Found = FALSE; while(Found == FALSE) { if(!EPSFile->GetToken()) return FALSE; if(EPSFile->GetTokenType() == TOKEN_NORMAL) { if(camStrcmp(TokenBuf, _T("spots")) == 0) { // check to see if the array is about to start if(!EPSFile->GetToken()) return FALSE; if(TokenBuf[0] == '[') { TRACEUSER( "Ben", _T("Found spots\n")); Found = TRUE; } } } if(camStrncmp(TokenBuf, _T("%%EndSetup"), 10) == 0) { TRACEUSER( "Ben", _T("Met end of setup without finding spots\n")); break; } if(EPSFile->eof()) goto EPSError; } if(Found == TRUE) { InColours = TRUE; } } break; case EPSC_def: if(InColours) { // finished the colours... TRACEUSER( "Ben", _T("Finished spot colours\n")); // scan for the end of the setup section BOOL Found = FALSE; while(Found == FALSE) { if(!EPSFile->GetToken()) return FALSE; if(EPSFile->GetTokenType() == TOKEN_COMMENT) { if(camStrncmp(TokenBuf, _T("%%EndSetup"), 10) == 0) { TRACEUSER( "Ben", _T("Found end of setup\n")); Found = TRUE; } } if(EPSFile->eof()) goto EPSError; } // get the ] off the stack EPSCommand Ignored; Stack.PopCmd(&Ignored); // empty it... Stack.DeleteAll (); InColours = FALSE; } else { // probably a font type thingy - empty the stack including commands Stack.DeleteAll (); } break; case EPSC_newcmykcustomcolor: // OK, here's a named colour... add it to those known { // discard some random thingy if(!Stack.Discard()) goto EPSError; // get the name String_64 ColourName; if(!Stack.Pop(&ColourName)) goto EPSError; // get the components double C, M, Y, K; if(!Stack.Pop(&K) || !Stack.Pop(&Y) || !Stack.Pop(&M) || !Stack.Pop(&C)) goto EPSError; // make the new colour ColourCMYK Colour; Colour.Cyan = C; Colour.Magenta = M; Colour.Yellow = Y; Colour.Key = K; // add it if(!pNewColours->AddColour(&ColourName, &Colour)) goto NoMemory; // add it to the list of colours // this is a bit of a bodge, but never mind. Shouldn't be that bad. IndexedColour *TheNewColour = pNewColours->GetColour(ColourName); if(TheNewColour == 0) goto NoMemory; // add it to the list of colours // enough space? if((ColourArrayEntries + 1) >= ColourArraySize) { TRACEUSER( "Ben", _T("Extening colour array\n")); IndexedColour **NewPtr = (IndexedColour **)CCRealloc(ColourArray, (ColourArraySize + FHEF_COLOURARRAY_CHUNK) * sizeof(IndexedColour *)); if(NewPtr == 0) goto NoMemory; ColourArray = NewPtr; ColourArraySize += FHEF_COLOURARRAY_CHUNK; } // add ColourArray[ColourArrayEntries] = TheNewColour; ColourArrayEntries++; } break; // ignore text stuff case EPSC_makesetfont: if(!Stack.DiscardArray()) goto EPSError; if(!Stack.Discard(1)) goto EPSError; InText = TRUE; break; case EPSC_ts: if(!Stack.Discard(6)) goto EPSError; break; case EPSC_stob: case EPSC_sts: Stack.DeleteAll (); InText = FALSE; break; default: // Token not understood - pass on to base class return EPSFilter::ProcessToken(); } // No errors encountered while parsing this token and its operands. return TRUE; // Error handlers: EPSError: HandleEPSError(); return FALSE; NoMemory: HandleNoMemory(); return FALSE; }
void MyCharacterDecorator::AfterDraw() { PopColour(); AmjuGL::PopMatrix(); }