Ver código fonte

Upped to C++11 because stdint and added moar Pixel constructors!

Florian DORMONT 10 anos atrás
pai
commit
237107e060
3 arquivos alterados com 16 adições e 7 exclusões
  1. 1 2
      Makefile
  2. 14 4
      include/Graphics.h
  3. 1 1
      src/Graphics.cpp

+ 1 - 2
Makefile

@@ -14,7 +14,7 @@ CC = nspire-gcc
 CFLAGS = $(CFLAGS_COMMON) -std=gnu11
 
 CPP = nspire-g++
-CPPFLAGS = $(CFLAGS_COMMON) -std=gnu++98
+CPPFLAGS = $(CFLAGS_COMMON) -std=gnu++11
 
 LDFLAGS = $(CFLAGS_COMMON)
 
@@ -63,4 +63,3 @@ clean:
 
 run: all
 	tilp -ns $(EXE) > /dev/null
-

+ 14 - 4
include/Graphics.h

@@ -1,29 +1,39 @@
 #ifndef INCLUDE_GRAPHICS_H
 #define INCLUDE_GRAPHICS_H
 
-namespace WalrusRPG{ namespace Graphics {
+#include <cstdint>
 
+namespace WalrusRPG{ namespace Graphics {
 
 	/*
 	 * Pixel structure
 	 * TODO?: Convert this into a class to hide value?
 	 */
 	union Pixel {
-		::uint16_t value;
+		std::uint16_t value;
 		struct {
 			unsigned r : 5;
 			unsigned g : 6;
 			unsigned b : 5;
 		};
 
-		Pixel(::uint8_t red, ::uint8_t green, ::uint8_t blue) : r(red>>3), g(green>>2), b(blue>>3) {
+		Pixel(std::uint16_t color) : value(color) {
+
+		}
+
+		Pixel(Pixel &pix) : value(pix.value) {
+
+		}
+
+		Pixel(std::uint8_t red, std::uint8_t green, std::uint8_t blue) : r(red>>3), g(green>>2), b(blue>>3) {
 
 		}
 
 		// Overloading (unsigned) typecast
-		operator ::uint16_t() {
+		operator std::uint16_t() {
 			return value;
 		}
+
 		Pixel& operator=(unsigned value) {
 			this->value = value;
 			return *this;

+ 1 - 1
src/Graphics.cpp

@@ -61,7 +61,7 @@ void GRAPHICS::buffer_swap()
 void GRAPHICS::buffer_fill(unsigned color)
 {
 	unsigned *buffer_back_32 = (unsigned *) buffer_back;
-	color += color << 16;
+	color |= color << 16; // To avoid stupid overflows
 	for (unsigned i = 0; i < (BUFFER_SIZE / 4); i++)
 		buffer_back_32[i] = color;
 }