3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / screen_savers / gravity / GravityView.cpp
blob1b0dea7669b8dfa6e52260c170ef0f31dc5c24e1
1 /*
2 * Copyright 2012-2013 Tri-Edge AI <triedgeai@gmail.com>
3 * Copyright 2014 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT license.
7 * Authors:
8 * Tri-Edge AI
9 * John Scipione, jscipione@gmail.com
13 #include "GravityView.h"
15 #include "Gravity.h"
16 #include "GravitySource.h"
17 #include "Particle.h"
19 #include <GL/glu.h>
22 GravityView::GravityView(BRect frame, Gravity* parent)
24 BGLView(frame, B_EMPTY_STRING, B_FOLLOW_NONE, 0,
25 BGL_RGB | BGL_DEPTH | BGL_DOUBLE),
26 fParent(parent),
27 fGravitySource(new GravitySource()),
28 fSize(128 << parent->Config.ParticleCount),
29 fShade(parent->Config.ShadeID)
31 Particle::Initialize(fSize, fShade);
35 GravityView::~GravityView()
37 Particle::Terminate();
38 delete fGravitySource;
42 void
43 GravityView::AttachedToWindow()
45 LockGL();
46 BGLView::AttachedToWindow();
48 glClearDepth(1.0f);
50 glEnable(GL_BLEND);
51 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
53 glMatrixMode(GL_PROJECTION);
54 glLoadIdentity();
55 gluPerspective(45.0f, Bounds().Width() / Bounds().Height(), 2.0f, 20000.0f);
56 glMatrixMode(GL_MODELVIEW);
57 glLoadIdentity();
59 glTranslatef(0.0f, 0.0f, -30.0f);
61 glDepthMask(GL_FALSE);
63 UnlockGL();
67 void
68 GravityView::DirectDraw()
70 int32 size = 128 << fParent->Config.ParticleCount;
71 int32 shade = fParent->Config.ShadeID;
73 // resize particle list if needed
74 if (size > fSize)
75 Particle::AddParticles(size, shade);
76 else if (size < fSize)
77 Particle::RemoveParticles(size, shade);
79 // recolor particles if needed
80 if (shade != fShade)
81 Particle::ColorParticles(size, shade);
83 fSize = size;
84 fShade = shade;
86 LockGL();
88 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
89 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
91 Particle::Tick();
92 fGravitySource->Tick();
94 SwapBuffers();
96 UnlockGL();