@@ -2,23 +2,16 @@ use std::fs::File;
22
33use eframe:: egui:: RichText ;
44use eframe:: egui:: { self } ;
5- use image:: { DynamicImage , GenericImage , ImageFormat } ;
6- use lazy_static:: lazy_static;
5+ use image:: { DynamicImage , GenericImage } ;
76use log:: { error, info, warn} ;
87use quicktag_core:: tagtypes:: TagType ;
9- use std:: io:: { Cursor , Write } ;
10- use std:: num:: NonZeroU32 ;
8+ use std:: io:: Write ;
119use tiger_pkg:: { TagHash , package_manager} ;
1210
1311use crate :: texture:: { Texture , cache:: TextureCache } ;
1412
1513use super :: TOASTS ;
1614
17- lazy_static ! {
18- static ref CF_PNG : NonZeroU32 = clipboard_win:: register_format( "PNG" ) . unwrap( ) ;
19- static ref CF_FILENAME : NonZeroU32 = clipboard_win:: register_format( "FileNameW" ) . unwrap( ) ;
20- }
21-
2215pub trait ResponseExt {
2316 fn tag_context ( self , tag : TagHash ) -> Self ;
2417
@@ -49,38 +42,19 @@ impl ResponseExt for egui::Response {
4942 match Texture :: load ( & texture_cache. render_state , tag, false ) {
5043 Ok ( o) => {
5144 let image = o. to_image ( & texture_cache. render_state , 0 ) . unwrap ( ) ;
52- let mut png_data = vec ! [ ] ;
53- let mut png_writer = Cursor :: new ( & mut png_data) ;
54- image. write_to ( & mut png_writer, ImageFormat :: Png ) . unwrap ( ) ;
55-
56- let _clipboard = clipboard_win:: Clipboard :: new ( ) ;
57- if let Err ( e) = clipboard_win:: raw:: set ( CF_PNG . get ( ) , & png_data) {
58- error ! ( "Failed to copy texture to clipboard: {e}" ) ;
59- }
60-
61- // Save to temp
62- let path = std:: env:: temp_dir ( ) . join ( format ! ( "{tag}.png" ) ) ;
63- let mut file = File :: create ( & path) . unwrap ( ) ;
64- file. write_all ( & png_data) . unwrap ( ) ;
65-
66- let mut path_utf16 =
67- path. to_string_lossy ( ) . encode_utf16 ( ) . collect :: < Vec < u16 > > ( ) ;
68- path_utf16. push ( 0 ) ;
69-
70- if let Err ( e) = clipboard_win:: raw:: set_without_clear (
71- CF_FILENAME . get ( ) ,
72- bytemuck:: cast_slice ( & path_utf16) ,
73- ) {
74- error ! ( "Failed to copy texture path to clipboard: {e}" ) ;
75- } else {
76- TOASTS . lock ( ) . success ( "Texture copied to clipboard" ) ;
77- }
45+ let rgba = image. to_rgba8 ( ) . to_vec ( ) ;
46+ let color_image = egui:: ColorImage :: from_rgba_unmultiplied (
47+ [ image. width ( ) as usize , image. height ( ) as usize ] ,
48+ & rgba,
49+ ) ;
50+
51+ self . ctx . copy_image ( color_image) ;
7852 }
7953 Err ( e) => {
8054 error ! ( "Failed to load texture: {e}" ) ;
8155 }
8256 }
83- ui. close_menu ( ) ;
57+ ui. close ( ) ;
8458 }
8559
8660 if ui
@@ -89,7 +63,7 @@ impl ResponseExt for egui::Response {
8963 . clicked ( )
9064 {
9165 export_texture ( texture_cache, tag) ;
92- ui. close_menu ( ) ;
66+ ui. close ( ) ;
9367 }
9468 }
9569 tag_context ( ui, tag) ;
@@ -215,29 +189,25 @@ pub fn tag_context(ui: &mut egui::Ui, tag: TagHash) {
215189 . selectable_label ( false , format ! ( "📋 Copy tag{flipped_postfix}" ) )
216190 . clicked ( )
217191 {
218- ui. output_mut ( |o| {
219- o. copied_text = if copy_flipped {
220- format ! ( "{:08X}" , tag. 0 . swap_bytes( ) )
221- } else {
222- format ! ( "{:08X}" , tag. 0 )
223- }
192+ ui. ctx ( ) . copy_text ( if copy_flipped {
193+ format ! ( "{:08X}" , tag. 0 . swap_bytes( ) )
194+ } else {
195+ format ! ( "{:08X}" , tag. 0 )
224196 } ) ;
225- ui. close_menu ( ) ;
197+ ui. close ( ) ;
226198 }
227199
228200 if let Some ( tag64) = package_manager ( ) . get_tag64_for_tag32 ( tag) {
229201 if ui
230202 . selectable_label ( false , format ! ( "📋 Copy 64-bit tag{flipped_postfix}" ) )
231203 . clicked ( )
232204 {
233- ui. output_mut ( |o| {
234- o. copied_text = if copy_flipped {
235- format ! ( "{:016X}" , tag64. 0 . swap_bytes( ) )
236- } else {
237- format ! ( "{:016X}" , tag64. 0 )
238- }
205+ ui. ctx ( ) . copy_text ( if copy_flipped {
206+ format ! ( "{:016X}" , tag64. 0 . swap_bytes( ) )
207+ } else {
208+ format ! ( "{:016X}" , tag64. 0 )
239209 } ) ;
240- ui. close_menu ( ) ;
210+ ui. close ( ) ;
241211 }
242212 }
243213
@@ -246,37 +216,35 @@ pub fn tag_context(ui: &mut egui::Ui, tag: TagHash) {
246216 . selectable_label ( false , format ! ( "📋 Copy reference tag{flipped_postfix}" ) )
247217 . clicked ( )
248218 {
249- ui. output_mut ( |o| {
250- o. copied_text = if copy_flipped {
251- format ! ( "{:08X}" , entry. reference. swap_bytes( ) )
252- } else {
253- format ! ( "{:08X}" , entry. reference)
254- }
219+ ui. ctx ( ) . copy_text ( if copy_flipped {
220+ format ! ( "{:08X}" , entry. reference. swap_bytes( ) )
221+ } else {
222+ format ! ( "{:08X}" , entry. reference)
255223 } ) ;
256- ui. close_menu ( ) ;
224+ ui. close ( ) ;
257225 }
258226
259227 let tt = TagType :: from_type_subtype ( entry. file_type , entry. file_subtype ) ;
260228 if tt == TagType :: WwiseStream && ui. selectable_label ( false , "🎵 Play audio" ) . clicked ( ) {
261229 open_audio_file_in_default_application ( tag, "wem" ) ;
262- ui. close_menu ( ) ;
230+ ui. close ( ) ;
263231 }
264232 }
265233
266234 if ui
267235 . add_enabled (
268236 false ,
269- egui:: SelectableLabel :: new ( false , "📤 Open in Alkahest" ) ,
237+ egui:: Button :: selectable ( false , "📤 Open in Alkahest" ) ,
270238 )
271239 . clicked ( )
272240 {
273241 warn ! ( "Alkahest IPC not implemented yet" ) ;
274- ui. close_menu ( ) ;
242+ ui. close ( ) ;
275243 }
276244
277245 if ui. selectable_label ( false , "📤 Open tag data" ) . clicked ( ) {
278246 open_tag_in_default_application ( tag) ;
279- ui. close_menu ( ) ;
247+ ui. close ( ) ;
280248 }
281249}
282250
0 commit comments