| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
static GdkColor CreateColor(uint8_t r, uint8_t g, uint8_t b) { |
| 4 |
GdkColor color; |
| 5 |
color.pixel = (r << 16) | (g << 8) | (b << 0); |
| 6 |
color.red = (r << 8) | (r << 0); |
| 7 |
color.green = (g << 8) | (g << 0); |
| 8 |
color.blue = (b << 8) | (b << 0); |
| 9 |
return color; |
| 10 |
} |
| 11 |
|
| 12 |
static GdkPixbuf* CreatePixbuf(const nall::image& image, bool scale = false) { |
| 13 |
nall::image gdkImage = image; |
| 14 |
gdkImage.transform(0, 32, 255u << 24, 255u << 0, 255u << 8, 255u << 16); |
| 15 |
if(scale) gdkImage.scale(15, 15); |
| 16 |
|
| 17 |
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, gdkImage.width, gdkImage.height); |
| 18 |
memcpy(gdk_pixbuf_get_pixels(pixbuf), gdkImage.data, gdkImage.width * gdkImage.height * 4); |
| 19 |
|
| 20 |
return pixbuf; |
| 21 |
} |
| 22 |
|
| 23 |
static GtkImage* CreateImage(const nall::image& image, bool scale = false) { |
| 24 |
GdkPixbuf* pixbuf = CreatePixbuf(image, scale); |
| 25 |
GtkImage* gtkImage = (GtkImage*)gtk_image_new_from_pixbuf(pixbuf); |
| 26 |
g_object_unref(pixbuf); |
| 27 |
return gtkImage; |
| 28 |
} |
| 29 |
|
| 30 |
static lstring DropPaths(GtkSelectionData* data) { |
| 31 |
gchar** uris = gtk_selection_data_get_uris(data); |
| 32 |
if(uris == nullptr) return {}; |
| 33 |
|
| 34 |
lstring paths; |
| 35 |
for(unsigned n = 0; uris[n] != nullptr; n++) { |
| 36 |
gchar* pathname = g_filename_from_uri(uris[n], nullptr, nullptr); |
| 37 |
if(pathname == nullptr) continue; |
| 38 |
|
| 39 |
string path = pathname; |
| 40 |
g_free(pathname); |
| 41 |
if(directory::exists(path) && !path.endsWith("/")) path.append("/"); |
| 42 |
paths.append(path); |
| 43 |
} |
| 44 |
|
| 45 |
g_strfreev(uris); |
| 46 |
return paths; |
| 47 |
} |
| 48 |
|
| 49 |
static Position GetDisplacement(Sizable* sizable) { |
| 50 |
Position position; |
| 51 |
while(sizable->state.parent) { |
| 52 |
Position displacement = sizable->state.parent->p.displacement(); |
| 53 |
position.x += displacement.x; |
| 54 |
position.y += displacement.y; |
| 55 |
sizable = sizable->state.parent; |
| 56 |
} |
| 57 |
return position; |
| 58 |
} |
| 59 |
|
| 60 |
static Layout* GetParentWidgetLayout(Sizable* sizable) { |
| 61 |
while(sizable) { |
| 62 |
if(sizable->state.parent && dynamic_cast<TabFrame*>(sizable->state.parent)) return (Layout*)sizable; |
| 63 |
sizable = sizable->state.parent; |
| 64 |
} |
| 65 |
return nullptr; |
| 66 |
} |
| 67 |
|
| 68 |
static Widget* GetParentWidget(Sizable* sizable) { |
| 69 |
while(sizable) { |
| 70 |
if(sizable->state.parent && dynamic_cast<TabFrame*>(sizable->state.parent)) return (Widget*)sizable->state.parent; |
| 71 |
sizable = sizable->state.parent; |
| 72 |
} |
| 73 |
return nullptr; |
| 74 |
} |
| 75 |
|
| 76 |
static Keyboard::Keycode Keysym(unsigned keysym) { |
| 77 |
switch(keysym) { |
| 78 |
case GDK_Escape: return Keyboard::Keycode::Escape; |
| 79 |
case GDK_F1: return Keyboard::Keycode::F1; |
| 80 |
case GDK_F2: return Keyboard::Keycode::F2; |
| 81 |
case GDK_F3: return Keyboard::Keycode::F3; |
| 82 |
case GDK_F4: return Keyboard::Keycode::F4; |
| 83 |
case GDK_F5: return Keyboard::Keycode::F5; |
| 84 |
case GDK_F6: return Keyboard::Keycode::F6; |
| 85 |
case GDK_F7: return Keyboard::Keycode::F7; |
| 86 |
case GDK_F8: return Keyboard::Keycode::F8; |
| 87 |
case GDK_F9: return Keyboard::Keycode::F9; |
| 88 |
case GDK_F10: return Keyboard::Keycode::F10; |
| 89 |
case GDK_F11: return Keyboard::Keycode::F11; |
| 90 |
case GDK_F12: return Keyboard::Keycode::F12; |
| 91 |
|
| 92 |
case GDK_Print: return Keyboard::Keycode::PrintScreen; |
| 93 |
//Keyboard::Keycode::SysRq |
| 94 |
case GDK_Scroll_Lock: return Keyboard::Keycode::ScrollLock; |
| 95 |
case GDK_Pause: return Keyboard::Keycode::Pause; |
| 96 |
//Keyboard::Keycode::Break |
| 97 |
|
| 98 |
case GDK_Insert: return Keyboard::Keycode::Insert; |
| 99 |
case GDK_Delete: return Keyboard::Keycode::Delete; |
| 100 |
case GDK_Home: return Keyboard::Keycode::Home; |
| 101 |
case GDK_End: return Keyboard::Keycode::End; |
| 102 |
case GDK_Prior: return Keyboard::Keycode::PageUp; |
| 103 |
case GDK_Next: return Keyboard::Keycode::PageDown; |
| 104 |
|
| 105 |
case GDK_Up: return Keyboard::Keycode::Up; |
| 106 |
case GDK_Down: return Keyboard::Keycode::Down; |
| 107 |
case GDK_Left: return Keyboard::Keycode::Left; |
| 108 |
case GDK_Right: return Keyboard::Keycode::Right; |
| 109 |
|
| 110 |
case GDK_grave: return Keyboard::Keycode::Grave; |
| 111 |
case GDK_1: return Keyboard::Keycode::Number1; |
| 112 |
case GDK_2: return Keyboard::Keycode::Number2; |
| 113 |
case GDK_3: return Keyboard::Keycode::Number3; |
| 114 |
case GDK_4: return Keyboard::Keycode::Number4; |
| 115 |
case GDK_5: return Keyboard::Keycode::Number5; |
| 116 |
case GDK_6: return Keyboard::Keycode::Number6; |
| 117 |
case GDK_7: return Keyboard::Keycode::Number7; |
| 118 |
case GDK_8: return Keyboard::Keycode::Number8; |
| 119 |
case GDK_9: return Keyboard::Keycode::Number9; |
| 120 |
case GDK_0: return Keyboard::Keycode::Number0; |
| 121 |
case GDK_minus: return Keyboard::Keycode::Minus; |
| 122 |
case GDK_equal: return Keyboard::Keycode::Equal; |
| 123 |
case GDK_BackSpace: return Keyboard::Keycode::Backspace; |
| 124 |
|
| 125 |
case GDK_asciitilde: return Keyboard::Keycode::Tilde; |
| 126 |
case GDK_exclam: return Keyboard::Keycode::Exclamation; |
| 127 |
case GDK_at: return Keyboard::Keycode::At; |
| 128 |
case GDK_numbersign: return Keyboard::Keycode::Pound; |
| 129 |
case GDK_dollar: return Keyboard::Keycode::Dollar; |
| 130 |
case GDK_percent: return Keyboard::Keycode::Percent; |
| 131 |
case GDK_asciicircum: return Keyboard::Keycode::Power; |
| 132 |
case GDK_ampersand: return Keyboard::Keycode::Ampersand; |
| 133 |
case GDK_asterisk: return Keyboard::Keycode::Asterisk; |
| 134 |
case GDK_parenleft: return Keyboard::Keycode::ParenthesisLeft; |
| 135 |
case GDK_parenright: return Keyboard::Keycode::ParenthesisRight; |
| 136 |
case GDK_underscore: return Keyboard::Keycode::Underscore; |
| 137 |
case GDK_plus: return Keyboard::Keycode::Plus; |
| 138 |
|
| 139 |
case GDK_bracketleft: return Keyboard::Keycode::BracketLeft; |
| 140 |
case GDK_bracketright: return Keyboard::Keycode::BracketRight; |
| 141 |
case GDK_backslash: return Keyboard::Keycode::Backslash; |
| 142 |
case GDK_semicolon: return Keyboard::Keycode::Semicolon; |
| 143 |
case GDK_apostrophe: return Keyboard::Keycode::Apostrophe; |
| 144 |
case GDK_comma: return Keyboard::Keycode::Comma; |
| 145 |
case GDK_period: return Keyboard::Keycode::Period; |
| 146 |
case GDK_slash: return Keyboard::Keycode::Slash; |
| 147 |
|
| 148 |
case GDK_braceleft: return Keyboard::Keycode::BraceLeft; |
| 149 |
case GDK_braceright: return Keyboard::Keycode::BraceRight; |
| 150 |
case GDK_bar: return Keyboard::Keycode::Pipe; |
| 151 |
case GDK_colon: return Keyboard::Keycode::Colon; |
| 152 |
case GDK_quotedbl: return Keyboard::Keycode::Quote; |
| 153 |
case GDK_less: return Keyboard::Keycode::CaretLeft; |
| 154 |
case GDK_greater: return Keyboard::Keycode::CaretRight; |
| 155 |
case GDK_question: return Keyboard::Keycode::Question; |
| 156 |
|
| 157 |
case GDK_Tab: return Keyboard::Keycode::Tab; |
| 158 |
case GDK_Caps_Lock: return Keyboard::Keycode::CapsLock; |
| 159 |
case GDK_Return: return Keyboard::Keycode::Return; |
| 160 |
case GDK_Shift_L: return Keyboard::Keycode::ShiftLeft; |
| 161 |
case GDK_Shift_R: return Keyboard::Keycode::ShiftRight; |
| 162 |
case GDK_Control_L: return Keyboard::Keycode::ControlLeft; |
| 163 |
case GDK_Control_R: return Keyboard::Keycode::ControlRight; |
| 164 |
case GDK_Super_L: return Keyboard::Keycode::SuperLeft; |
| 165 |
case GDK_Super_R: return Keyboard::Keycode::SuperRight; |
| 166 |
case GDK_Alt_L: return Keyboard::Keycode::AltLeft; |
| 167 |
case GDK_Alt_R: return Keyboard::Keycode::AltRight; |
| 168 |
case GDK_space: return Keyboard::Keycode::Space; |
| 169 |
case GDK_Menu: return Keyboard::Keycode::Menu; |
| 170 |
|
| 171 |
case GDK_A: return Keyboard::Keycode::A; |
| 172 |
case GDK_B: return Keyboard::Keycode::B; |
| 173 |
case GDK_C: return Keyboard::Keycode::C; |
| 174 |
case GDK_D: return Keyboard::Keycode::D; |
| 175 |
case GDK_E: return Keyboard::Keycode::E; |
| 176 |
case GDK_F: return Keyboard::Keycode::F; |
| 177 |
case GDK_G: return Keyboard::Keycode::G; |
| 178 |
case GDK_H: return Keyboard::Keycode::H; |
| 179 |
case GDK_I: return Keyboard::Keycode::I; |
| 180 |
case GDK_J: return Keyboard::Keycode::J; |
| 181 |
case GDK_K: return Keyboard::Keycode::K; |
| 182 |
case GDK_L: return Keyboard::Keycode::L; |
| 183 |
case GDK_M: return Keyboard::Keycode::M; |
| 184 |
case GDK_N: return Keyboard::Keycode::N; |
| 185 |
case GDK_O: return Keyboard::Keycode::O; |
| 186 |
case GDK_P: return Keyboard::Keycode::P; |
| 187 |
case GDK_Q: return Keyboard::Keycode::Q; |
| 188 |
case GDK_R: return Keyboard::Keycode::R; |
| 189 |
case GDK_S: return Keyboard::Keycode::S; |
| 190 |
case GDK_T: return Keyboard::Keycode::T; |
| 191 |
case GDK_U: return Keyboard::Keycode::U; |
| 192 |
case GDK_V: return Keyboard::Keycode::V; |
| 193 |
case GDK_W: return Keyboard::Keycode::W; |
| 194 |
case GDK_X: return Keyboard::Keycode::X; |
| 195 |
case GDK_Y: return Keyboard::Keycode::Y; |
| 196 |
case GDK_Z: return Keyboard::Keycode::Z; |
| 197 |
|
| 198 |
case GDK_a: return Keyboard::Keycode::a; |
| 199 |
case GDK_b: return Keyboard::Keycode::b; |
| 200 |
case GDK_c: return Keyboard::Keycode::c; |
| 201 |
case GDK_d: return Keyboard::Keycode::d; |
| 202 |
case GDK_e: return Keyboard::Keycode::e; |
| 203 |
case GDK_f: return Keyboard::Keycode::f; |
| 204 |
case GDK_g: return Keyboard::Keycode::g; |
| 205 |
case GDK_h: return Keyboard::Keycode::h; |
| 206 |
case GDK_i: return Keyboard::Keycode::i; |
| 207 |
case GDK_j: return Keyboard::Keycode::j; |
| 208 |
case GDK_k: return Keyboard::Keycode::k; |
| 209 |
case GDK_l: return Keyboard::Keycode::l; |
| 210 |
case GDK_m: return Keyboard::Keycode::m; |
| 211 |
case GDK_n: return Keyboard::Keycode::n; |
| 212 |
case GDK_o: return Keyboard::Keycode::o; |
| 213 |
case GDK_p: return Keyboard::Keycode::p; |
| 214 |
case GDK_q: return Keyboard::Keycode::q; |
| 215 |
case GDK_r: return Keyboard::Keycode::r; |
| 216 |
case GDK_s: return Keyboard::Keycode::s; |
| 217 |
case GDK_t: return Keyboard::Keycode::t; |
| 218 |
case GDK_u: return Keyboard::Keycode::u; |
| 219 |
case GDK_v: return Keyboard::Keycode::v; |
| 220 |
case GDK_w: return Keyboard::Keycode::w; |
| 221 |
case GDK_x: return Keyboard::Keycode::x; |
| 222 |
case GDK_y: return Keyboard::Keycode::y; |
| 223 |
case GDK_z: return Keyboard::Keycode::z; |
| 224 |
|
| 225 |
case GDK_Num_Lock: return Keyboard::Keycode::NumLock; |
| 226 |
case GDK_KP_Divide: return Keyboard::Keycode::Divide; |
| 227 |
case GDK_KP_Multiply: return Keyboard::Keycode::Multiply; |
| 228 |
case GDK_KP_Subtract: return Keyboard::Keycode::Subtract; |
| 229 |
case GDK_KP_Add: return Keyboard::Keycode::Add; |
| 230 |
case GDK_KP_Enter: return Keyboard::Keycode::Enter; |
| 231 |
case GDK_KP_Decimal: return Keyboard::Keycode::Point; |
| 232 |
|
| 233 |
case GDK_KP_1: return Keyboard::Keycode::Keypad1; |
| 234 |
case GDK_KP_2: return Keyboard::Keycode::Keypad2; |
| 235 |
case GDK_KP_3: return Keyboard::Keycode::Keypad3; |
| 236 |
case GDK_KP_4: return Keyboard::Keycode::Keypad4; |
| 237 |
case GDK_KP_5: return Keyboard::Keycode::Keypad5; |
| 238 |
case GDK_KP_6: return Keyboard::Keycode::Keypad6; |
| 239 |
case GDK_KP_7: return Keyboard::Keycode::Keypad7; |
| 240 |
case GDK_KP_8: return Keyboard::Keycode::Keypad8; |
| 241 |
case GDK_KP_9: return Keyboard::Keycode::Keypad9; |
| 242 |
case GDK_KP_0: return Keyboard::Keycode::Keypad0; |
| 243 |
|
| 244 |
case GDK_KP_Home: return Keyboard::Keycode::KeypadHome; |
| 245 |
case GDK_KP_End: return Keyboard::Keycode::KeypadEnd; |
| 246 |
case GDK_KP_Page_Up: return Keyboard::Keycode::KeypadPageUp; |
| 247 |
case GDK_KP_Page_Down: return Keyboard::Keycode::KeypadPageDown; |
| 248 |
case GDK_KP_Up: return Keyboard::Keycode::KeypadUp; |
| 249 |
case GDK_KP_Down: return Keyboard::Keycode::KeypadDown; |
| 250 |
case GDK_KP_Left: return Keyboard::Keycode::KeypadLeft; |
| 251 |
case GDK_KP_Right: return Keyboard::Keycode::KeypadRight; |
| 252 |
case GDK_KP_Begin: return Keyboard::Keycode::KeypadCenter; |
| 253 |
case GDK_KP_Insert: return Keyboard::Keycode::KeypadInsert; |
| 254 |
case GDK_KP_Delete: return Keyboard::Keycode::KeypadDelete; |
| 255 |
} |
| 256 |
return Keyboard::Keycode::None; |
| 257 |
} |
| 258 |
|
| 259 |
} |