diff window/menuitem.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 223b71206888
children 4416cfac86ae
line wrap: on
line diff
--- a/window/menuitem.cc
+++ b/window/menuitem.cc
@@ -26,7 +26,7 @@
  */
 
 
-#include"menuitem.h"
+#include "menuitem.h"
 
 #define Button WidButton
 #define Scale WidScale
@@ -44,12 +44,13 @@ MenuItem::MenuItem(PicContainer* parent,
 	SetPic(parent->create_node(r_orig, 0));
 	menu_width = r_orig.width();
 	menu_height = r_orig.height();
-	label = 0;
+	label = NULL;
 	lb_width  = 0; lb_right = 0;
 	lb_left = -1; lb_bottom = -1;
 	int i;
 	for (i=0; i<x_size*y_size; i++) item.push_back(0);
-};
+}
+
 void MenuItem::SetLabelLeft(PicWidget* lb, const Rect& min_rect, const Rect& min_margin) {
 	lb_width = min_rect.width();
 	lb_right = min_margin.width();
@@ -57,6 +58,7 @@ void MenuItem::SetLabelLeft(PicWidget* l
 	lb_bottom = -1;
 	label = lb;
 }
+
 void MenuItem::SetLabelTop(PicWidget* lb, const Rect& left_margin, const Rect& bottom_margin) {
 	lb_left = left_margin.width();
 	lb_bottom = bottom_margin.height();
@@ -64,25 +66,29 @@ void MenuItem::SetLabelTop(PicWidget* lb
 	lb_right = -1;
 	label = lb;
 }
+
 void MenuItem::SetValue(int new_value) {
 	SetValueImpl(new_value);
 	if (value_ptr) *value_ptr = new_value;
 	if (set_func) (*set_func)(set_pointer, this);
 }
+
 void MenuItem::activate(void) {
 	iterator it;
 	for (it=item.begin(); it!=item.end(); it++) {
-		if (*it == 0) continue;
+		if (*it == NULL) continue;
 		(*it)->activate();
 	}
 }
+
 void MenuItem::deactivate(void) {
 	iterator it;
 	for (it=item.begin(); it!=item.end(); it++) {
-		if (*it == 0) continue;
+		if (*it == NULL) continue;
 		(*it)->deactivate();
 	}
 }
+
 void MenuItem::pack(void) {
 	int x_min = 0, y_min = 0;
 	if (lb_width == -1) { // 上にラベルを貼る
@@ -112,14 +118,14 @@ void MenuItem::pack(void) {
 	int* item_height = new int[y_size];
 	int* item_x = new int[x_size];
 	int* item_y = new int[y_size];
-	int i,j;
+	int i, j;
 	for (i=0; i<x_size; i++) item_width[i]=0;
 	for (i=0; i<y_size; i++) item_height[i]=0;
 	
 	iterator it = item.begin();
 	for (i=0; i<y_size; i++) {
 		for (j=0; j<x_size; j++) {
-			if (*it != 0 && (*it)->Pic() != 0) {
+			if (*it != NULL && (*it)->Pic() != NULL) {
 				PicBase* pic = (*it)->Pic();
 				if (item_width[j] < pic->Width()) item_width[j] = pic->Width();
 				if (item_height[i] < pic->Height()) item_height[i] = pic->Height();
@@ -175,7 +181,7 @@ void MenuItem::pack(void) {
 	it = item.begin();
 	for (i=0; i<y_size; i++) {
 		for (j=0; j<x_size; j++) {
-			if (*it != 0 && (*it)->Pic() != 0) {
+			if (*it != NULL && (*it)->Pic() != NULL) {
 				PicBase* pic = (*it)->Pic();
 				int x0 = item_x[j]-pic->Width()/2;
 				int y0 = item_y[i]-pic->Height()/2;
@@ -195,16 +201,18 @@ void MenuItem::pack(void) {
 	delete[] item_height;
 	delete[] item_x;
 	delete[] item_y;
-};
+}
 
 RadioButton::RadioButton(Event::Container& _container, PicContainer* _parent, const Rect& r_orig, int _x_size, int _y_size, int* _value_ptr, const Rect& _button_r, int _text_size, const Color& _fore, const Color& _pressed, const Color& _back) :
 	MenuItem(_parent, r_orig, _x_size, _y_size,_value_ptr),
 	container(_container), parent(_parent), text_size(_text_size), button_rect(_button_r), buttons(0),
 	fore_color(_fore), pressed_color(_pressed), back_color(_back) {
 }
+
 void RadioButton::Add(const char* s, bool is_center) {
 	Add(s, fore_color, pressed_color, back_color, is_center);
 }
+
 void RadioButton::Add(const char* s, const Color& fore, const Color& pressed, const Color& back, bool is_center) {
 	if (buttons >= x_size*y_size) {
 		fprintf(stderr,"too many buttons (%d/%d) in RadioButton::Add ; text = %s\n",x_size,y_size,s);
@@ -221,7 +229,8 @@ void RadioButton::Add(const char* s, con
 	else x_pos = buttons / y_size, y_pos = buttons % y_size;
 	item[x_pos + y_pos*x_size] = wid;
 	buttons++;
-};
+}
+
 void RadioButton::PressCallback(void* pointer, Button* from) {
 	RadioButton* wid = (RadioButton*)pointer;
 	int i;
@@ -231,13 +240,13 @@ void RadioButton::PressCallback(void* po
 			return;
 		}
 	}
-	return;
 }
+
 void RadioButton::SetValueImpl(int new_value) {
 	int i;
 	for (i=0; i<x_size*y_size; i++) {
 		Button* wid = dynamic_cast<Button*>(item[i]);
-		if (wid) {
+		if (wid != NULL) {
 			if (i == new_value) wid->Toggle(true);
 			else wid->Toggle(false);
 		}