Browse Source

Allow BoxComponents to choose their color (for fwd/back buttons), load anime texture from file

pull/2/head
Odilitime 5 years ago
parent
commit
4b13f6891b
  1. 24
      src/graphics/components/AnimeComponent.cpp
  2. 27
      src/graphics/components/BoxComponent.cpp
  3. 4
      src/graphics/components/BoxComponent.h

24
src/graphics/components/AnimeComponent.cpp

@ -1,11 +1,9 @@ @@ -1,11 +1,9 @@
#include "AnimeComponent.h"
#ifndef _MSC_VER
#include "../../../anime.h"
#endif
#include <cmath>
#include <iostream>
#include "pnm.h"
AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) : BoxComponent(rawX, rawY, rawWidth, rawHeight, passedWindowWidth, passedWindowHeight){
AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) : BoxComponent(rawX, rawY, rawWidth, rawHeight, passedWindowWidth, 0x000000FF, passedWindowHeight){
//std::cout << "AnimeComponent::AnimeComponent" << std::endl;
windowWidth = passedWindowWidth;
@ -15,16 +13,22 @@ AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float r @@ -15,16 +13,22 @@ AnimeComponent::AnimeComponent(const float rawX, const float rawY, const float r
y = rawY;
width = rawWidth;
height = rawHeight;
RGBAPNMObject *anime = readPPM("anime.pnm");
if (!anime) {
std::cout << "Can't set up anime component, couldn't read anime.pnm" << std::endl;
}
for (int py = 0; py < 1024; py++) {
for (int px = 0; px < 1024; px++) {
#ifndef _MSC_VER
for (int i = 0; i < 4; i++) {
data[1023 - py][px][i] = anime.pixel_data[((px * 4) + (py * 4 * 1024)) + i];
if (anime) {
for (int i = 0; i < 4; i++) {
//data[1023 - py][px][i] = anime.pixel_data[((px * 4) + (py * 4 * 1024)) + i];
data[1023 - py][px][i] = anime->m_Ptr[((px * 4) + (py * 4 * 1024)) + i];
}
} else {
data[1023 - py][px][3] = 0x00; // just make it all transparent for now
}
#else
data[1023 - py][px][3] = 0x00; // just make it all transparent for now
#endif
}
}

27
src/graphics/components/BoxComponent.cpp

@ -6,7 +6,7 @@ BoxComponent::BoxComponent() { @@ -6,7 +6,7 @@ BoxComponent::BoxComponent() {
//std::cout << "BoxComponent::BoxComponent - empty" << std::endl;
}
BoxComponent::BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) {
BoxComponent::BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const unsigned int hexColor, const int passedWindowWidth, const int passedWindowHeight) {
//std::cout << "BoxComponent::BoxComponent - data" << std::endl;
//std::cout << "BoxComponent::BoxComponent - window: " << windowWidth << "x" << windowHeight << " passed " << passedWindowWidth << "x" << passedWindowHeight << std::endl;
@ -32,12 +32,13 @@ BoxComponent::BoxComponent(const float rawX, const float rawY, const float rawWi @@ -32,12 +32,13 @@ BoxComponent::BoxComponent(const float rawX, const float rawY, const float rawWi
initialHeight = height;
initialWindowWidth = windowWidth;
initialWindowHeight = windowHeight;
for (int i = 0; i < 3; i++) {
data[0][0][i] = 0x88; // set RGB color
}
data[0][0][3] = 0xff; // set alpha
// set texture color
data[0][0][0] = (hexColor >> 24) & 0xFF;
data[0][0][1] = (hexColor >> 16) & 0xFF;
data[0][0][2] = (hexColor >> 8) & 0xFF;
data[0][0][3] = (hexColor >> 0) & 0xFF;
float vx = rawX;
float vy = rawY;
//std::cout << "placing box at " << (int)vx << "x" << (int)vy << " size: " << (int)rawWidth << "x" << (int)rawHeight << std::endl;
@ -149,6 +150,18 @@ void BoxComponent::render() { @@ -149,6 +150,18 @@ void BoxComponent::render() {
// can actuall delete vertices here
}
// this seems to work 17-08-10
// for box
// anime girl, we'll get aspect ratio breakage
void BoxComponent::resize(const int passedWindowWidth, const int passedWindowHeight) {
//std::cout << "BoxComponent::resize" << std::endl;
windowWidth = passedWindowWidth;
windowHeight = passedWindowHeight;
//std::cout << "BoxComponent::resize - boundToPage " << boundToPage << std::endl;
// figure out new vertices
}
/*
void BoxComponent::resize(const int passedWindowWidth, const int passedWindowHeight) {

4
src/graphics/components/BoxComponent.h

@ -25,10 +25,10 @@ protected: @@ -25,10 +25,10 @@ protected:
int initialWindowHeight;
public:
BoxComponent();
BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
BoxComponent(const float rawX, const float rawY, const float rawWidth, const float rawHeight, const unsigned int hexColor, const int passedWindowWidth, const int passedWindowHeight);
~BoxComponent();
virtual void render();
//void resize(const int passedWindowWidth, const int passedWindowHeight);
virtual void resize(const int passedWindowWidth, const int passedWindowHeight);
};
#endif

Loading…
Cancel
Save