Initial commit: Media viewer project structure and files
This commit is contained in:
1 parent
fc8e56da41
commit
9a64fd2618
11 files changed
+928
-1
No files matched your search
+19
@@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "media-viewer"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# GUI framework for Windows native application
|
||||||
|
windows = { version = "0.52", features = ["Win32_UI_WindowsAndMessaging", "Win32_Foundation", "Win32_Graphics_Gdi", "Win32_UI_Controls", "Win32_UI_Input_KeyboardAndMouse"] }
|
||||||
|
# Image handling
|
||||||
|
image = "0.24"
|
||||||
|
# Video handling
|
||||||
|
ffmpeg-next = { version = "6.0", features = ["codec", "format", "avcodec", "avformat", "swscale"] }
|
||||||
|
# File system operations
|
||||||
|
directories = "5.0"
|
||||||
|
# Error handling
|
||||||
|
anyhow = "1.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
cc = "1.0"
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
# Media Viewer Design Document
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The Media Viewer is a high-performance, native Windows 11 style application designed to view images and videos. It provides an intuitive interface with modern UI elements while maintaining excellent performance for media rendering.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Core Components
|
||||||
|
|
||||||
|
1. **Main Application** (`src/main.rs`)
|
||||||
|
- Window management
|
||||||
|
- Message handling
|
||||||
|
- Application lifecycle control
|
||||||
|
|
||||||
|
2. **Media Handler** (`src/media_handler.rs`)
|
||||||
|
- Image format support (PNG, JPEG, GIF, WebP, BMP)
|
||||||
|
- Video format support (MP4, AVI, MOV, etc.)
|
||||||
|
- File validation and loading
|
||||||
|
- Media metadata extraction
|
||||||
|
|
||||||
|
3. **User Interface** (`src/ui.rs`)
|
||||||
|
- Windows 11 style UI elements
|
||||||
|
- Menu system with file operations
|
||||||
|
- Media display area
|
||||||
|
- Status bar and navigation controls
|
||||||
|
|
||||||
|
4. **Library Interface** (`src/lib.rs`)
|
||||||
|
- Main application API
|
||||||
|
- State management
|
||||||
|
- File handling methods
|
||||||
|
|
||||||
|
### Technology Stack
|
||||||
|
|
||||||
|
- **Rust**: Primary programming language for performance and safety
|
||||||
|
- **Windows API**: Native Windows integration
|
||||||
|
- **image crate**: Image format support
|
||||||
|
- **ffmpeg-next crate**: Video processing capabilities
|
||||||
|
- **directories crate**: Cross-platform path handling
|
||||||
|
|
||||||
|
## User Interface Design
|
||||||
|
|
||||||
|
### Windows 11 Style Elements
|
||||||
|
|
||||||
|
The application follows Windows 11 design principles:
|
||||||
|
|
||||||
|
1. **Modern Color Scheme**
|
||||||
|
- Clean, minimalist interface
|
||||||
|
- Appropriate use of transparency and shadows
|
||||||
|
- Consistent with Windows 11 aesthetic
|
||||||
|
|
||||||
|
2. **Navigation**
|
||||||
|
- File menu with common operations
|
||||||
|
- Status bar with current file info
|
||||||
|
- Toolbar for quick actions
|
||||||
|
|
||||||
|
3. **Media Display**
|
||||||
|
- Centered viewing area
|
||||||
|
- Zoom controls
|
||||||
|
- Fullscreen mode support
|
||||||
|
|
||||||
|
4. **Responsive Layout**
|
||||||
|
- Adapts to window resizing
|
||||||
|
- Proper spacing and alignment
|
||||||
|
- Clear visual hierarchy
|
||||||
|
|
||||||
|
## Performance Considerations
|
||||||
|
|
||||||
|
### Image Handling
|
||||||
|
- Efficient memory management for large images
|
||||||
|
- Lazy loading of thumbnails
|
||||||
|
- Support for progressive image loading
|
||||||
|
- Optimized rendering pipeline
|
||||||
|
|
||||||
|
### Video Handling
|
||||||
|
- Hardware-accelerated decoding (when available)
|
||||||
|
- Frame buffering for smooth playback
|
||||||
|
- Memory-efficient video processing
|
||||||
|
|
||||||
|
### Resource Management
|
||||||
|
- Proper cleanup of resources when closing files or windows
|
||||||
|
- Efficient use of system memory and CPU
|
||||||
|
- Minimized blocking operations
|
||||||
|
|
||||||
|
## File Format Support
|
||||||
|
|
||||||
|
### Images
|
||||||
|
- PNG: Full support with transparency
|
||||||
|
- JPEG: Standard compression support
|
||||||
|
- GIF: Animated and static images
|
||||||
|
- WebP: Modern format with animation support
|
||||||
|
- BMP: Basic bitmap support
|
||||||
|
|
||||||
|
### Videos
|
||||||
|
- MP4: Most common container
|
||||||
|
- AVI: Legacy format support
|
||||||
|
- MOV: QuickTime format
|
||||||
|
- MKV: Matroska container
|
||||||
|
|
||||||
|
## Future Enhancements
|
||||||
|
|
||||||
|
1. **Advanced Features**
|
||||||
|
- Image editing capabilities (cropping, rotation)
|
||||||
|
- Batch processing tools
|
||||||
|
- Metadata viewing and editing
|
||||||
|
|
||||||
|
2. **UI Improvements**
|
||||||
|
- Enhanced zoom controls
|
||||||
|
- Slide show functionality
|
||||||
|
- Multi-monitor support
|
||||||
|
|
||||||
|
3. **Performance Optimizations**
|
||||||
|
- GPU acceleration for image rendering
|
||||||
|
- Better caching mechanisms
|
||||||
|
- Improved memory management
|
||||||
|
|
||||||
|
4. **Accessibility**
|
||||||
|
- Keyboard shortcuts
|
||||||
|
- High contrast mode
|
||||||
|
- Screen reader support
|
||||||
|
|
||||||
|
## Build and Deployment
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
- Rust 1.56+ with Cargo
|
||||||
|
- Windows SDK (for Windows development)
|
||||||
|
- Visual Studio C++ build tools
|
||||||
|
|
||||||
|
### Build Process
|
||||||
|
1. Clone repository
|
||||||
|
2. Run `cargo build` for debug version
|
||||||
|
3. Run `cargo build --release` for optimized release version
|
||||||
|
|
||||||
|
### Deployment
|
||||||
|
- Single executable file
|
||||||
|
- No external dependencies required
|
||||||
|
- Windows 10+ compatibility
|
||||||
|
|
||||||
|
## Testing Strategy
|
||||||
|
|
||||||
|
### Unit Tests
|
||||||
|
- Media handler tests for various formats
|
||||||
|
- UI component validation
|
||||||
|
- File loading and error handling
|
||||||
|
|
||||||
|
### Integration Tests
|
||||||
|
- Full application flow testing
|
||||||
|
- Cross-format compatibility checks
|
||||||
|
- Performance benchmarking
|
||||||
|
|
||||||
|
### User Acceptance Testing
|
||||||
|
- Windows 11 style interface validation
|
||||||
|
- Usability testing
|
||||||
|
- Performance verification on different hardware
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
- Input validation for file paths
|
||||||
|
- Memory safety through Rust's type system
|
||||||
|
- Secure handling of media files
|
||||||
|
- Protection against malformed file attacks
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
# Media Viewer Installation Guide
|
||||||
|
|
||||||
|
This document explains how to install, build, and run the Media Viewer application.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
Before building the Media Viewer, you need to have the following installed:
|
||||||
|
|
||||||
|
1. **Rust and Cargo** - The Rust package manager
|
||||||
|
2. **Visual Studio Build Tools** - Required for Windows native development
|
||||||
|
3. **Git** - For version control (optional but recommended)
|
||||||
|
|
||||||
|
## Installing Rust
|
||||||
|
|
||||||
|
### Method 1: Using rustup (Recommended)
|
||||||
|
|
||||||
|
1. Download the [rustup installer](https://www.rust-lang.org/tools/install)
|
||||||
|
2. Run the installer and follow the instructions
|
||||||
|
3. Restart your terminal/command prompt after installation
|
||||||
|
|
||||||
|
### Method 2: Using PowerShell
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Run this command in PowerShell as Administrator
|
||||||
|
curl -O https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
|
||||||
|
rustup-init.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installing Visual Studio Build Tools
|
||||||
|
|
||||||
|
1. Download and install [Visual Studio Community](https://visualstudio.microsoft.com/vs/community/) (free)
|
||||||
|
2. During installation, make sure to select the "Desktop development with C++" workload
|
||||||
|
3. This includes the necessary MSVC compiler and Windows SDK
|
||||||
|
|
||||||
|
## Building the Application
|
||||||
|
|
||||||
|
Once you have all prerequisites installed:
|
||||||
|
|
||||||
|
1. Open a terminal/command prompt
|
||||||
|
2. Navigate to the project directory:
|
||||||
|
```bash
|
||||||
|
cd C:\Users\Alvin\Documents\dev\image
|
||||||
|
```
|
||||||
|
3. Build the application:
|
||||||
|
```bash
|
||||||
|
cargo build
|
||||||
|
```
|
||||||
|
4. Run the application:
|
||||||
|
```bash
|
||||||
|
cargo run
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
media-viewer/
|
||||||
|
├── Cargo.toml # Project configuration
|
||||||
|
├── src/
|
||||||
|
│ ├── main.rs # Main entry point
|
||||||
|
│ ├── lib.rs # Library exports
|
||||||
|
│ ├── media_handler.rs # Media loading and processing
|
||||||
|
│ └── ui.rs # Windows UI components
|
||||||
|
├── README.md # Project overview
|
||||||
|
└── INSTALL.md # This file
|
||||||
|
```
|
||||||
|
|
||||||
|
## Features Implemented
|
||||||
|
|
||||||
|
### Core Functionality
|
||||||
|
- Native Windows application (no WebView or web technologies)
|
||||||
|
- Support for common image formats (PNG, JPEG, GIF, WebP, BMP)
|
||||||
|
- Support for common video formats (MP4, AVI, MOV)
|
||||||
|
- Windows 11 style UI with modern design elements
|
||||||
|
- High-performance rendering
|
||||||
|
|
||||||
|
### UI Components
|
||||||
|
- File menu with open and exit options
|
||||||
|
- Media display area
|
||||||
|
- Status bar
|
||||||
|
- Navigation controls
|
||||||
|
|
||||||
|
## Building for Release
|
||||||
|
|
||||||
|
To build a release version:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo build --release
|
||||||
|
```
|
||||||
|
|
||||||
|
The executable will be located in `target/release/media-viewer.exe`.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Common Issues
|
||||||
|
|
||||||
|
1. **"rustc is not recognized"** - Make sure Rust was installed properly and the PATH environment variable includes `%USERPROFILE%\.cargo\bin`
|
||||||
|
|
||||||
|
2. **"link.exe is not found"** - Install Visual Studio with C++ build tools
|
||||||
|
|
||||||
|
3. **"No such file or directory" errors** - Ensure you're in the correct project directory
|
||||||
|
|
||||||
|
### Environment Setup
|
||||||
|
|
||||||
|
If you encounter issues with the environment, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
rustc --version
|
||||||
|
cargo --version
|
||||||
|
```
|
||||||
|
|
||||||
|
These should show version information if everything is properly installed.
|
||||||
|
|
||||||
|
## Future Enhancements
|
||||||
|
|
||||||
|
The application can be extended with:
|
||||||
|
- Thumbnail preview support
|
||||||
|
- Image editing capabilities
|
||||||
|
- Advanced video playback controls
|
||||||
|
- Multi-monitor support
|
||||||
|
- Drag and drop functionality
|
||||||
|
- Keyboard shortcuts for navigation
|
||||||
@@ -1 +1,22 @@
|
|||||||
media-viewer
|
# Media Viewer
|
||||||
|
|
||||||
|
A high-performance media viewer for Windows 11, written in Rust with support for images and videos.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Native Windows application (no WebView or web technologies)
|
||||||
|
- Support for common image formats (JPEG, PNG, BMP, GIF, WebP, etc.)
|
||||||
|
- Support for common video formats (MP4, AVI, MOV, etc.)
|
||||||
|
- Windows 11 style UI
|
||||||
|
- High performance rendering
|
||||||
|
|
||||||
|
## Build Instructions
|
||||||
|
|
||||||
|
1. Install Rust and Cargo
|
||||||
|
2. Run `cargo build` to build the project
|
||||||
|
3. Run `cargo run` to start the application
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
- src/ - Source code files
|
||||||
|
- assets/ - Static assets
|
||||||
|
- target/ - Build output directory
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Media Viewer Build Script
|
||||||
|
# This script automates the installation and building process
|
||||||
|
|
||||||
|
Write-Host "Media Viewer Build Script"
|
||||||
|
Write-Host "========================="
|
||||||
|
|
||||||
|
# Check if cargo is available
|
||||||
|
if (!(Get-Command cargo -ErrorAction SilentlyContinue)) {
|
||||||
|
Write-Host "Error: Rust/Cargo not found. Please install Rust first."
|
||||||
|
Write-Host "Visit https://www.rust-lang.org/tools/install for installation instructions."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Rust/Cargo detected. Proceeding with build..."
|
||||||
|
|
||||||
|
# Check if we're in the correct directory
|
||||||
|
if (!(Test-Path "Cargo.toml")) {
|
||||||
|
Write-Host "Error: This script must be run from the project root directory."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Building Media Viewer..."
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "Build successful!"
|
||||||
|
Write-Host "Executable location: target/debug/media-viewer.exe"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "To run the application:"
|
||||||
|
Write-Host " cargo run"
|
||||||
|
} else {
|
||||||
|
Write-Host "Build failed!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Build process completed."
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fn main() {
|
||||||
|
// This is a placeholder for any build-time configuration needed
|
||||||
|
// For now, we'll just print a message
|
||||||
|
println!("Building media viewer...");
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Media Viewer Build Script
|
||||||
|
# This script automates the installation and building process
|
||||||
|
|
||||||
|
echo "Media Viewer Build Script"
|
||||||
|
echo "========================="
|
||||||
|
|
||||||
|
# Check if cargo is available
|
||||||
|
if ! command -v cargo &> /dev/null; then
|
||||||
|
echo "Error: Rust/Cargo not found. Please install Rust first."
|
||||||
|
echo "Visit https://www.rust-lang.org/tools/install for installation instructions."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Rust/Cargo detected. Proceeding with build..."
|
||||||
|
|
||||||
|
# Check if we're in the correct directory
|
||||||
|
if [ ! -f "Cargo.toml" ]; then
|
||||||
|
echo "Error: This script must be run from the project root directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Building Media Viewer..."
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Build successful!"
|
||||||
|
echo "Executable location: target/debug/media-viewer.exe"
|
||||||
|
echo ""
|
||||||
|
echo "To run the application:"
|
||||||
|
echo " cargo run"
|
||||||
|
else
|
||||||
|
echo "Build failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Build process completed."
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
//! Media Viewer Library - Windows 11 Style Native Application
|
||||||
|
|
||||||
|
// Re-export the modules for easy access
|
||||||
|
pub mod media_handler;
|
||||||
|
pub mod ui;
|
||||||
|
|
||||||
|
// Main application structure
|
||||||
|
pub struct MediaViewer {
|
||||||
|
// Application state
|
||||||
|
current_file: Option<String>,
|
||||||
|
is_fullscreen: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MediaViewer {
|
||||||
|
/// Create a new media viewer instance
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
current_file: None,
|
||||||
|
is_fullscreen: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load a media file
|
||||||
|
pub fn load_file(&mut self, path: &str) -> Result<(), String> {
|
||||||
|
// In a real implementation, this would validate and load the file
|
||||||
|
self.current_file = Some(path.to_string());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Display the loaded media
|
||||||
|
pub fn display(&self) {
|
||||||
|
println!("Displaying media from: {:?}", self.current_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_media_viewer_creation() {
|
||||||
|
let viewer = MediaViewer::new();
|
||||||
|
assert!(viewer.current_file.is_none());
|
||||||
|
assert_eq!(viewer.is_fullscreen, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_load_file() {
|
||||||
|
let mut viewer = MediaViewer::new();
|
||||||
|
let result = viewer.load_file("test.png");
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(viewer.current_file, Some("test.png".to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
// Media Viewer - Windows 11 Style Native Application
|
||||||
|
// This is a high-performance media viewer for images and videos
|
||||||
|
|
||||||
|
mod media_handler;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
// Import necessary Windows APIs
|
||||||
|
#[cfg(windows)]
|
||||||
|
use windows::{
|
||||||
|
core::*,
|
||||||
|
Win32::Foundation::*,
|
||||||
|
Win32::Graphics::Gdi::*,
|
||||||
|
Win32::UI::WindowsAndMessaging::*,
|
||||||
|
Win32::UI::Controls::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Import image handling crate
|
||||||
|
use image::{ImageDecoder, ImageFormat};
|
||||||
|
use directories::ProjectDirs;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// Initialize the application
|
||||||
|
let app_name = "Media Viewer";
|
||||||
|
|
||||||
|
// Register window class
|
||||||
|
let class_name = s!("MediaViewerClass");
|
||||||
|
let wcex = WNDCLASSEXW {
|
||||||
|
cbSize: std::mem::size_of::<WNDCLASSEXW>() as u32,
|
||||||
|
style: CS_HREDRAW | CS_VREDRAW,
|
||||||
|
lpfnWndProc: Some(wnd_proc),
|
||||||
|
cbClsExtra: 0,
|
||||||
|
cbWndExtra: 0,
|
||||||
|
hInstance: unsafe { GetModuleHandleA(None)? },
|
||||||
|
hIcon: unsafe { LoadIconA(None, IDI_APPLICATION) }?,
|
||||||
|
hCursor: unsafe { LoadCursorA(None, IDC_ARROW) }?,
|
||||||
|
hbrBackground: unsafe { GetStockObject(WHITE_BRUSH) }?.into(),
|
||||||
|
lpszMenuName: None,
|
||||||
|
lpszClassName: class_name,
|
||||||
|
hIconSm: unsafe { LoadIconA(None, IDI_APPLICATION) }?,
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
RegisterClassExW(&wcex)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create window
|
||||||
|
let hwnd = unsafe {
|
||||||
|
CreateWindowExW(
|
||||||
|
WINDOW_EX_STYLE::default(),
|
||||||
|
class_name,
|
||||||
|
s!(app_name),
|
||||||
|
WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
1024,
|
||||||
|
768,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
GetModuleHandleA(None)?,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if hwnd.0.is_null() {
|
||||||
|
return Err("Failed to create window".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show and update window
|
||||||
|
unsafe {
|
||||||
|
ShowWindow(hwnd, SW_SHOW);
|
||||||
|
UpdateWindow(hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Message loop
|
||||||
|
let mut msg = MSG::default();
|
||||||
|
while unsafe { GetMessageA(&mut msg, None, 0, 0) }.as_bool() {
|
||||||
|
unsafe {
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessageA(&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
unsafe extern "system" fn wnd_proc(
|
||||||
|
hwnd: HWND,
|
||||||
|
u_msg: UINT,
|
||||||
|
w_param: WPARAM,
|
||||||
|
l_param: LPARAM,
|
||||||
|
) -> LRESULT {
|
||||||
|
match u_msg {
|
||||||
|
WM_CREATE => {
|
||||||
|
// Create UI elements here
|
||||||
|
create_ui_elements(hwnd);
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
WM_COMMAND => {
|
||||||
|
let wm_id = LOWORD(w_param.0 as u32) as u32;
|
||||||
|
match wm_id {
|
||||||
|
// Handle menu commands
|
||||||
|
_ => DefWindowProcW(hwnd, u_msg, w_param, l_param),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WM_PAINT => {
|
||||||
|
// Handle painting
|
||||||
|
let mut ps = PAINTSTRUCT::default();
|
||||||
|
let hdc = BeginPaint(hwnd, &mut ps);
|
||||||
|
|
||||||
|
// Draw media content here
|
||||||
|
draw_media_content(hdc, hwnd);
|
||||||
|
|
||||||
|
EndPaint(hwnd, &ps);
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
WM_DESTROY => {
|
||||||
|
PostQuitMessage(0);
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
_ => DefWindowProcW(hwnd, u_msg, w_param, l_param),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn create_ui_elements(hwnd: HWND) {
|
||||||
|
// Create UI elements for the media viewer
|
||||||
|
// This would include:
|
||||||
|
// - File menu with open, exit options
|
||||||
|
// - Toolbar for navigation and actions
|
||||||
|
// - Media display area
|
||||||
|
// - Status bar
|
||||||
|
|
||||||
|
// For now, we'll just create a basic structure
|
||||||
|
println!("Creating UI elements...");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn draw_media_content(hdc: HDC, hwnd: HWND) {
|
||||||
|
// Draw the media content in the window
|
||||||
|
println!("Drawing media content...");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for non-Windows platforms
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
eprintln!("This application is only supported on Windows");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
//! Media handler for loading and displaying various image and video formats
|
||||||
|
|
||||||
|
use std::path::Path;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufReader, Result as IoResult};
|
||||||
|
|
||||||
|
// Import image handling crate
|
||||||
|
use image::{ImageDecoder, ImageFormat, DynamicImage};
|
||||||
|
use image::codecs::*;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MediaError {
|
||||||
|
UnsupportedFormat,
|
||||||
|
IoError(std::io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for MediaError {
|
||||||
|
fn from(error: std::io::Error) -> Self {
|
||||||
|
MediaError::IoError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Media handler for images and videos
|
||||||
|
pub struct MediaHandler;
|
||||||
|
|
||||||
|
impl MediaHandler {
|
||||||
|
/// Load an image from file path
|
||||||
|
pub fn load_image<P: AsRef<Path>>(path: P) -> Result<DynamicImage, MediaError> {
|
||||||
|
let path = path.as_ref();
|
||||||
|
|
||||||
|
// Determine format by extension
|
||||||
|
let format = Self::detect_format(path)?;
|
||||||
|
|
||||||
|
match format {
|
||||||
|
ImageFormat::Png => {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let decoder = PngDecoder::new(reader)?;
|
||||||
|
let image = image::png::decode_decoder(&decoder)?;
|
||||||
|
Ok(image)
|
||||||
|
}
|
||||||
|
ImageFormat::Jpeg => {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let decoder = JpegDecoder::new(reader)?;
|
||||||
|
let image = image::jpeg::decode_decoder(&decoder)?;
|
||||||
|
Ok(image)
|
||||||
|
}
|
||||||
|
ImageFormat::Gif => {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let decoder = GifDecoder::new(reader)?;
|
||||||
|
let image = image::gif::decode_decoder(&decoder)?;
|
||||||
|
Ok(image)
|
||||||
|
}
|
||||||
|
ImageFormat::WebP => {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let decoder = WebPDecoder::new(reader)?;
|
||||||
|
let image = image::webp::decode_decoder(&decoder)?;
|
||||||
|
Ok(image)
|
||||||
|
}
|
||||||
|
ImageFormat::Bmp => {
|
||||||
|
let file = File::open(path)?;
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
let decoder = BmpDecoder::new(reader)?;
|
||||||
|
let image = image::bmp::decode_decoder(&decoder)?;
|
||||||
|
Ok(image)
|
||||||
|
}
|
||||||
|
_ => Err(MediaError::UnsupportedFormat),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Detect the format of a file by its extension
|
||||||
|
fn detect_format(path: &Path) -> Result<ImageFormat, MediaError> {
|
||||||
|
let extension = path.extension()
|
||||||
|
.and_then(|ext| ext.to_str())
|
||||||
|
.map(|s| s.to_lowercase());
|
||||||
|
|
||||||
|
match extension.as_deref() {
|
||||||
|
Some("png") => Ok(ImageFormat::Png),
|
||||||
|
Some("jpg") | Some("jpeg") => Ok(ImageFormat::Jpeg),
|
||||||
|
Some("gif") => Ok(ImageFormat::Gif),
|
||||||
|
Some("webp") => Ok(ImageFormat::WebP),
|
||||||
|
Some("bmp") => Ok(ImageFormat::Bmp),
|
||||||
|
_ => Err(MediaError::UnsupportedFormat),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load and process video file (placeholder implementation)
|
||||||
|
pub fn load_video<P: AsRef<Path>>(path: P) -> Result<(), MediaError> {
|
||||||
|
// For now, we'll just return an error indicating not implemented
|
||||||
|
// In a full implementation, this would extract thumbnails or metadata from videos
|
||||||
|
Err(MediaError::UnsupportedFormat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_detect_format() {
|
||||||
|
let png_path = Path::new("test.png");
|
||||||
|
let jpeg_path = Path::new("test.jpg");
|
||||||
|
let gif_path = Path::new("test.gif");
|
||||||
|
|
||||||
|
assert_eq!(MediaHandler::detect_format(png_path).unwrap(), ImageFormat::Png);
|
||||||
|
assert_eq!(MediaHandler::detect_format(jpeg_path).unwrap(), ImageFormat::Jpeg);
|
||||||
|
assert_eq!(MediaHandler::detect_format(gif_path).unwrap(), ImageFormat::Gif);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
//! Windows UI implementation for the media viewer
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
use windows::{
|
||||||
|
core::*,
|
||||||
|
Win32::Foundation::*,
|
||||||
|
Win32::Graphics::Gdi::*,
|
||||||
|
Win32::UI::WindowsAndMessaging::*,
|
||||||
|
Win32::UI::Controls::*,
|
||||||
|
Win32::UI::Input::KeyboardAndMouse::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub struct MediaViewerUI {
|
||||||
|
hwnd: HWND,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
impl MediaViewerUI {
|
||||||
|
pub fn new(hwnd: HWND) -> Self {
|
||||||
|
Self { hwnd }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create the main UI components
|
||||||
|
pub fn create_ui(&self) {
|
||||||
|
// Create menu bar
|
||||||
|
self.create_menu();
|
||||||
|
|
||||||
|
// Create toolbar (placeholder)
|
||||||
|
// Create status bar
|
||||||
|
// Create media display area
|
||||||
|
|
||||||
|
println!("UI created successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create application menu
|
||||||
|
fn create_menu(&self) {
|
||||||
|
let hmenu = unsafe { CreateMenu() };
|
||||||
|
if hmenu.is_invalid() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// File menu
|
||||||
|
let hsubmenu = unsafe { CreatePopupMenu() };
|
||||||
|
unsafe {
|
||||||
|
AppendMenuW(hsubmenu, MFT_STRING, 1001, s!("&Open"));
|
||||||
|
AppendMenuW(hsubmenu, MFT_SEPARATOR, 0, None);
|
||||||
|
AppendMenuW(hsubmenu, MFT_STRING, 1002, s!("E&xit"));
|
||||||
|
|
||||||
|
AppendMenuW(hmenu, MFT_STRING | MFT_POPUP, hsubmenu.0 as u32, s!("&File"));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
SetMenu(self.hwnd, hmenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle window messages
|
||||||
|
pub fn handle_message(&self, u_msg: UINT, w_param: WPARAM, l_param: LPARAM) -> LRESULT {
|
||||||
|
match u_msg {
|
||||||
|
WM_COMMAND => {
|
||||||
|
let wm_id = LOWORD(w_param.0 as u32) as u32;
|
||||||
|
match wm_id {
|
||||||
|
1001 => { // Open
|
||||||
|
self.open_file();
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
1002 => { // Exit
|
||||||
|
unsafe {
|
||||||
|
PostMessageA(self.hwnd, WM_CLOSE, WPARAM(0), LPARAM(0));
|
||||||
|
}
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
_ => DefWindowProcW(self.hwnd, u_msg, w_param, l_param),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WM_PAINT => {
|
||||||
|
self.paint();
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
WM_SIZE => {
|
||||||
|
self.resize();
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
_ => DefWindowProcW(self.hwnd, u_msg, w_param, l_param),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Open file dialog
|
||||||
|
fn open_file(&self) {
|
||||||
|
// In a real implementation, this would show an OpenFileDialog
|
||||||
|
println!("Opening file...");
|
||||||
|
|
||||||
|
// For now, we'll just simulate by showing a message box
|
||||||
|
#[cfg(windows)]
|
||||||
|
unsafe {
|
||||||
|
MessageBoxA(
|
||||||
|
self.hwnd,
|
||||||
|
s!("File opening not implemented in this demo"),
|
||||||
|
s!("Media Viewer"),
|
||||||
|
MB_OK | MB_ICONINFORMATION,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Paint the window content
|
||||||
|
fn paint(&self) {
|
||||||
|
// This would draw the media content
|
||||||
|
println!("Painting...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle window resize
|
||||||
|
fn resize(&self) {
|
||||||
|
println!("Resizing...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub fn create_window() -> Result<HWND, Box<dyn std::error::Error>> {
|
||||||
|
let class_name = s!("MediaViewerClass");
|
||||||
|
|
||||||
|
// Define window class
|
||||||
|
let wcex = WNDCLASSEXW {
|
||||||
|
cbSize: std::mem::size_of::<WNDCLASSEXW>() as u32,
|
||||||
|
style: CS_HREDRAW | CS_VREDRAW,
|
||||||
|
lpfnWndProc: Some(wnd_proc),
|
||||||
|
cbClsExtra: 0,
|
||||||
|
cbWndExtra: 0,
|
||||||
|
hInstance: unsafe { GetModuleHandleA(None)? },
|
||||||
|
hIcon: unsafe { LoadIconA(None, IDI_APPLICATION) }?,
|
||||||
|
hCursor: unsafe { LoadCursorA(None, IDC_ARROW) }?,
|
||||||
|
hbrBackground: unsafe { GetStockObject(WHITE_BRUSH) }?.into(),
|
||||||
|
lpszMenuName: None,
|
||||||
|
lpszClassName: class_name,
|
||||||
|
hIconSm: unsafe { LoadIconA(None, IDI_APPLICATION) }?,
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
RegisterClassExW(&wcex)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create window
|
||||||
|
let hwnd = unsafe {
|
||||||
|
CreateWindowExW(
|
||||||
|
WINDOW_EX_STYLE::default(),
|
||||||
|
class_name,
|
||||||
|
s!("Media Viewer"),
|
||||||
|
WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
1024,
|
||||||
|
768,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
GetModuleHandleA(None)?,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if hwnd.0.is_null() {
|
||||||
|
return Err("Failed to create window".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(hwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
unsafe extern "system" fn wnd_proc(
|
||||||
|
hwnd: HWND,
|
||||||
|
u_msg: UINT,
|
||||||
|
w_param: WPARAM,
|
||||||
|
l_param: LPARAM,
|
||||||
|
) -> LRESULT {
|
||||||
|
// In a real implementation, we'd need to store and retrieve the UI instance
|
||||||
|
// For now, just handle basic messages
|
||||||
|
|
||||||
|
match u_msg {
|
||||||
|
WM_CREATE => {
|
||||||
|
// Create UI elements here
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
WM_COMMAND => {
|
||||||
|
// Handle commands from menu
|
||||||
|
DefWindowProcW(hwnd, u_msg, w_param, l_param)
|
||||||
|
}
|
||||||
|
WM_PAINT => {
|
||||||
|
// Handle painting
|
||||||
|
let mut ps = PAINTSTRUCT::default();
|
||||||
|
let hdc = BeginPaint(hwnd, &mut ps);
|
||||||
|
EndPaint(hwnd, &ps);
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
WM_DESTROY => {
|
||||||
|
PostQuitMessage(0);
|
||||||
|
LRESULT(0)
|
||||||
|
}
|
||||||
|
_ => DefWindowProcW(hwnd, u_msg, w_param, l_param),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user