Atrinik Client  4.0
color_chooser.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <toolkit/colorspace.h>
34 
36 static int popup_draw(popup_struct *popup)
37 {
38  color_picker_struct *color_picker;
39  double rgb[3];
40  SDL_Rect box;
41 
42  color_picker = popup->custom_data;
43  color_picker_set_parent(color_picker, popup->x, popup->y);
44  color_picker->x = 10;
45  color_picker->y = 20;
46  color_picker_show(popup->surface, color_picker);
47 
48  colorspace_hsv2rgb(color_picker->hsv, rgb);
49  box.w = 100;
50  box.h = 200;
51  text_show_format(popup->surface, FONT_ARIAL11, color_picker->x + 180, color_picker->y, COLOR_WHITE, TEXT_MARKUP | TEXT_WORD_WRAP, &box, "Preview:\n[bar=#%.2X%.2X%.2X 80 20][border=#303030 80 20]\n\nChoose your desired color, then dismiss this popup.", (int) (255 * rgb[0]), (int) (255 * rgb[1]), (int) (255 * rgb[2]));
52 
53  return 1;
54 }
55 
57 static int popup_event(popup_struct *popup, SDL_Event *event)
58 {
59  color_picker_struct *color_picker;
60 
61  color_picker = popup->custom_data;
62 
63  if (color_picker_event(color_picker, event)) {
64  return 1;
65  }
66 
67  return -1;
68 }
69 
76 {
77  popup_struct *popup;
78  color_picker_struct *color_picker;
79 
80  color_picker = emalloc(sizeof(*color_picker));
81  color_picker_create(color_picker, 150);
82 
83  popup = popup_create(texture_get(TEXTURE_TYPE_SOFTWARE, "rectangle:300,200;[bar=widget_bg][border=widget_border -1 -1 2]"));
84  popup->draw_func = popup_draw;
85  popup->event_func = popup_event;
86  popup->custom_data = color_picker;
87  popup->modal = 0;
88  popup->destroy_on_switch = 1;
89  popup->button_left.button.texture = NULL;
90  popup->button_right.button.texture = texture_get(TEXTURE_TYPE_CLIENT, "button_round");
91  popup->button_right.button.texture_over = texture_get(TEXTURE_TYPE_CLIENT, "button_round_over");
92  popup->button_right.button.texture_pressed = texture_get(TEXTURE_TYPE_CLIENT, "button_round_down");
93  popup->button_right.x += 7;
94 
95  return color_picker;
96 }
#define TEXT_WORD_WRAP
Definition: text.h:226
int(* event_func)(struct popup_struct *popup, SDL_Event *event)
Definition: popup.h:148
int(* draw_func)(struct popup_struct *popup)
Definition: popup.h:127
void * custom_data
Definition: popup.h:78
button_struct button
Definition: popup.h:47
int x
Definition: popup.h:87
texture_struct * texture_get(texture_type_t type, const char *name)
Definition: texture.c:279
#define TEXT_MARKUP
Definition: text.h:224
texture_struct * texture_over
Definition: button.h:67
static int popup_event(popup_struct *popup, SDL_Event *event)
Definition: color_chooser.c:57
color_picker_struct * color_chooser_open(void)
Definition: color_chooser.c:75
texture_struct * texture
Definition: button.h:61
int y
Definition: popup.h:90
popup_button button_left
Definition: popup.h:93
texture_struct * texture_pressed
Definition: button.h:73
int x
Definition: popup.h:38
popup_button button_right
Definition: popup.h:96
SDL_Surface * surface
Definition: popup.h:65
void text_show_format(SDL_Surface *surface, font_struct *font, int x, int y, const char *color_notation, uint64_t flags, SDL_Rect *box, const char *format,...)
Definition: text.c:2289
static int popup_draw(popup_struct *popup)
Definition: color_chooser.c:36
#define COLOR_WHITE
Definition: text.h:289